- Moved all the code related to authentication to AuthLib

- Changed configuration files autoload.php and rest.php to use AuthLib
- Added new method getCheckUserAuth to controller CheckUserAuth.php
- Removed libraries/FHC_Auth.php
- Removed models/CheckUserAuth_model.php
- Removed include/AddonAuthentication.php
This commit is contained in:
Paolo
2017-09-25 17:11:44 +02:00
parent ec62250b41
commit 3cf42c4545
6 changed files with 56 additions and 143 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ $autoload['packages'] = array();
|
| $autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array('Session', 'FHC_Auth');
$autoload['libraries'] = array('Session', 'AuthLib');
/*
| -------------------------------------------------------------------
+1 -1
View File
@@ -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';
@@ -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();
}
}
}
/**
* 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);
}
}
-69
View File
@@ -1,69 +0,0 @@
<?php
/**
* FH-Complete
*
* @package FHC-Helper
* @author FHC-Team
* @copyright Copyright (c) 2016 fhcomplete.org
* @license GPLv3
* @link https://fhcomplete.org
* @since Version 1.0.0
* @filesource
*/
/**
* FHC-Auth Helpers
*
* @package FH-Complete
* @subpackage Helpers
* @category Helpers
* @author FHC-Team
* @link http://fhcomplete.org/user_guide/helpers/fhcauth_helper.html
*/
if (! defined('BASEPATH')) exit('No direct script access allowed');
require_once FHCPATH.'include/authentication.class.php';
require_once FHCPATH.'include/AddonAuthentication.php';
class FHC_Auth extends authentication
{
/**
* Construct
*/
public function __construct()
{
parent::__construct();
}
/**
* Auth Username, Password over FH-Complete
*/
public function basicAuthentication($username, $password)
{
if ($this->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));
}
}
@@ -1,18 +0,0 @@
<?php
class CheckUserAuth_model extends FHC_Model
{
/**
* Construct
*/
public function __construct()
{
parent::__construct();
$this->load->library('fhc_auth');
}
public function checkByUsernamePassword($username, $password)
{
return success($this->fhc_auth->checkpassword($username, $password));
}
}
-46
View File
@@ -1,46 +0,0 @@
<?php
// TO BE UPDATED
/*
* This class requires only DB functionalities from CI
* CI_Hack couldn't be included here because this class is called every time an addon
* makes an API call, so it would raise a lot of "already declared" errors
*/
require_once(dirname(__FILE__).'/../vendor/codeigniter/framework/system/core/Model.php');
require_once(dirname(__FILE__).'/../application/core/FHC_Model.php');
require_once(dirname(__FILE__).'/../application/core/DB_Model.php');
/**
* This class is used to authenticate the addons on the core system
*/
class AddonAuthentication extends DB_Model
{
public function __construct()
{
parent::__construct(NULL);
}
/**
* It retrieves the password with the given username from ci_addons table
* CREATE TABLE ci_addons (
* username varchar(10),
* password varchar(40),
* enabled integer,
* CONSTRAINT ci_addons_pk UNIQUE(username));
*/
public function getPasswordByUsername($username)
{
$password = NULL;
$sql = "SELECT password FROM public.ci_addons WHERE enabled = 1 AND username = ?";
$result = $this->db->query($sql, array($username));
if(!is_null($result) && $result->num_rows() > 0)
{
$password = $result->row()->password;
}
return $password;
}
}