diff --git a/application/config/autoload.php b/application/config/autoload.php index 97eac47b8..76835381d 100755 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -58,7 +58,7 @@ $autoload['packages'] = array(); | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array('Session', 'FHC_Auth'); +$autoload['libraries'] = array('Session', 'AuthLib'); /* | ------------------------------------------------------------------- diff --git a/application/config/rest.php b/application/config/rest.php index ec2d6f5ad..4f3a78972 100644 --- a/application/config/rest.php +++ b/application/config/rest.php @@ -143,7 +143,7 @@ $config['auth_source'] = 'library'; | password for that username, even if it is hashed | */ -$config['auth_library_class'] = 'FHC_Auth'; +$config['auth_library_class'] = 'AuthLib'; // rest_auth is basic $config['auth_library_function'] = 'basicAuthentication'; diff --git a/application/controllers/api/v1/CheckUserAuth.php b/application/controllers/api/v1/CheckUserAuth.php index a793845a7..ac4195808 100644 --- a/application/controllers/api/v1/CheckUserAuth.php +++ b/application/controllers/api/v1/CheckUserAuth.php @@ -22,18 +22,23 @@ class CheckUserAuth extends APIv1_Controller public function __construct() { parent::__construct(); - $this->load->model('CheckUserAuth_model', 'CheckUserAuthModel'); + + // Loads the authentication library + $this->load->library('AuthLib'); } - + + /** + * Checks if username and password of a final user are valid + */ public function getCheckByUsernamePassword() { - $username = $this->get("username"); - $password = $this->get("password"); - + $username = $this->get('username'); + $password = $this->get('password'); + if (isset($username) && isset($password)) { - $result = $this->CheckUserAuthModel->checkByUsernamePassword($username, $password); - + $result = $this->authlib->CheckUserAuthByUsernamePassword($username, $password); + $this->response($result, REST_Controller::HTTP_OK); } else @@ -41,4 +46,45 @@ class CheckUserAuth extends APIv1_Controller $this->response(); } } -} \ No newline at end of file + + /** + * Checks if username and password of a final user are valid + * Returns all the keys with which is possible to obtain all the personal data about a final user + */ + public function getCheckUserAuth() + { + $code = $this->get('code'); + $email = $this->get('email'); + $username = $this->get('username'); + $password = $this->get('password'); + + $result = null; + $httpCode = null; + + // If username and password are given then check authentication using them + if (isset($username) && isset($password)) + { + $result = $this->authlib->CheckUserAuthByUsernamePassword($username, $password, true); + } + elseif (isset($code) || isset($email)) + { + // If code and email are given then check authentication using them + if (isset($code) && isset($email)) + { + $result = $this->authlib->CheckUserAuthByCodeEmail($code, $email); + } + else // otherwise check authentication using only code + { + $result = $this->authlib->CheckUserAuthByCode($code); + } + } + + // If is a success and contains data + if (hasData($result)) + { + $httpCode = REST_Controller::HTTP_OK; + } + + $this->response($result, $httpCode); + } +} diff --git a/application/libraries/FHC_Auth.php b/application/libraries/FHC_Auth.php deleted file mode 100644 index dd7bb09e2..000000000 --- a/application/libraries/FHC_Auth.php +++ /dev/null @@ -1,69 +0,0 @@ -checkpassword($username, $password)) - { - return true; - } - else - { - return false; - } - } - - /** - * - * TO BE UPDATED - * - * Get the md5 hashed password by the addon username - * - * @param string $username addon username - * @return string md5 hashed string - */ - public function digestAuthentication($username) - { - $aam = new AddonAuthentication(); - - return md5($aam->getPasswordByUsername($username)); - } -} diff --git a/application/models/CheckUserAuth_model.php b/application/models/CheckUserAuth_model.php deleted file mode 100644 index 503251268..000000000 --- a/application/models/CheckUserAuth_model.php +++ /dev/null @@ -1,18 +0,0 @@ -load->library('fhc_auth'); - } - - public function checkByUsernamePassword($username, $password) - { - return success($this->fhc_auth->checkpassword($username, $password)); - } -} \ No newline at end of file diff --git a/include/AddonAuthentication.php b/include/AddonAuthentication.php deleted file mode 100644 index a67ea260b..000000000 --- a/include/AddonAuthentication.php +++ /dev/null @@ -1,46 +0,0 @@ -db->query($sql, array($username)); - - if(!is_null($result) && $result->num_rows() > 0) - { - $password = $result->row()->password; - } - - return $password; - } -} \ No newline at end of file