application/controllers/Api.php
/**
	 * Check credentials passed from login form.
	 * GET /api/authenticate?user_pin=9999&api_key=2b3vCKJO901LmncHfUREw8bxzsi3293101kLMNDhf HTTP/1.1
	 */
Check credentials passed from login form.
Check credentials passed from login form .
public function authenticate_get() {
		$userPin = $_REQUEST['user_pin'];
		$apiKey = $_REQUEST['api_key'];
		$this->load->model('User_model');
		$authObject = $this->User_model->getAuthObject($userPin);
		if($authObject->authenticated && $apiKey==API_KEY) {
			$userObject = $authObject->user;
			$userData =  [
				'user_id' => (int) $userObject->id,
				'username' => $userObject->username,
				'first_name' => $userObject->first_name,
				'last_name' => $userObject->last_name,
				'email_address' => $userObject->email_address,
				'role' => $userObject->role
			];
			$this->response([
				'status' => TRUE,
				'message' => 'OK',
				'userData' => $userData
			], REST_Controller::HTTP_OK);
		} else {
			$this->response([
				'status' => FALSE,
				'message' => 'Invalid credentials. Please try again.'
			], REST_Controller::HTTP_UNAUTHORIZED);
		}
		return;
	}
public function authenticate_get ( ) { $ userPin = $ _REQUEST [ 'user_pin' ] ; $ apiKey = $ _REQUEST [ 'api_key' ] ; $ this -> load -> model ( 'User_model' ) ; $ authObject = $ this -> User_model -> getAuthObject ( $ userPin ) ; if ( $ authObject -> authenticated && $ apiKey == API_KEY ) { $ userObject = $ authObject -> user ; $ userData = [ 'user_id' => ( int ) $ userObject -> id , 'username' => $ userObject -> username , 'first_name' => $ userObject -> first_name , 'last_name' => $ userObject -> last_name , 'email_address' => $ userObject -> email_address , 'role' => $ userObject -> role ] ; $ this -> response ( [ 'status' => TRUE , 'message' => 'OK' , 'userData' => $ userData ] , REST_Controller :: HTTP_OK ) ; } else { $ this -> response ( [ 'status' => FALSE , 'message' => 'Invalid credentials. Please try again.' ] , REST_Controller :: HTTP_UNAUTHORIZED ) ; } return ; }
Check credentials passed from login form.
Check credentials passed from login form .