2021-12-07 12:53:59 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2022-01-18 15:05:42 +03:00
|
|
|
* Easy!Appointments - Online Appointment Scheduler
|
2021-12-07 12:53:59 +03:00
|
|
|
*
|
|
|
|
* @package EasyAppointments
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
2021-12-07 12:53:59 +03:00
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
* @since v1.5.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Login controller.
|
|
|
|
*
|
2023-11-29 12:24:09 +03:00
|
|
|
* Handles the login page functionality.
|
2021-12-07 12:53:59 +03:00
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
class Login extends EA_Controller
|
|
|
|
{
|
2021-12-07 12:53:59 +03:00
|
|
|
/**
|
|
|
|
* Login constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->load->library('accounts');
|
|
|
|
$this->load->library('email_messages');
|
2021-12-14 10:06:10 +03:00
|
|
|
|
2021-12-17 12:53:22 +03:00
|
|
|
script_vars([
|
2023-12-22 13:35:41 +03:00
|
|
|
'dest_url' => session('dest_url', site_url('calendar')),
|
2021-12-14 10:06:10 +03:00
|
|
|
]);
|
2021-12-07 12:53:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-29 12:24:09 +03:00
|
|
|
* Render the login page.
|
2021-12-07 12:53:59 +03:00
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2024-03-28 14:08:55 +03:00
|
|
|
if (session('user_id')) {
|
|
|
|
redirect('calendar');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-18 19:22:40 +03:00
|
|
|
html_vars([
|
2022-10-16 18:02:47 +03:00
|
|
|
'page_title' => lang('login'),
|
2021-12-07 12:53:59 +03:00
|
|
|
'base_url' => config('base_url'),
|
2022-01-14 10:34:28 +03:00
|
|
|
'dest_url' => session('dest_url', site_url('calendar')),
|
2023-12-22 13:35:41 +03:00
|
|
|
'company_name' => setting('company_name'),
|
2021-12-07 12:53:59 +03:00
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
2022-01-19 12:21:05 +03:00
|
|
|
$this->load->view('pages/login');
|
2021-12-07 12:53:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-29 12:24:09 +03:00
|
|
|
* Validate the provided credentials and start a new session if the validation was successful.
|
2021-12-07 12:53:59 +03:00
|
|
|
*/
|
|
|
|
public function validate()
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
try {
|
2021-12-07 12:53:59 +03:00
|
|
|
$username = request('username');
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($username)) {
|
2021-12-07 12:53:59 +03:00
|
|
|
throw new InvalidArgumentException('No username value provided.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$password = request('password');
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($password)) {
|
2021-12-07 12:53:59 +03:00
|
|
|
throw new InvalidArgumentException('No password value provided.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$user_data = $this->accounts->check_login($username, $password);
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($user_data)) {
|
2021-12-07 12:53:59 +03:00
|
|
|
throw new InvalidArgumentException('Invalid credentials provided, please try again.');
|
|
|
|
}
|
2023-11-29 12:24:09 +03:00
|
|
|
|
2023-04-15 15:46:30 +03:00
|
|
|
$this->session->sess_regenerate();
|
2021-12-07 12:53:59 +03:00
|
|
|
|
|
|
|
session($user_data); // Save data in the session.
|
|
|
|
|
|
|
|
json_response([
|
2023-12-22 13:35:41 +03:00
|
|
|
'success' => true,
|
2021-12-07 12:53:59 +03:00
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
} catch (Throwable $e) {
|
2021-12-07 12:53:59 +03:00
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|