1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
<?php
/**
* Kalkun
* An open source web based SMS Management
*
* @package Kalkun
* @author Kalkun Dev Team
* @license https://spdx.org/licenses/GPL-2.0-or-later.html
* @link https://kalkun.sourceforge.io/
*/
// ------------------------------------------------------------------------
/**
* Login Class
*
* @package Kalkun
* @subpackage Login
* @category Controllers
*/
class Login extends CI_Controller {
public $idiom = 'english';
/**
* Constructor
*
* @access public
*/
function __construct()
{
parent::__construct();
// language
$this->load->helper('i18n');
$i18n = new MY_Lang();
if ($this->input->post('idiom') !== NULL)
{
$this->idiom = $this->input->post('idiom');
}
else
{
if ($this->input->get('l') !== NULL)
{
$this->idiom = $this->input->get('l');
}
else
{
$this->idiom = $i18n->get_idiom();
}
}
$this->lang->load('kalkun', $this->idiom);
$this->load->library('session');
$this->load->database();
$this->load->model('Kalkun_model');
}
// --------------------------------------------------------------------
/**
* Index
*
* Display login form and handle login process
*
* @access public
*/
function index()
{
$this->load->helper('form');
$this->session->set_flashdata(
'bef_login_post_data',
$this->session->flashdata('bef_login_post_data')
);
if ($_POST && empty($this->input->post('change_language')))
{
$this->Kalkun_model->login();
}
$data['idiom'] = $this->idiom;
$data['language_list'] = $this->lang->kalkun_supported_languages();
$this->load->view('main/login', $data);
}
// --------------------------------------------------------------------
/**
* Logout
*
* Logout process, destroy user session
*
* @access public
*/
function logout()
{
$this->session->sess_destroy();
redirect('login');
}
// --------------------------------------------------------------------
/**
* Forgot Password
*
* Forgot password form
*
* @access public
*/
function forgot_password()
{
$this->load->model('Message_model');
$this->load->helper('form');
if ($_POST && empty($this->input->post('change_language')))
{
$token = $this->Kalkun_model->forgot_password();
if ( ! $token)
{
// Remain silent
}
else
{
// Send token to user
$data['class'] = '1';
$data['dest'] = $token['phone'];
$data['date'] = date('Y-m-d H:i:s');
$data['message'] = tr_raw('To reset your Kalkun password please visit {0}', NULL, site_url('login/password_reset/'.$token['token']).'?l='.$this->idiom);
$data['delivery_report'] = 'default';
$data['uid'] = 1;
$this->Message_model->send_messages($data);
}
if (empty($this->session->flashdata('errorlogin')))
{
$this->session->set_flashdata('errorlogin', tr_raw('If you are a registered user, a SMS has been sent to you.'));
}
redirect('login/forgot_password?l='.$this->idiom);
}
$data['language_list'] = $this->lang->kalkun_supported_languages();
$data['idiom'] = $this->idiom;
$this->load->view('main/forgot_password', $data);
}
// --------------------------------------------------------------------
/**
* Password Reset
*
* Password reset form
*
* @access public
*/
function password_reset($token = NULL)
{
$this->load->helper('form');
$password_submitted = ($_POST && empty($this->input->post('change_language')));
if ($password_submitted)
{
$token = $this->input->post('token');
}
$user_token = $this->Kalkun_model->valid_token($token);
if ($user_token === FALSE)
{
$this->session->set_flashdata('errorlogin', tr_raw('Token invalid.'));
redirect('login/forgot_password?l='.$this->idiom);
}
else
{
if ($password_submitted)
{
$this->Kalkun_model->update_password($user_token['id_user']);
$this->Kalkun_model->delete_token($user_token['id_user']);
$this->session->set_flashdata('errorlogin', tr_raw('Password changed successfully.'));
redirect('login?l='.$this->idiom);
}
else
{
$data['token'] = $token;
$data['idiom'] = $this->idiom;
$data['language_list'] = $this->lang->kalkun_supported_languages();
$data['idiom'] = $this->idiom;
$this->load->view('main/password_reset', $data);
}
}
}
}
|