iflrandevu/engine/Api/V1/Authorization.php

63 lines
1.6 KiB
PHP
Raw Normal View History

<?php
/* ----------------------------------------------------------------------------
* Easy!Appointments - Open Source Web Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
* @link http://easyappointments.org
* @since v1.2.0
* ---------------------------------------------------------------------------- */
namespace EA\Engine\Api\V1;
use CI_Controller;
use EA\Engine\Types\NonEmptyText;
use EA_Controller;
2016-07-09 13:24:52 +03:00
/**
* API v1 Authorization Class
2016-07-09 13:24:52 +03:00
*
* This class will handle the authorization procedure of the API.
*
* @deprecated
2016-07-09 13:24:52 +03:00
*/
class Authorization {
2016-07-09 13:24:52 +03:00
/**
* Framework Instance
*
* @var EA_Controller
2016-07-09 13:24:52 +03:00
*/
protected $CI;
2016-07-09 13:24:52 +03:00
/**
* Class Constructor
*
* @param CI_Controller $CI
2016-07-09 13:24:52 +03:00
*/
public function __construct(EA_Controller $CI)
{
$this->CI = $CI;
2016-07-09 13:24:52 +03:00
}
/**
* Perform Basic Authentication
*
* @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.
*/
public function basic(NonEmptyText $username, NonEmptyText $password)
{
$this->CI->load->model('user_model');
2016-07-09 13:24:52 +03:00
if ( ! $this->CI->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');
}
}
}