MaketRandevu/application/controllers/User.php

175 lines
4.4 KiB
PHP
Raw Normal View History

<?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>
* @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-11-06 18:21:27 +03:00
* User controller.
*
* Handles the user related operations.
2015-12-30 13:02:14 +02:00
*
* @package Controllers
*/
class User extends EA_Controller {
/**
* User constructor.
*/
public function __construct()
{
parent::__construct();
$this->load->library('accounts');
$this->load->library('email_messages');
}
2015-12-30 13:02:14 +02:00
/**
* Redirect to the login page.
2015-12-30 13:02:14 +02:00
*/
public function index()
{
redirect('user/login');
2015-12-30 13:02:14 +02:00
}
/**
* Display the login page.
*/
public function login()
{
$this->load->view('pages/account_login_page', [
'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.
*/
public function logout()
{
$this->session->sess_destroy();
$this->load->view('pages/account_logout_page', [
'base_url' => config('base_url'),
'company_name' => setting('company_name')
]);
2015-12-30 13:02:14 +02:00
}
/**
* Display the password recovery page.
2015-12-30 13:02:14 +02:00
*/
public function forgot_password()
{
$this->load->view('pages/account_recovery_page', [
'base_url' => config('base_url'),
'company_name' => setting('company_name')
]);
2015-12-30 13:02:14 +02:00
}
/**
* Display the no-permissions page.
*/
public function no_permissions()
{
$this->load->view('pages/account_no_permissions_page', [
'base_url' => config('base_url'),
'company_name' => setting('company_name')
]);
2015-12-30 13:02:14 +02:00
}
/**
* Validate the login credentials and if successful, log the user in.
2015-12-30 13:02:14 +02:00
*/
public function ajax_check_login()
{
try
{
$username = request('username');
if (empty($username))
{
throw new InvalidArgumentException('No username value provided.');
2015-12-30 13:02:14 +02:00
}
$password = request('password');
if (empty($password))
{
throw new InvalidArgumentException('No password value provided.');
2018-01-23 12:08:37 +03:00
}
$user_data = $this->accounts->check_login($username, $password);
if (empty($user_data))
{
throw new InvalidArgumentException('Invalid credentials provided, please try again.');
2015-12-30 13:02:14 +02:00
}
session($user_data); // Save data in the session.
2021-11-06 18:51:36 +03:00
json_response([
'success' => TRUE,
]);
2017-09-23 02:30:22 +03:00
}
catch (Throwable $e)
{
json_exception($e);
2015-12-30 13:02:14 +02:00
}
}
/**
* Recover the user password and notify the user via email.
2015-12-30 13:02:14 +02:00
*/
public function ajax_forgot_password()
{
try
{
$username = request('username');
if (empty($username))
{
throw new InvalidArgumentException('No username value provided.');
2015-12-30 13:02:14 +02:00
}
$email = request('email');
2015-12-30 13:02:14 +02:00
if (empty($email))
{
throw new InvalidArgumentException('No email value provided.');
}
$new_password = $this->accounts->regenerate_password(
$username,
$email
);
if ($new_password)
{
$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);
2015-12-30 13:02:14 +02:00
}
json_response([
'success' => TRUE
]);
2017-09-23 02:30:22 +03:00
}
catch (Throwable $e)
{
json_exception($e);
2015-12-30 13:02:14 +02:00
}
}
}