2017-09-15 14:36:37 +03:00
|
|
|
<?php
|
2016-07-08 22:35:48 +03:00
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
* Easy!Appointments - Open Source Web Scheduler
|
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2020-03-11 12:10:59 +03:00
|
|
|
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
2016-07-08 22:35:48 +03:00
|
|
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link http://easyappointments.org
|
|
|
|
* @since v1.2.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
namespace EA\Engine\Api\V1;
|
2016-07-08 22:35:48 +03:00
|
|
|
|
2016-11-09 21:56:24 +03:00
|
|
|
use \EA\Engine\Types\NonEmptyText;
|
2016-07-09 13:24:52 +03:00
|
|
|
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* API v1 Authorization Class
|
2016-07-09 13:24:52 +03:00
|
|
|
*
|
2016-07-10 11:59:39 +03:00
|
|
|
* This class will handle the authorization procedure of the API.
|
2020-05-12 21:49:15 +03:00
|
|
|
*
|
|
|
|
* @deprecated
|
2016-07-09 13:24:52 +03:00
|
|
|
*/
|
2016-07-08 22:35:48 +03:00
|
|
|
class Authorization {
|
2016-07-09 13:24:52 +03:00
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Framework Instance
|
|
|
|
*
|
2016-07-09 13:24:52 +03:00
|
|
|
* @var CI_Controller
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
protected $framework;
|
2016-07-09 13:24:52 +03:00
|
|
|
|
|
|
|
/**
|
2017-09-15 14:36:37 +03:00
|
|
|
* Class Constructor
|
|
|
|
*
|
2016-07-09 13:24:52 +03:00
|
|
|
* @param \CI_Controller $framework
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function __construct(\CI_Controller $framework)
|
|
|
|
{
|
2016-07-09 13:24:52 +03:00
|
|
|
$this->framework = $framework;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform Basic Authentication
|
2017-09-15 14:36:37 +03:00
|
|
|
*
|
2016-11-09 21:56:24 +03:00
|
|
|
* @param NonEmptyText $username Admin Username
|
|
|
|
* @param NonEmptyText $password Admin Password
|
2016-07-09 13:24:52 +03:00
|
|
|
*
|
|
|
|
* @throws \EA\Engine\Api\V1\Exception Throws 401-Unauthorized exception if the authentication fails.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function basic(NonEmptyText $username, NonEmptyText $password)
|
|
|
|
{
|
|
|
|
$this->framework->load->model('user_model');
|
2016-07-09 13:24:52 +03:00
|
|
|
|
2017-09-15 14:36:37 +03:00
|
|
|
if ( ! $this->framework->user_model->check_login($username->get(), $password->get()))
|
|
|
|
{
|
2016-07-09 13:24:52 +03:00
|
|
|
throw new Exception('The provided credentials do not match any admin user!', 401, 'Unauthorized');
|
|
|
|
}
|
|
|
|
}
|
2016-07-08 22:35:48 +03:00
|
|
|
}
|