0
|
1 |
<?php
|
|
2 |
class Au extends Controller
|
|
3 |
{
|
|
4 |
// local var
|
|
5 |
private $referer_page;
|
|
6 |
private $obj;
|
|
7 |
private $data;
|
|
8 |
private $use_cap;
|
|
9 |
|
|
10 |
function Au()
|
|
11 |
{
|
|
12 |
parent::Controller();
|
|
13 |
$this->load->helper(array('form', 'url'));
|
|
14 |
$this->load->library('validation');
|
|
15 |
$this->load->library('parser');
|
|
16 |
$this->load->library('aulib');
|
|
17 |
|
|
18 |
$this->obj = & get_instance();
|
|
19 |
if(!$this->obj->session->flashdata('referer'))
|
|
20 |
$this->referer_page = (isset($_SERVER['HTTP_REFERER']))? $_SERVER['HTTP_REFERER'] : '';
|
|
21 |
else
|
|
22 |
$this->referer_page = $this->obj->session->flashdata('referer');
|
|
23 |
$this->obj->session->set_flashdata('referer', $this->referer_page);
|
|
24 |
//$this->config->load('auconfig');
|
|
25 |
if ($this->config->item('au_language') != '')
|
|
26 |
$curLang = $this->config->item('au_language');
|
|
27 |
else
|
|
28 |
$curLang = $this->config->item('language');
|
|
29 |
$this->lang->load('au', $curLang);
|
|
30 |
$this->use_cap = $this->config->item('au_capcha_use');
|
|
31 |
}
|
|
32 |
|
|
33 |
/*
|
|
34 |
* All view's call from this function
|
|
35 |
* You may customize output as you want from one point
|
|
36 |
*/
|
|
37 |
function _show_view($view_name)
|
|
38 |
{
|
|
39 |
$this->parser->parse($view_name, $this->data);
|
|
40 |
}
|
|
41 |
|
|
42 |
/*
|
|
43 |
* Login page
|
|
44 |
*/
|
|
45 |
function login()
|
|
46 |
{
|
|
47 |
$rules['username'] = "trim|required|min_length[4]|max_length[12]|xss_clean";
|
|
48 |
$rules['password'] = "trim|required|md5";
|
|
49 |
if($this->use_cap) $rules['captcha'] = "trim|required|callback__captcha_check";
|
|
50 |
$this->validation->set_rules($rules);
|
|
51 |
|
|
52 |
$fields['username'] = '"'.$this->lang->line('form_username').'"';
|
|
53 |
$fields['password'] = '"'.$this->lang->line('form_password').'"';
|
|
54 |
if($this->use_cap)
|
|
55 |
{
|
|
56 |
$fields['captcha'] = '"'.$this->lang->line('form_captcha').'"';
|
|
57 |
$this->validation->set_message('_captcha_check', $this->lang->line('error_captcha'));
|
|
58 |
}
|
|
59 |
$this->validation->set_fields($fields);
|
|
60 |
|
|
61 |
if ($this->validation->run() == FALSE)
|
|
62 |
{
|
|
63 |
$this->data['form_title'] = $this->lang->line('title_login');
|
|
64 |
$this->data['username_label'] = $this->lang->line('form_username');
|
|
65 |
$this->data['username_value'] = $this->validation->username;
|
|
66 |
$this->data['username_error'] = $this->validation->username_error;
|
|
67 |
$this->data['password_label'] = $this->lang->line('form_password');
|
|
68 |
$this->data['password_error'] = $this->validation->password_error;
|
|
69 |
$this->data['autologin_label'] = $this->lang->line('form_check_autologin');
|
|
70 |
if($this->use_cap)
|
|
71 |
{
|
|
72 |
$cap = $this->aulib->getCaptcha();
|
|
73 |
$this->session->set_userdata('captcha', $cap['word']);
|
|
74 |
$this->data['captcha_label'] = $this->lang->line('form_captcha');
|
|
75 |
$this->data['captcha'] = $cap['image'];
|
|
76 |
$this->data['captcha_value'] = '<input type="text" name="captcha" value="" size="20" />';
|
|
77 |
$this->data['captcha_error'] = $this->validation->captcha_error;
|
|
78 |
}
|
|
79 |
else
|
|
80 |
{
|
|
81 |
$this->data['captcha_label'] = '';
|
|
82 |
$this->data['captcha'] = '';
|
|
83 |
$this->data['captcha_error'] = '';
|
|
84 |
$this->data['captcha_value'] = '';
|
|
85 |
}
|
|
86 |
$this->data['submit_label'] = $this->lang->line('form_ok');
|
|
87 |
$this->data['registers_link'] = anchor('au/registers', $this->lang->line('form_registers'));
|
|
88 |
$this->data['pass_change_link'] = anchor('au/change', $this->lang->line('form_pass_change'));
|
|
89 |
$this->data['pass_forgot_link'] = anchor('au/forgotten', $this->lang->line('form_pass_forgot'));
|
|
90 |
$this->_show_view('au/login.php');
|
|
91 |
}
|
|
92 |
else
|
|
93 |
{
|
|
94 |
$name = $this->input->post('username');
|
|
95 |
$pass = $this->input->post('password');
|
|
96 |
$autologin = $this->input->post('autologin');
|
|
97 |
$user_id = $this->aumodel->login($name, $pass, $autologin);
|
|
98 |
$this->aulib->setSessionId($user_id, $autologin);
|
|
99 |
if( $user_id )
|
|
100 |
{
|
|
101 |
header('Location: '.$this->referer_page);
|
|
102 |
}
|
|
103 |
else
|
|
104 |
{
|
|
105 |
$this->data['message'] = $this->lang->line('error_login');
|
|
106 |
$this->_show_view('au/blank.php');
|
|
107 |
}
|
|
108 |
}
|
|
109 |
}
|
|
110 |
|
|
111 |
/*
|
|
112 |
* Terminate user's session and show index page
|
|
113 |
*/
|
|
114 |
function logout()
|
|
115 |
{
|
|
116 |
$this->aulib->setSessionId(-1, FALSE);
|
|
117 |
redirect(index_page(), 'refresh');
|
|
118 |
}
|
|
119 |
|
|
120 |
/*
|
|
121 |
* Page for registers new user
|
|
122 |
*/
|
|
123 |
function registers()
|
|
124 |
{
|
|
125 |
$rules['username'] = "trim|required|min_length[4]|max_length[12]|xss_clean|callback__username_check";
|
|
126 |
$rules['password'] = "trim|required|matches[passconf]|md5";
|
|
127 |
$rules['passconf'] = "trim|required|md5";
|
|
128 |
$rules['email'] = "trim|required|valid_email";
|
|
129 |
if($this->use_cap) $rules['captcha'] = "trim|required|callback__captcha_check";
|
|
130 |
$this->validation->set_rules($rules);
|
|
131 |
|
|
132 |
$fields['username'] = '"'.$this->lang->line('form_username').'"';
|
|
133 |
$fields['password'] = '"'.$this->lang->line('form_password').'"';
|
|
134 |
$fields['passconf'] = '"'.$this->lang->line('form_password_confirm').'"';
|
|
135 |
$fields['email'] = '"'.$this->lang->line('form_email').'"';
|
|
136 |
$this->validation->set_message('_username_check', $this->lang->line('error_name_exist'));
|
|
137 |
if($this->use_cap)
|
|
138 |
{
|
|
139 |
$fields['captcha'] = '"'.$this->lang->line('form_captcha').'"';
|
|
140 |
$this->validation->set_message('_captcha_check', $this->lang->line('error_captcha'));
|
|
141 |
}
|
|
142 |
$this->validation->set_fields($fields);
|
|
143 |
|
|
144 |
if ($this->validation->run() == FALSE)
|
|
145 |
{
|
|
146 |
$this->data['form_title'] = $this->lang->line('title_registers');
|
|
147 |
$this->data['username_label'] = $this->lang->line('form_username');
|
|
148 |
$this->data['username_value'] = $this->validation->username;
|
|
149 |
$this->data['username_error'] = $this->validation->username_error;
|
|
150 |
$this->data['password_label'] = $this->lang->line('form_password');
|
|
151 |
$this->data['password_error'] = $this->validation->password_error;
|
|
152 |
$this->data['password_confirm_label'] = $this->lang->line('form_password_confirm');
|
|
153 |
$this->data['password_confirm_error'] = $this->validation->passconf_error;
|
|
154 |
$this->data['email_label'] = $this->lang->line('form_email');
|
|
155 |
$this->data['email_value'] = $this->validation->email;
|
|
156 |
$this->data['email_error'] = $this->validation->email_error;
|
|
157 |
if($this->use_cap)
|
|
158 |
{
|
|
159 |
$cap = $this->aulib->getCaptcha();
|
|
160 |
$this->session->set_userdata('captcha', $cap['word']);
|
|
161 |
$this->data['captcha_label'] = $this->lang->line('form_captcha');
|
|
162 |
$this->data['captcha'] = $cap['image'];
|
|
163 |
$this->data['captcha_error'] = $this->validation->captcha_error;
|
|
164 |
$this->data['captcha_value'] = '<input type="text" name="captcha" value="" size="20" />';
|
|
165 |
}
|
|
166 |
else
|
|
167 |
{
|
|
168 |
$this->data['captcha_label'] = '';
|
|
169 |
$this->data['captcha'] = '';
|
|
170 |
$this->data['captcha_error'] = '';
|
|
171 |
$this->data['captcha_value'] = '';
|
|
172 |
}
|
|
173 |
$this->data['submit_label'] = $this->lang->line('form_ok');
|
|
174 |
$this->_show_view('au/registers.php');
|
|
175 |
}
|
|
176 |
else
|
|
177 |
{
|
|
178 |
$confirm = $this->config->item('registers_via_email');
|
|
179 |
$name = $this->input->post('username');
|
|
180 |
$pass = $this->input->post('password');
|
|
181 |
$email = $this->input->post('email');
|
|
182 |
if( $this->aumodel->registers($name, $pass, $email, $confirm) )
|
|
183 |
{
|
|
184 |
if($confirm)
|
|
185 |
{
|
|
186 |
$this->data['message'] = $this->lang->line('confirm_registers_message');
|
|
187 |
$this->_show_view('au/blank.php');
|
|
188 |
}
|
|
189 |
else
|
|
190 |
header('Location: '.$this->referer_page);
|
|
191 |
}
|
|
192 |
else
|
|
193 |
{
|
|
194 |
$this->data['message'] = $this->lang->line('registers_failure_message');
|
|
195 |
$this->_show_view('au/blank.php');
|
|
196 |
}
|
|
197 |
}
|
|
198 |
}
|
|
199 |
|
|
200 |
/*
|
|
201 |
* Satellite function for register new user
|
|
202 |
* Check if user name is present in DB
|
|
203 |
*/
|
|
204 |
function _username_check($new_name=NULL)
|
|
205 |
{
|
|
206 |
return !$this->aumodel->check_name($new_name);
|
|
207 |
}
|
|
208 |
|
|
209 |
/*
|
|
210 |
* Check for correct captcha input
|
|
211 |
*/
|
|
212 |
function _captcha_check($captcha)
|
|
213 |
{
|
|
214 |
return ($captcha == $this->session->userdata('captcha'));
|
|
215 |
}
|
|
216 |
|
|
217 |
/*
|
|
218 |
* Page for confirmation from e-mail letter
|
|
219 |
*/
|
|
220 |
function confirm()
|
|
221 |
{
|
|
222 |
$id = $this->uri->segment(3);
|
|
223 |
$mess = $this->uri->segment(4);
|
|
224 |
if($this->aumodel->confirmEmail($id, $mess))
|
|
225 |
$this->data['message'] = $this->lang->line('registers_confirmed');
|
|
226 |
else
|
|
227 |
$this->data['message'] = $this->lang->line('registers_fail');
|
|
228 |
$this->_show_view('au/blank.php');
|
|
229 |
}
|
|
230 |
|
|
231 |
/*
|
|
232 |
* Show deny access page
|
|
233 |
*/
|
|
234 |
function denyaccess()
|
|
235 |
{
|
|
236 |
$this->data['message'] = $this->lang->line('deny_access');
|
|
237 |
$this->_show_view('au/blank.php');
|
|
238 |
}
|
|
239 |
|
|
240 |
/*
|
|
241 |
* Change password page
|
|
242 |
*/
|
|
243 |
function change()
|
|
244 |
{
|
|
245 |
$rules['username'] = "trim|required|min_length[4]|max_length[12]|xss_clean";
|
|
246 |
$rules['password'] = "trim|required|md5";
|
|
247 |
$rules['new_password'] = "trim|required|matches[new_password_conf]|md5";
|
|
248 |
$rules['new_password_conf'] = "trim|required|md5";
|
|
249 |
if($this->use_cap) $rules['captcha'] = "trim|required|callback__captcha_check";
|
|
250 |
$this->validation->set_rules($rules);
|
|
251 |
|
|
252 |
$fields['username'] = '"'.$this->lang->line('form_username').'"';
|
|
253 |
$fields['password'] = '"'.$this->lang->line('form_old_password').'"';
|
|
254 |
$fields['new_password'] = '"'.$this->lang->line('form_new_password').'"';
|
|
255 |
$fields['new_password_conf'] = '"'.$this->lang->line('form_password_confirm').'"';
|
|
256 |
if($this->use_cap)
|
|
257 |
{
|
|
258 |
$fields['captcha'] = '"'.$this->lang->line('form_captcha').'"';
|
|
259 |
$this->validation->set_message('_captcha_check', $this->lang->line('error_captcha'));
|
|
260 |
}
|
|
261 |
$this->validation->set_fields($fields);
|
|
262 |
|
|
263 |
if ($this->validation->run() == FALSE)
|
|
264 |
{
|
|
265 |
$this->data['form_title'] = $this->lang->line('title_login');
|
|
266 |
$this->data['username_label'] = $this->lang->line('form_username');
|
|
267 |
$this->data['username_value'] = $this->validation->username;
|
|
268 |
$this->data['username_error'] = $this->validation->username_error;
|
|
269 |
$this->data['password_label'] = $this->lang->line('form_old_password');
|
|
270 |
$this->data['password_error'] = $this->validation->password_error;
|
|
271 |
$this->data['new_password_label'] = $this->lang->line('form_new_password');
|
|
272 |
$this->data['new_password_error'] = $this->validation->new_password_error;
|
|
273 |
$this->data['new_password_conf_label'] = $this->lang->line('form_password_confirm');
|
|
274 |
$this->data['new_password_conf_error'] = $this->validation->new_password_conf_error;
|
|
275 |
$this->data['autologin_label'] = $this->lang->line('form_check_autologin');
|
|
276 |
if($this->use_cap)
|
|
277 |
{
|
|
278 |
$cap = $this->aulib->getCaptcha();
|
|
279 |
$this->session->set_userdata('captcha', $cap['word']);
|
|
280 |
$this->data['captcha_label'] = $this->lang->line('form_captcha');
|
|
281 |
$this->data['captcha'] = $cap['image'];
|
|
282 |
$this->data['captcha_error'] = $this->validation->captcha_error;
|
|
283 |
$this->data['captcha_value'] = '<input type="text" name="captcha" value="" size="20" />';
|
|
284 |
}
|
|
285 |
else
|
|
286 |
{
|
|
287 |
$this->data['captcha_label'] = '';
|
|
288 |
$this->data['captcha'] = '';
|
|
289 |
$this->data['captcha_error'] = '';
|
|
290 |
$this->data['captcha_value'] = '';
|
|
291 |
}
|
|
292 |
$this->data['submit_label'] = $this->lang->line('form_ok');
|
|
293 |
$this->_show_view('au/change.php');
|
|
294 |
}
|
|
295 |
else
|
|
296 |
{
|
|
297 |
$name = $this->input->post('username');
|
|
298 |
$pass = $this->input->post('password');
|
|
299 |
$new_pass = $this->input->post('new_password');
|
|
300 |
$autologin = $this->input->post('autologin');
|
|
301 |
$user_id = $this->aumodel->login($name, $pass, $autologin);
|
|
302 |
$this->aulib->setSessionId($user_id, $autologin);
|
|
303 |
if( $user_id )
|
|
304 |
{
|
|
305 |
$data = array('password' => $new_pass);
|
|
306 |
$this->aumodel->change($user_id, $data);
|
|
307 |
$this->data['message'] = $this->lang->line('confirm_password_change');
|
|
308 |
$this->_show_view('au/blank.php');
|
|
309 |
}
|
|
310 |
else
|
|
311 |
{
|
|
312 |
$this->data['message'] = $this->lang->line('error_password_change');
|
|
313 |
$this->_show_view('au/blank.php');
|
|
314 |
}
|
|
315 |
}
|
|
316 |
}
|
|
317 |
|
|
318 |
/*
|
|
319 |
* Forgotten pasword page
|
|
320 |
*/
|
|
321 |
function forgotten()
|
|
322 |
{
|
|
323 |
$rules['username'] = "trim|required|min_length[4]|max_length[12]|xss_clean";
|
|
324 |
$rules['email'] = "trim|required|valid_email";
|
|
325 |
if($this->use_cap) $rules['captcha'] = "trim|required|callback__captcha_check";
|
|
326 |
$this->validation->set_rules($rules);
|
|
327 |
|
|
328 |
$fields['username'] = '"'.$this->lang->line('form_username').'"';
|
|
329 |
$fields['email'] = '"'.$this->lang->line('form_email').'"';
|
|
330 |
$this->validation->set_message('_username_check', $this->lang->line('error_name_exist'));
|
|
331 |
if($this->use_cap)
|
|
332 |
{
|
|
333 |
$fields['captcha'] = '"'.$this->lang->line('form_captcha').'"';
|
|
334 |
$this->validation->set_message('_captcha_check', $this->lang->line('error_captcha'));
|
|
335 |
}
|
|
336 |
$this->validation->set_fields($fields);
|
|
337 |
|
|
338 |
if ($this->validation->run() == FALSE)
|
|
339 |
{
|
|
340 |
$this->data['form_title'] = $this->lang->line('title_registers');
|
|
341 |
$this->data['username_label'] = $this->lang->line('form_username');
|
|
342 |
$this->data['username_value'] = $this->validation->username;
|
|
343 |
$this->data['username_error'] = $this->validation->username_error;
|
|
344 |
$this->data['email_label'] = $this->lang->line('form_email');
|
|
345 |
$this->data['email_value'] = $this->validation->email;
|
|
346 |
$this->data['email_error'] = $this->validation->email_error;
|
|
347 |
if($this->use_cap)
|
|
348 |
{
|
|
349 |
$cap = $this->aulib->getCaptcha();
|
|
350 |
$this->session->set_userdata('captcha', $cap['word']);
|
|
351 |
$this->data['captcha_label'] = $this->lang->line('form_captcha');
|
|
352 |
$this->data['captcha'] = $cap['image'];
|
|
353 |
$this->data['captcha_error'] = $this->validation->captcha_error;
|
|
354 |
$this->data['captcha_value'] = '<input type="text" name="captcha" value="" size="20" />';
|
|
355 |
}
|
|
356 |
else
|
|
357 |
{
|
|
358 |
$this->data['captcha_label'] = '';
|
|
359 |
$this->data['captcha'] = '';
|
|
360 |
$this->data['captcha_error'] = '';
|
|
361 |
$this->data['captcha_value'] = '';
|
|
362 |
}
|
|
363 |
$this->data['submit_label'] = $this->lang->line('form_ok');
|
|
364 |
$this->_show_view('au/forgotten.php');
|
|
365 |
}
|
|
366 |
else
|
|
367 |
{
|
|
368 |
$name = $this->input->post('username');
|
|
369 |
$email = $this->input->post('email');
|
|
370 |
if( $this->aumodel->forgotten($name, $email) )
|
|
371 |
{
|
|
372 |
$this->data['message'] = $this->lang->line('confirm_forgotten_message');
|
|
373 |
$this->_show_view('au/blank.php');
|
|
374 |
}
|
|
375 |
else
|
|
376 |
{
|
|
377 |
$this->data['message'] = $this->lang->line('forgotten_failure_message');
|
|
378 |
$this->_show_view('au/blank.php');
|
|
379 |
}
|
|
380 |
|
|
381 |
}
|
|
382 |
}
|
|
383 |
}
|
|
384 |
?>
|