117 lines
3.2 KiB
PHP
117 lines
3.2 KiB
PHP
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
/**
|
|
* AMS
|
|
*
|
|
* @package HMVC
|
|
* @author Venba
|
|
* @copyright 2022 Venba
|
|
* @license https://venbainfotech.com/licenses/MIT MIT License
|
|
* @link <URI> (description)
|
|
* @version GIT: $Id$
|
|
* @since Version 0.0.1
|
|
* @filesource
|
|
*
|
|
*/
|
|
|
|
class Auth extends MY_Controller
|
|
{
|
|
/**
|
|
* [__construct description]
|
|
*
|
|
* @method __construct
|
|
*/
|
|
public function __construct()
|
|
{
|
|
// To inherit directly the attributes of the parent class.
|
|
parent::__construct();
|
|
$this->load->model('auth_model');
|
|
}
|
|
|
|
/**
|
|
* [index description]
|
|
*
|
|
* @method index
|
|
*
|
|
* @return [type] [description]
|
|
*/
|
|
public function index()
|
|
{
|
|
//echo site_url();
|
|
// Example
|
|
if(check_auth())
|
|
{
|
|
redirect('dashboard');
|
|
}
|
|
else{
|
|
$this->layout->load_view('auth/login');
|
|
}
|
|
// $this->load->view('welcome/welcome_message');
|
|
// $this->load->view('welcome_message');
|
|
}
|
|
|
|
public function authendicate()
|
|
{
|
|
$user = $this->auth_model->validate_user();
|
|
//print_r($user);die();
|
|
// echo hash_password('password');die();
|
|
|
|
if (empty($user)) {
|
|
redirect('login');
|
|
}
|
|
// if (!empty($user) && $user->status == 0) {
|
|
// // account pending
|
|
// echo json_encode(array('st'=>2));
|
|
// exit();
|
|
// }
|
|
// if (!empty($user) && $user->status == 2) {
|
|
// // account suspend
|
|
// echo json_encode(array('st'=>3));
|
|
// exit();
|
|
// }
|
|
|
|
|
|
|
|
// if ($user->role == 'user') {
|
|
// $diff = date_difference($user->created_at);
|
|
// if (!empty($user) && $user->email_verified == 0 && $this->settings->enable_email_verify == 1 && $diff < 2) {
|
|
// // email verify
|
|
// echo json_encode(array('st'=>4));
|
|
// exit();
|
|
// }
|
|
// }
|
|
|
|
|
|
// if ($user->role == 'subadmin' || $user->role == 'editor' || $user->role == 'viewer') {
|
|
// $user_id = $user->parent_id;
|
|
// }else{
|
|
// $user_id = $user->id;
|
|
// }
|
|
|
|
// if valid
|
|
if(password_verify($this->input->post('password'), $user->password))
|
|
{
|
|
$data = array(
|
|
'id' => $user->id,
|
|
'name' => $user->name,
|
|
//'thumb' => $user->thumb,
|
|
'email' =>$user->email,
|
|
'role' =>$user->role,
|
|
'action_permit' =>$user->action_permit,
|
|
'business_id' =>$user->business_id,
|
|
'logged_in' => TRUE
|
|
);
|
|
$data = $this->security->xss_clean($data);
|
|
$this->session->set_userdata($data);
|
|
redirect('dashboard');
|
|
}
|
|
redirect('login');
|
|
}
|
|
|
|
public function logout()
|
|
{
|
|
$this->auth_model->logout();
|
|
redirect('login');
|
|
}
|
|
}
|