application/controllers/Auth.php
/* login the user
     parameters email,password
     */
login the user
parameters email,password
login the user parameters email password
public function login_post($fb_data = NULL)
    {
    	$this->load->helper('security');
    	if (!$fb_data) {
    		$post_data = $this->post();
			$this->form_validation->set_data($post_data);
			$this->form_validation->set_error_delimiters('', '');
			$this->form_validation->set_rules('email','Email','required');
			$this->form_validation->set_rules('password','Password','required');
			if ($this->form_validation->run() === false) {
	    		$this->response(array('ResponseCode' => 0, 'ResponseMessage' => 'FAILURE', 'Comments' => validation_errors(),'Result'=>false), 400);
			}else{
				$data = $this->Auth_model->login($post_data);
			}
    	}
    	if($fb_data){
    		$data = $this->Auth_model->fb_login_dummy_user($fb_data);
    	}
		if ($data) {
			$email = strtolower($data[0]['email']);
			$post_data['token'] = $this->generate_token();
			$post_data['tokenExpiry'] = $this->generate_token_expiry();
			$post_data['refreshToken'] = $this->generate_token();
			$post_data['refreshTokenExpiry'] = $this->generate_refresh_token_expiry();
			$token_data = $this->Auth_model->save_token_with_expiry($post_data,$email);
			if ($token_data) {
				$data[0]['token'] = $post_data['token'];
				$data[0]['tokenExpiry'] = $post_data['tokenExpiry'];
				$data[0]['refreshToken'] = $post_data['refreshToken'];
				$data[0]['refreshTokenExpiry'] = $post_data['refreshTokenExpiry'];						
				$this->response(array('ResponseCode' => 1, 'ResponseMessage' => 'SUCCESS', 'Comments' => 'Logged in successfully','Result'=>$data[0]), 200);
			}else{
				$this->response(array('ResponseCode' => 0, 'ResponseMessage' => 'FAILURE', 'Comments' => 'Server error','Result'=>''), 400);	
			}			
		}else{
			$this->response(array('ResponseCode' => 0, 'ResponseMessage' => 'FAILURE', 'Comments' => $_POST['login_error'],'Result'=>''), 400);
		}				
	}
public function login_post ( $ fb_data = NULL ) { $ this -> load -> helper ( 'security' ) ; if ( ! $ fb_data ) { $ post_data = $ this -> post ( ) ; $ this -> form_validation -> set_data ( $ post_data ) ; $ this -> form_validation -> set_error_delimiters ( '' , '' ) ; $ this -> form_validation -> set_rules ( 'email' , 'Email' , 'required' ) ; $ this -> form_validation -> set_rules ( 'password' , 'Password' , 'required' ) ; if ( $ this -> form_validation -> run ( ) === false ) { $ this -> response ( array ( 'ResponseCode' => 0 , 'ResponseMessage' => 'FAILURE' , 'Comments' => validation_errors ( ) , 'Result' => false ) , 400 ) ; } else { $ data = $ this -> Auth_model -> login ( $ post_data ) ; } } if ( $ fb_data ) { $ data = $ this -> Auth_model -> fb_login_dummy_user ( $ fb_data ) ; } if ( $ data ) { $ email = strtolower ( $ data [ 0 ] [ 'email' ] ) ; $ post_data [ 'token' ] = $ this -> generate_token ( ) ; $ post_data [ 'tokenExpiry' ] = $ this -> generate_token_expiry ( ) ; $ post_data [ 'refreshToken' ] = $ this -> generate_token ( ) ; $ post_data [ 'refreshTokenExpiry' ] = $ this -> generate_refresh_token_expiry ( ) ; $ token_data = $ this -> Auth_model -> save_token_with_expiry ( $ post_data , $ email ) ; if ( $ token_data ) { $ data [ 0 ] [ 'token' ] = $ post_data [ 'token' ] ; $ data [ 0 ] [ 'tokenExpiry' ] = $ post_data [ 'tokenExpiry' ] ; $ data [ 0 ] [ 'refreshToken' ] = $ post_data [ 'refreshToken' ] ; $ data [ 0 ] [ 'refreshTokenExpiry' ] = $ post_data [ 'refreshTokenExpiry' ] ; $ this -> response ( array ( 'ResponseCode' => 1 , 'ResponseMessage' => 'SUCCESS' , 'Comments' => 'Logged in successfully' , 'Result' => $ data [ 0 ] ) , 200 ) ; } else { $ this -> response ( array ( 'ResponseCode' => 0 , 'ResponseMessage' => 'FAILURE' , 'Comments' => 'Server error' , 'Result' => '' ) , 400 ) ; } } else { $ this -> response ( array ( 'ResponseCode' => 0 , 'ResponseMessage' => 'FAILURE' , 'Comments' => $ _POST [ 'login_error' ] , 'Result' => '' ) , 400 ) ; } }
login the user
parameters email,password
login the user parameters email password
//print_r($data);exit();