mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-26 00:23:33 +03:00
Refactored the login controller callback
This commit is contained in:
parent
c9a7f551b5
commit
31b452766d
1 changed files with 20 additions and 27 deletions
|
@ -11,10 +11,6 @@
|
|||
* @since v1.0.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
use EA\Engine\Notifications\Email as EmailClient;
|
||||
use EA\Engine\Types\Email;
|
||||
use EA\Engine\Types\NonEmptyText;
|
||||
|
||||
/**
|
||||
* User controller
|
||||
*
|
||||
|
@ -31,6 +27,7 @@ class User extends EA_Controller {
|
|||
parent::__construct();
|
||||
|
||||
$this->load->library('accounts');
|
||||
$this->load->library('email_messages');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,41 +92,37 @@ class User extends EA_Controller {
|
|||
{
|
||||
try
|
||||
{
|
||||
if ( ! request('username') || ! request('password'))
|
||||
{
|
||||
throw new Exception('Invalid credentials given!');
|
||||
}
|
||||
|
||||
$username = request('username');
|
||||
|
||||
if (empty($username))
|
||||
{
|
||||
throw new InvalidArgumentException('Empty username provided.');
|
||||
}
|
||||
|
||||
$password = request('password');
|
||||
|
||||
if (empty($password))
|
||||
{
|
||||
throw new InvalidArgumentException('Empty password provided.');
|
||||
}
|
||||
|
||||
$user_data = $this->accounts->check_login($username, $password);
|
||||
|
||||
if ($user_data)
|
||||
if (empty($user_data))
|
||||
{
|
||||
session($user_data); // Save data in the session.
|
||||
throw new InvalidArgumentException('Invalid credentials provided, please try again.');
|
||||
}
|
||||
|
||||
$response = AJAX_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
$response = AJAX_FAILURE;
|
||||
}
|
||||
session($user_data); // Save data in the session.
|
||||
|
||||
json_encode([
|
||||
'success' => TRUE,
|
||||
]);
|
||||
}
|
||||
catch (Throwable $e)
|
||||
{
|
||||
$this->output->set_status_header(500);
|
||||
|
||||
$response = [
|
||||
'message' => $e->getMessage(),
|
||||
'trace' => config('debug') ? $e->getTrace() : []
|
||||
];
|
||||
json_exception($e);
|
||||
}
|
||||
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode($response));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue