2020-04-22 22:48:56 +03:00
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2015-12-30 13:02:14 +02: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
|
2020-11-14 22:36:25 +03:00
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
2015-12-30 13:02:14 +02:00
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
2021-10-28 15:01:17 +03:00
|
|
|
* User controller
|
|
|
|
*
|
|
|
|
* Handles the user related operations.
|
2015-12-30 13:02:14 +02:00
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
2020-11-16 11:29:36 +03:00
|
|
|
class User extends EA_Controller {
|
2020-12-05 12:55:09 +03:00
|
|
|
/**
|
|
|
|
* User constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
2021-10-28 15:01:17 +03:00
|
|
|
|
|
|
|
$this->load->library('accounts');
|
2021-11-06 18:09:29 +03:00
|
|
|
$this->load->library('email_messages');
|
2020-12-05 12:55:09 +03:00
|
|
|
}
|
|
|
|
|
2015-12-30 13:02:14 +02:00
|
|
|
/**
|
2021-10-28 15:01:17 +03:00
|
|
|
* Redirect to the login page.
|
2015-12-30 13:02:14 +02:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function index()
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
redirect('user/login');
|
2015-12-30 13:02:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the login page.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function login()
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->load->view('user/login', [
|
|
|
|
'base_url' => config('base_url'),
|
|
|
|
'company_name' => setting('company_name'),
|
|
|
|
'dest_url' => session('dest_url', site_url('backend'))
|
|
|
|
]);
|
2015-12-30 13:02:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the logout page.
|
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function logout()
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->session->sess_destroy();
|
|
|
|
|
|
|
|
$this->load->view('user/logout', [
|
|
|
|
'base_url' => config('base_url'),
|
|
|
|
'company_name' => setting('company_name')
|
|
|
|
]);
|
2015-12-30 13:02:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-28 15:01:17 +03:00
|
|
|
* Display the password recovery page.
|
2015-12-30 13:02:14 +02:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function forgot_password()
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->load->view('user/forgot_password', [
|
|
|
|
'base_url' => config('base_url'),
|
|
|
|
'company_name' => setting('company_name')
|
|
|
|
]);
|
2015-12-30 13:02:14 +02:00
|
|
|
}
|
|
|
|
|
2016-04-27 09:21:40 +03:00
|
|
|
/**
|
2021-10-28 15:01:17 +03:00
|
|
|
* Display the no-permissions page.
|
2016-04-27 09:21:40 +03:00
|
|
|
*/
|
2021-10-28 15:01:17 +03:00
|
|
|
public function no_permissions()
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$this->load->view('user/no_privileges', [
|
|
|
|
'base_url' => config('base_url'),
|
|
|
|
'company_name' => setting('company_name')
|
|
|
|
]);
|
2015-12-30 13:02:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-28 15:01:17 +03:00
|
|
|
* Validate the login credentials and if successful, log the user in.
|
2015-12-30 13:02:14 +02:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_check_login()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-11-06 18:09:29 +03:00
|
|
|
$username = request('username');
|
|
|
|
|
|
|
|
if (empty($username))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-11-06 18:11:55 +03:00
|
|
|
throw new InvalidArgumentException('No username value provided.');
|
2015-12-30 13:02:14 +02:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$password = request('password');
|
|
|
|
|
2021-11-06 18:09:29 +03:00
|
|
|
if (empty($password))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-11-06 18:11:55 +03:00
|
|
|
throw new InvalidArgumentException('No password value provided.');
|
2018-01-23 12:08:37 +03:00
|
|
|
}
|
2021-11-06 18:09:29 +03:00
|
|
|
|
|
|
|
$user_data = $this->accounts->check_login($username, $password);
|
|
|
|
|
|
|
|
if (empty($user_data))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-11-06 18:09:29 +03:00
|
|
|
throw new InvalidArgumentException('Invalid credentials provided, please try again.');
|
2015-12-30 13:02:14 +02:00
|
|
|
}
|
2021-11-06 18:09:29 +03:00
|
|
|
|
|
|
|
session($user_data); // Save data in the session.
|
|
|
|
|
|
|
|
json_encode([
|
|
|
|
'success' => TRUE,
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-11-06 18:09:29 +03:00
|
|
|
json_exception($e);
|
2015-12-30 13:02:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-28 15:01:17 +03:00
|
|
|
* Recover the user password and notify the user via email.
|
2015-12-30 13:02:14 +02:00
|
|
|
*/
|
2017-09-15 14:36:37 +03:00
|
|
|
public function ajax_forgot_password()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
$username = request('username');
|
|
|
|
|
|
|
|
if (empty($username))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new InvalidArgumentException('No username value provided.');
|
2015-12-30 13:02:14 +02:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
$email = request('email');
|
2015-12-30 13:02:14 +02:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if (empty($email))
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
throw new InvalidArgumentException('No email value provided.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$new_password = $this->accounts->regenerate_password(
|
|
|
|
$username,
|
|
|
|
$email
|
|
|
|
);
|
2020-04-22 22:48:56 +03:00
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
if ($new_password)
|
|
|
|
{
|
|
|
|
$settings = [
|
|
|
|
'company_name' => setting('company_name'),
|
|
|
|
'company_link' => setting('company_link'),
|
|
|
|
'company_email' => setting('company_email')
|
2017-09-15 14:36:37 +03:00
|
|
|
];
|
2016-07-16 17:56:02 +03:00
|
|
|
|
2021-11-06 18:11:55 +03:00
|
|
|
$this->email_messages->send_password($new_password, $email, $settings);
|
2015-12-30 13:02:14 +02:00
|
|
|
}
|
|
|
|
|
2021-10-28 15:01:17 +03:00
|
|
|
json_response([
|
|
|
|
'success' => TRUE
|
|
|
|
]);
|
2017-09-23 02:30:22 +03:00
|
|
|
}
|
2021-10-28 15:01:17 +03:00
|
|
|
catch (Throwable $e)
|
2017-09-15 14:36:37 +03:00
|
|
|
{
|
2021-10-28 15:01:17 +03:00
|
|
|
json_exception($e);
|
2015-12-30 13:02:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|