2021-12-10 10:41:16 +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-10 10:41:16 +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-10 10:41:16 +03:00
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
* @link https://easyappointments.org
|
|
|
|
* @since v1.0.0
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recovery controller.
|
|
|
|
*
|
|
|
|
* Handles the recovery page functionality.
|
|
|
|
*
|
|
|
|
* @package Controllers
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
class Recovery extends EA_Controller
|
|
|
|
{
|
2021-12-10 10:41:16 +03:00
|
|
|
/**
|
|
|
|
* User constructor.
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->load->library('accounts');
|
|
|
|
$this->load->library('email_messages');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the password recovery page.
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
$company_name = setting('company_name');
|
|
|
|
|
2021-12-18 19:22:40 +03:00
|
|
|
html_vars([
|
2022-10-16 18:02:47 +03:00
|
|
|
'page_title' => lang('forgot_your_password'),
|
2021-12-10 10:41:16 +03:00
|
|
|
'dest_url' => session('dest_url', site_url('backend')),
|
2021-12-18 19:22:40 +03:00
|
|
|
'company_name' => $company_name
|
2023-11-29 12:24:09 +03:00
|
|
|
]);
|
|
|
|
|
2022-01-19 12:21:05 +03:00
|
|
|
$this->load->view('pages/recovery');
|
2021-12-10 10:41:16 +03:00
|
|
|
}
|
2023-11-29 12:24:09 +03:00
|
|
|
|
2021-12-10 10:41:16 +03:00
|
|
|
/**
|
|
|
|
* Recover the user password and notify the user via email.
|
|
|
|
*/
|
|
|
|
public function perform()
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
try {
|
2021-12-10 10:41:16 +03:00
|
|
|
$username = request('username');
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($username)) {
|
2021-12-10 10:41:16 +03:00
|
|
|
throw new InvalidArgumentException('No username value provided.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$email = request('email');
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if (empty($email)) {
|
2021-12-10 10:41:16 +03:00
|
|
|
throw new InvalidArgumentException('No email value provided.');
|
|
|
|
}
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
$new_password = $this->accounts->regenerate_password($username, $email);
|
2021-12-10 10:41:16 +03:00
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
if ($new_password) {
|
2021-12-10 10:41:16 +03:00
|
|
|
$settings = [
|
|
|
|
'company_name' => setting('company_name'),
|
|
|
|
'company_link' => setting('company_link'),
|
|
|
|
'company_email' => setting('company_email')
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->email_messages->send_password($new_password, $email, $settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
json_response([
|
2023-11-29 12:24:09 +03:00
|
|
|
'success' => true
|
2021-12-10 10:41:16 +03:00
|
|
|
]);
|
2023-11-29 12:24:09 +03:00
|
|
|
} catch (Throwable $e) {
|
2021-12-10 10:41:16 +03:00
|
|
|
json_exception($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|