mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-22 14:42:23 +03:00
Minor code format corrections.
This commit is contained in:
parent
739368c00f
commit
af976440f8
8 changed files with 316 additions and 281 deletions
|
@ -72,7 +72,6 @@ class Backend extends CI_Controller {
|
|||
$view['secretary_providers'] = array();
|
||||
}
|
||||
|
||||
|
||||
$results = $this->appointments_model->get_batch(array('hash' => $appointment_hash));
|
||||
if ($appointment_hash != '' && count($results) > 0) {
|
||||
$appointment = $results[0];
|
||||
|
@ -232,6 +231,7 @@ class Backend extends CI_Controller {
|
|||
* @param bool $redirect (OPTIONAL - TRUE) If the user has not the required privileges
|
||||
* (either not logged in or insufficient role privileges) then the user will be redirected
|
||||
* to another page. Set this argument to FALSE when using ajax.
|
||||
*
|
||||
* @return bool Returns whether the user has the required privileges to view the page or
|
||||
* not. If the user is not logged in then he will be prompted to log in. If he hasn't the
|
||||
* required privileges then an info message will be displayed.
|
||||
|
|
|
@ -48,10 +48,10 @@ class Backend_api extends CI_Controller {
|
|||
* This method returns the database appointments and unavailable periods for the
|
||||
* user selected date period and record type (provider or service).
|
||||
*
|
||||
* @param {numeric} $_POST['record_id'] Selected record id.
|
||||
* @param {string} $_POST['filter_type'] Could be either FILTER_TYPE_PROVIDER or FILTER_TYPE_SERVICE.
|
||||
* @param {string} $_POST['start_date'] The user selected start date.
|
||||
* @param {string} $_POST['end_date'] The user selected end date.
|
||||
* @param numeric $_POST['record_id'] Selected record id.
|
||||
* @param string $_POST['filter_type'] Could be either FILTER_TYPE_PROVIDER or FILTER_TYPE_SERVICE.
|
||||
* @param string $_POST['start_date'] The user selected start date.
|
||||
* @param string $_POST['end_date'] The user selected end date.
|
||||
*/
|
||||
public function ajax_get_calendar_appointments() {
|
||||
try {
|
||||
|
@ -113,13 +113,10 @@ class Backend_api extends CI_Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* [AJAX] Save appointment changes that are made from the backend calendar
|
||||
* page.
|
||||
* [AJAX] Save appointment changes that are made from the backend calendar page.
|
||||
*
|
||||
* @param array $_POST['appointment_data'] (OPTIONAL) Array with the
|
||||
* appointment data.
|
||||
* @param array $_POST['customer_data'] (OPTIONAL) Array with the customer
|
||||
* data.
|
||||
* @param array $_POST['appointment_data'] (OPTIONAL) Array with the appointment data.
|
||||
* @param array $_POST['customer_data'] (OPTIONAL) Array with the customer data.
|
||||
*/
|
||||
public function ajax_save_appointment() {
|
||||
try {
|
||||
|
@ -374,7 +371,6 @@ class Backend_api extends CI_Controller {
|
|||
if (!isset($_POST['provider_id']))
|
||||
throw new Exception('Provider id not specified.');
|
||||
|
||||
|
||||
if ($this->privileges[PRIV_USERS]['edit'] == FALSE
|
||||
&& $this->session->userdata('user_id') != $_POST['provider_id']) {
|
||||
throw new Exception('You do not have the required privileges for this task.');
|
||||
|
@ -398,7 +394,8 @@ class Backend_api extends CI_Controller {
|
|||
/**
|
||||
* [AJAX] Filter the customer records with the given key string.
|
||||
*
|
||||
* @param string $_POST['key'] The filter key string
|
||||
* @param string $_POST['key'] The filter key string.
|
||||
*
|
||||
* @return array Returns the search results.
|
||||
*/
|
||||
public function ajax_filter_customers() {
|
||||
|
@ -666,6 +663,7 @@ class Backend_api extends CI_Controller {
|
|||
* [AJAX] Filter service records by given key string.
|
||||
*
|
||||
* @param string $_POST['key'] Key string used to filter the records.
|
||||
*
|
||||
* @return array Returns a json encoded array back to client.
|
||||
*/
|
||||
public function ajax_filter_services() {
|
||||
|
@ -744,6 +742,7 @@ class Backend_api extends CI_Controller {
|
|||
* [AJAX] Filter services categories with key string.
|
||||
*
|
||||
* @param string $_POST['key'] The key string used to filter the records.
|
||||
*
|
||||
* @return array Returns a json encoded array back to client with the category records.
|
||||
*/
|
||||
public function ajax_filter_service_categories() {
|
||||
|
@ -768,6 +767,7 @@ class Backend_api extends CI_Controller {
|
|||
* [AJAX] Filter admin records with string key.
|
||||
*
|
||||
* @param string $_POST['key'] The key string used to filter the records.
|
||||
*
|
||||
* @return array Returns a json encoded array back to client with the admin records.
|
||||
*/
|
||||
public function ajax_filter_admins() {
|
||||
|
@ -798,6 +798,7 @@ class Backend_api extends CI_Controller {
|
|||
*
|
||||
* @param array $_POST['admin'] A json encoded array that contains the admin data. If an 'id'
|
||||
* value is provided then the record is going to be updated.
|
||||
*
|
||||
* @return array Returns an array with the operation status and the record id that was
|
||||
* saved into the database.
|
||||
*/
|
||||
|
@ -832,6 +833,7 @@ class Backend_api extends CI_Controller {
|
|||
* [AJAX] Delete an admin record from the database.
|
||||
*
|
||||
* @param numeric $_POST['admin_id'] The id of the record to be deleted.
|
||||
*
|
||||
* @return string Returns the operation result constant (AJAX_SUCESS or AJAX_FAILURE).
|
||||
*/
|
||||
public function ajax_delete_admin() {
|
||||
|
@ -854,6 +856,7 @@ class Backend_api extends CI_Controller {
|
|||
* [AJAX] Filter provider records with string key.
|
||||
*
|
||||
* @param string $_POST['key'] The key string used to filter the records.
|
||||
*
|
||||
* @return array Returns a json encoded array back to client with the provider records.
|
||||
*/
|
||||
public function ajax_filter_providers() {
|
||||
|
@ -884,6 +887,7 @@ class Backend_api extends CI_Controller {
|
|||
*
|
||||
* @param array $_POST['provider'] A json encoded array that contains the provider data. If an 'id'
|
||||
* value is provided then the record is going to be updated.
|
||||
*
|
||||
* @return string Returns the success contant 'AJAX_SUCCESS' so javascript knows that
|
||||
* everything completed successfully.
|
||||
*/
|
||||
|
@ -923,6 +927,7 @@ class Backend_api extends CI_Controller {
|
|||
* [AJAX] Delete a provider record from the database.
|
||||
*
|
||||
* @param numeric $_POST['provider_id'] The id of the record to be deleted.
|
||||
*
|
||||
* @return string Returns the operation result constant (AJAX_SUCESS or AJAX_FAILURE).
|
||||
*/
|
||||
public function ajax_delete_provider() {
|
||||
|
@ -945,6 +950,7 @@ class Backend_api extends CI_Controller {
|
|||
* [AJAX] Filter secretary records with string key.
|
||||
*
|
||||
* @param string $_POST['key'] The key string used to filter the records.
|
||||
*
|
||||
* @return array Returns a json encoded array back to client with the secretary records.
|
||||
*/
|
||||
public function ajax_filter_secretaries() {
|
||||
|
@ -975,6 +981,7 @@ class Backend_api extends CI_Controller {
|
|||
*
|
||||
* @param array $_POST['secretary'] A json encoded array that contains the secretary data.
|
||||
* If an 'id' value is provided then the record is going to be updated.
|
||||
*
|
||||
* @return string Returns the success contant 'AJAX_SUCCESS' so javascript knows that
|
||||
* everything completed successfully.
|
||||
*/
|
||||
|
@ -1007,6 +1014,7 @@ class Backend_api extends CI_Controller {
|
|||
* [AJAX] Delete a secretary record from the database.
|
||||
*
|
||||
* @param numeric $_POST['secretary_id'] The id of the record to be deleted.
|
||||
*
|
||||
* @return string Returns the operation result constant (AJAX_SUCESS or AJAX_FAILURE).
|
||||
*/
|
||||
public function ajax_delete_secretary() {
|
||||
|
|
|
@ -1,44 +1,47 @@
|
|||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.0.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Errors Controller
|
||||
*
|
||||
* @package Controllers
|
||||
*/
|
||||
class Errors extends CI_Controller {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->library('session');
|
||||
// Set user's selected language.
|
||||
if ($this->session->userdata('language')) {
|
||||
$this->config->set_item('language', $this->session->userdata('language'));
|
||||
$this->lang->load('translations', $this->session->userdata('language'));
|
||||
} else {
|
||||
$this->lang->load('translations', $this->config->item('language')); // default
|
||||
}
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$this->e404();
|
||||
}
|
||||
|
||||
public function error404() {
|
||||
$this->load->model('settings_model');
|
||||
$view['company_name'] = $this->settings_model->get_setting('company_name');
|
||||
$this->load->view('general/error404', $view);
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file errors.php */
|
||||
/* Location: ./application/controllers/errors.php */
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.0.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Errors Controller
|
||||
*
|
||||
* @package Controllers
|
||||
*/
|
||||
class Errors extends CI_Controller {
|
||||
/**
|
||||
* Class Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->library('session');
|
||||
// Set user's selected language.
|
||||
if ($this->session->userdata('language')) {
|
||||
$this->config->set_item('language', $this->session->userdata('language'));
|
||||
$this->lang->load('translations', $this->session->userdata('language'));
|
||||
} else {
|
||||
$this->lang->load('translations', $this->config->item('language')); // default
|
||||
}
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$this->e404();
|
||||
}
|
||||
|
||||
public function error404() {
|
||||
$this->load->model('settings_model');
|
||||
$view['company_name'] = $this->settings_model->get_setting('company_name');
|
||||
$this->load->view('general/error404', $view);
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file errors.php */
|
||||
/* Location: ./application/controllers/errors.php */
|
||||
|
|
|
@ -14,9 +14,14 @@
|
|||
/**
|
||||
* Google Controller
|
||||
*
|
||||
* This controller handles the Google Calendar synchronization operations.
|
||||
*
|
||||
* @package Controllers
|
||||
*/
|
||||
class Google extends CI_Controller {
|
||||
/**
|
||||
* Class Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
* @package Controllers
|
||||
*/
|
||||
class Installation extends CI_Controller {
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
*/
|
||||
|
@ -37,7 +36,6 @@ class Installation extends CI_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Display the installation page.
|
||||
*/
|
||||
|
|
|
@ -1,71 +1,75 @@
|
|||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.0.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Test Controller
|
||||
*
|
||||
* @package Controllers
|
||||
*/
|
||||
class Test extends CI_Controller {
|
||||
/**
|
||||
* Class Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->driver('Unit_tests');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all available unit tests.
|
||||
*
|
||||
* We only test models at the moment. In the future the unit test will be
|
||||
* improved.
|
||||
*/
|
||||
public function index() {
|
||||
// User must be logged in as an admin in order to run the tests.
|
||||
$this->load->library('session');
|
||||
$this->session->set_userdata('dest_url', $this->config->item('base_url') . '/index.php/test');
|
||||
if ($this->session->userdata('role_slug') != DB_SLUG_ADMIN) {
|
||||
header('Location: ' . $this->config->item('base_url') . '/index.php/user/login');
|
||||
return;
|
||||
}
|
||||
|
||||
if (ENVIRONMENT !== 'development') {
|
||||
$this->output->set_output('Tests are available only at development environment. '
|
||||
. 'Please check your "index.php" file settings.');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->view('general/test');
|
||||
$this->unit_tests->run_all_tests();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test only the app models.
|
||||
*/
|
||||
public function models() {
|
||||
//$this->load->view('general/test');
|
||||
//$this->unit_tests->run_model_tests();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test only the app libraries.
|
||||
*/
|
||||
public function libraries() {
|
||||
//$this->load->view('general/test');
|
||||
//$this->unit_tests->run_library_tests();
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file test.php */
|
||||
/* Location: ./application/controllers/test.php */
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.0.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Test Controller
|
||||
*
|
||||
* NOTICE: This controller is outdated and must not be used.
|
||||
*
|
||||
* @deprecated v1.1.0
|
||||
*
|
||||
* @package Controllers
|
||||
*/
|
||||
class Test extends CI_Controller {
|
||||
/**
|
||||
* Class Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->driver('Unit_tests');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all available unit tests.
|
||||
*
|
||||
* We only test models at the moment. In the future the unit test will be
|
||||
* improved.
|
||||
*/
|
||||
public function index() {
|
||||
// User must be logged in as an admin in order to run the tests.
|
||||
$this->load->library('session');
|
||||
$this->session->set_userdata('dest_url', $this->config->item('base_url') . '/index.php/test');
|
||||
if ($this->session->userdata('role_slug') != DB_SLUG_ADMIN) {
|
||||
header('Location: ' . $this->config->item('base_url') . '/index.php/user/login');
|
||||
return;
|
||||
}
|
||||
|
||||
if (ENVIRONMENT !== 'development') {
|
||||
$this->output->set_output('Tests are available only at development environment. '
|
||||
. 'Please check your "index.php" file settings.');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->load->view('general/test');
|
||||
$this->unit_tests->run_all_tests();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test only the app models.
|
||||
*/
|
||||
public function models() {
|
||||
//$this->load->view('general/test');
|
||||
//$this->unit_tests->run_model_tests();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test only the app libraries.
|
||||
*/
|
||||
public function libraries() {
|
||||
//$this->load->view('general/test');
|
||||
//$this->unit_tests->run_library_tests();
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file test.php */
|
||||
/* Location: ./application/controllers/test.php */
|
||||
|
|
|
@ -1,150 +1,167 @@
|
|||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.0.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* User Controller
|
||||
*
|
||||
* @package Controllers
|
||||
*/
|
||||
class User extends CI_Controller {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->library('session');
|
||||
|
||||
// Set user's selected language.
|
||||
if ($this->session->userdata('language')) {
|
||||
$this->config->set_item('language', $this->session->userdata('language'));
|
||||
$this->lang->load('translations', $this->session->userdata('language'));
|
||||
} else {
|
||||
$this->lang->load('translations', $this->config->item('language')); // default
|
||||
}
|
||||
}
|
||||
|
||||
public function index() {
|
||||
header('Location: ' . $this->config->item('base_url') . '/index.php/user/login');
|
||||
}
|
||||
|
||||
public function login() {
|
||||
$this->load->model('settings_model');
|
||||
|
||||
$view['base_url'] = $this->config->item('base_url');
|
||||
$view['dest_url'] = $this->session->userdata('dest_url');
|
||||
|
||||
if (!$view['dest_url']) {
|
||||
$view['dest_url'] = $view['base_url'] . '/index.php/backend';
|
||||
}
|
||||
|
||||
$view['company_name'] = $this->settings_model->get_setting('company_name');
|
||||
$this->load->view('user/login', $view);
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
$this->load->model('settings_model');
|
||||
|
||||
$this->session->unset_userdata('user_id');
|
||||
$this->session->unset_userdata('user_email');
|
||||
$this->session->unset_userdata('role_slug');
|
||||
$this->session->unset_userdata('username');
|
||||
$this->session->unset_userdata('dest_url');
|
||||
|
||||
$view['base_url'] = $this->config->item('base_url');
|
||||
$view['company_name'] = $this->settings_model->get_setting('company_name');
|
||||
$this->load->view('user/logout', $view);
|
||||
}
|
||||
|
||||
public function forgot_password() {
|
||||
$this->load->model('settings_model');
|
||||
$view['base_url'] = $this->config->item('base_url');
|
||||
$view['company_name'] = $this->settings_model->get_setting('company_name');
|
||||
$this->load->view('user/forgot_password', $view);
|
||||
}
|
||||
|
||||
public function no_privileges() {
|
||||
$this->load->model('settings_model');
|
||||
$view['base_url'] = $this->config->item('base_url');
|
||||
$view['company_name'] = $this->settings_model->get_setting('company_name');
|
||||
$this->load->view('user/no_privileges', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* [AJAX] Check whether the user has entered the correct login credentials.
|
||||
*
|
||||
* The session data of a logged in user are the following:
|
||||
* 'user_id'
|
||||
* 'user_email'
|
||||
* 'role_slug'
|
||||
* 'dest_url'
|
||||
*/
|
||||
public function ajax_check_login() {
|
||||
try {
|
||||
if (!isset($_POST['username']) || !isset($_POST['password'])) {
|
||||
throw new Exception('Invalid credentials given!');
|
||||
}
|
||||
|
||||
$this->load->model('user_model');
|
||||
$user_data = $this->user_model->check_login($_POST['username'], $_POST['password']);
|
||||
|
||||
if ($user_data) {
|
||||
$this->session->set_userdata($user_data); // Save data on user's session.
|
||||
echo json_encode(AJAX_SUCCESS);
|
||||
} else {
|
||||
echo json_encode(AJAX_FAILURE);
|
||||
}
|
||||
|
||||
} catch(Exception $exc) {
|
||||
echo json_encode(array(
|
||||
'exceptions' => array(exceptionToJavaScript($exc))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate a new password for the current user, only if the username and
|
||||
* email address given corresond to an existing user in db.
|
||||
*
|
||||
* @param string $_POST['username']
|
||||
* @param string $_POST['email']
|
||||
*/
|
||||
public function ajax_forgot_password() {
|
||||
try {
|
||||
if (!isset($_POST['username']) || !isset($_POST['email'])) {
|
||||
throw new Exception('You must enter a valid username and email address in '
|
||||
. 'order to get a new password!');
|
||||
}
|
||||
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('settings_model');
|
||||
|
||||
$new_password = $this->user_model->regenerate_password($_POST['username'], $_POST['email']);
|
||||
|
||||
if ($new_password != FALSE) {
|
||||
$this->load->library('notifications');
|
||||
$company_settings = array(
|
||||
'company_name' => $this->settings_model->get_setting('company_name'),
|
||||
'company_link' => $this->settings_model->get_setting('company_link'),
|
||||
'company_email' => $this->settings_model->get_setting('company_email')
|
||||
);
|
||||
$this->notifications->send_password($new_password, $_POST['email'], $company_settings);
|
||||
}
|
||||
|
||||
echo ($new_password != FALSE) ? json_encode(AJAX_SUCCESS) : json_encode(AJAX_FAILURE);
|
||||
} catch(Exception $exc) {
|
||||
echo json_encode(array(
|
||||
'exceptions' => array(exceptionToJavaScript($exc))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file user.php */
|
||||
/* Location: ./application/controllers/user.php */
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.0.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* User Controller
|
||||
*
|
||||
* @package Controllers
|
||||
*/
|
||||
class User extends CI_Controller {
|
||||
/**
|
||||
* Class Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->library('session');
|
||||
|
||||
// Set user's selected language.
|
||||
if ($this->session->userdata('language')) {
|
||||
$this->config->set_item('language', $this->session->userdata('language'));
|
||||
$this->lang->load('translations', $this->session->userdata('language'));
|
||||
} else {
|
||||
$this->lang->load('translations', $this->config->item('language')); // default
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default Method
|
||||
*
|
||||
* The default method will redirect the browser to the user/login URL.
|
||||
*/
|
||||
public function index() {
|
||||
header('Location: ' . $this->config->item('base_url') . '/index.php/user/login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the login page.
|
||||
*/
|
||||
public function login() {
|
||||
$this->load->model('settings_model');
|
||||
|
||||
$view['base_url'] = $this->config->item('base_url');
|
||||
$view['dest_url'] = $this->session->userdata('dest_url');
|
||||
|
||||
if (!$view['dest_url']) {
|
||||
$view['dest_url'] = $view['base_url'] . '/index.php/backend';
|
||||
}
|
||||
|
||||
$view['company_name'] = $this->settings_model->get_setting('company_name');
|
||||
$this->load->view('user/login', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the logout page.
|
||||
*/
|
||||
public function logout() {
|
||||
$this->load->model('settings_model');
|
||||
|
||||
$this->session->unset_userdata('user_id');
|
||||
$this->session->unset_userdata('user_email');
|
||||
$this->session->unset_userdata('role_slug');
|
||||
$this->session->unset_userdata('username');
|
||||
$this->session->unset_userdata('dest_url');
|
||||
|
||||
$view['base_url'] = $this->config->item('base_url');
|
||||
$view['company_name'] = $this->settings_model->get_setting('company_name');
|
||||
$this->load->view('user/logout', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the forgot password page.
|
||||
*/
|
||||
public function forgot_password() {
|
||||
$this->load->model('settings_model');
|
||||
$view['base_url'] = $this->config->item('base_url');
|
||||
$view['company_name'] = $this->settings_model->get_setting('company_name');
|
||||
$this->load->view('user/forgot_password', $view);
|
||||
}
|
||||
|
||||
public function no_privileges() {
|
||||
$this->load->model('settings_model');
|
||||
$view['base_url'] = $this->config->item('base_url');
|
||||
$view['company_name'] = $this->settings_model->get_setting('company_name');
|
||||
$this->load->view('user/no_privileges', $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* [AJAX] Check whether the user has entered the correct login credentials.
|
||||
*
|
||||
* The session data of a logged in user are the following:
|
||||
* - 'user_id'
|
||||
* - 'user_email'
|
||||
* - 'role_slug'
|
||||
* - 'dest_url'
|
||||
*/
|
||||
public function ajax_check_login() {
|
||||
try {
|
||||
if (!isset($_POST['username']) || !isset($_POST['password'])) {
|
||||
throw new Exception('Invalid credentials given!');
|
||||
}
|
||||
|
||||
$this->load->model('user_model');
|
||||
$user_data = $this->user_model->check_login($_POST['username'], $_POST['password']);
|
||||
|
||||
if ($user_data) {
|
||||
$this->session->set_userdata($user_data); // Save data on user's session.
|
||||
echo json_encode(AJAX_SUCCESS);
|
||||
} else {
|
||||
echo json_encode(AJAX_FAILURE);
|
||||
}
|
||||
|
||||
} catch(Exception $exc) {
|
||||
echo json_encode(array(
|
||||
'exceptions' => array(exceptionToJavaScript($exc))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regenerate a new password for the current user, only if the username and
|
||||
* email address given corresond to an existing user in db.
|
||||
*
|
||||
* @param string $_POST['username']
|
||||
* @param string $_POST['email']
|
||||
*/
|
||||
public function ajax_forgot_password() {
|
||||
try {
|
||||
if (!isset($_POST['username']) || !isset($_POST['email'])) {
|
||||
throw new Exception('You must enter a valid username and email address in '
|
||||
. 'order to get a new password!');
|
||||
}
|
||||
|
||||
$this->load->model('user_model');
|
||||
$this->load->model('settings_model');
|
||||
|
||||
$new_password = $this->user_model->regenerate_password($_POST['username'], $_POST['email']);
|
||||
|
||||
if ($new_password != FALSE) {
|
||||
$this->load->library('notifications');
|
||||
$company_settings = array(
|
||||
'company_name' => $this->settings_model->get_setting('company_name'),
|
||||
'company_link' => $this->settings_model->get_setting('company_link'),
|
||||
'company_email' => $this->settings_model->get_setting('company_email')
|
||||
);
|
||||
$this->notifications->send_password($new_password, $_POST['email'], $company_settings);
|
||||
}
|
||||
|
||||
echo ($new_password != FALSE) ? json_encode(AJAX_SUCCESS) : json_encode(AJAX_FAILURE);
|
||||
} catch(Exception $exc) {
|
||||
echo json_encode(array(
|
||||
'exceptions' => array(exceptionToJavaScript($exc))
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file user.php */
|
||||
/* Location: ./application/controllers/user.php */
|
||||
|
|
|
@ -13,7 +13,6 @@ root {
|
|||
display: block;
|
||||
}
|
||||
|
||||
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
|
@ -241,6 +240,7 @@ body {
|
|||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
|
||||
/* MOBILE DEVICES
|
||||
------------------------------------------------------------------------- */
|
||||
@media(max-width:768px) {
|
||||
|
|
Loading…
Reference in a new issue