--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/controllers/au.php Thu Dec 25 11:25:58 2008 +0000
@@ -0,0 +1,384 @@
+<?php
+class Au extends Controller
+{
+ // local var
+ private $referer_page;
+ private $obj;
+ private $data;
+ private $use_cap;
+
+ function Au()
+ {
+ parent::Controller();
+ $this->load->helper(array('form', 'url'));
+ $this->load->library('validation');
+ $this->load->library('parser');
+ $this->load->library('aulib');
+
+ $this->obj = & get_instance();
+ if(!$this->obj->session->flashdata('referer'))
+ $this->referer_page = (isset($_SERVER['HTTP_REFERER']))? $_SERVER['HTTP_REFERER'] : '';
+ else
+ $this->referer_page = $this->obj->session->flashdata('referer');
+ $this->obj->session->set_flashdata('referer', $this->referer_page);
+ //$this->config->load('auconfig');
+ if ($this->config->item('au_language') != '')
+ $curLang = $this->config->item('au_language');
+ else
+ $curLang = $this->config->item('language');
+ $this->lang->load('au', $curLang);
+ $this->use_cap = $this->config->item('au_capcha_use');
+ }
+
+ /*
+ * All view's call from this function
+ * You may customize output as you want from one point
+ */
+ function _show_view($view_name)
+ {
+ $this->parser->parse($view_name, $this->data);
+ }
+
+ /*
+ * Login page
+ */
+ function login()
+ {
+ $rules['username'] = "trim|required|min_length[4]|max_length[12]|xss_clean";
+ $rules['password'] = "trim|required|md5";
+ if($this->use_cap) $rules['captcha'] = "trim|required|callback__captcha_check";
+ $this->validation->set_rules($rules);
+
+ $fields['username'] = '"'.$this->lang->line('form_username').'"';
+ $fields['password'] = '"'.$this->lang->line('form_password').'"';
+ if($this->use_cap)
+ {
+ $fields['captcha'] = '"'.$this->lang->line('form_captcha').'"';
+ $this->validation->set_message('_captcha_check', $this->lang->line('error_captcha'));
+ }
+ $this->validation->set_fields($fields);
+
+ if ($this->validation->run() == FALSE)
+ {
+ $this->data['form_title'] = $this->lang->line('title_login');
+ $this->data['username_label'] = $this->lang->line('form_username');
+ $this->data['username_value'] = $this->validation->username;
+ $this->data['username_error'] = $this->validation->username_error;
+ $this->data['password_label'] = $this->lang->line('form_password');
+ $this->data['password_error'] = $this->validation->password_error;
+ $this->data['autologin_label'] = $this->lang->line('form_check_autologin');
+ if($this->use_cap)
+ {
+ $cap = $this->aulib->getCaptcha();
+ $this->session->set_userdata('captcha', $cap['word']);
+ $this->data['captcha_label'] = $this->lang->line('form_captcha');
+ $this->data['captcha'] = $cap['image'];
+ $this->data['captcha_value'] = '<input type="text" name="captcha" value="" size="20" />';
+ $this->data['captcha_error'] = $this->validation->captcha_error;
+ }
+ else
+ {
+ $this->data['captcha_label'] = '';
+ $this->data['captcha'] = '';
+ $this->data['captcha_error'] = '';
+ $this->data['captcha_value'] = '';
+ }
+ $this->data['submit_label'] = $this->lang->line('form_ok');
+ $this->data['registers_link'] = anchor('au/registers', $this->lang->line('form_registers'));
+ $this->data['pass_change_link'] = anchor('au/change', $this->lang->line('form_pass_change'));
+ $this->data['pass_forgot_link'] = anchor('au/forgotten', $this->lang->line('form_pass_forgot'));
+ $this->_show_view('au/login.php');
+ }
+ else
+ {
+ $name = $this->input->post('username');
+ $pass = $this->input->post('password');
+ $autologin = $this->input->post('autologin');
+ $user_id = $this->aumodel->login($name, $pass, $autologin);
+ $this->aulib->setSessionId($user_id, $autologin);
+ if( $user_id )
+ {
+ header('Location: '.$this->referer_page);
+ }
+ else
+ {
+ $this->data['message'] = $this->lang->line('error_login');
+ $this->_show_view('au/blank.php');
+ }
+ }
+ }
+
+ /*
+ * Terminate user's session and show index page
+ */
+ function logout()
+ {
+ $this->aulib->setSessionId(-1, FALSE);
+ redirect(index_page(), 'refresh');
+ }
+
+ /*
+ * Page for registers new user
+ */
+ function registers()
+ {
+ $rules['username'] = "trim|required|min_length[4]|max_length[12]|xss_clean|callback__username_check";
+ $rules['password'] = "trim|required|matches[passconf]|md5";
+ $rules['passconf'] = "trim|required|md5";
+ $rules['email'] = "trim|required|valid_email";
+ if($this->use_cap) $rules['captcha'] = "trim|required|callback__captcha_check";
+ $this->validation->set_rules($rules);
+
+ $fields['username'] = '"'.$this->lang->line('form_username').'"';
+ $fields['password'] = '"'.$this->lang->line('form_password').'"';
+ $fields['passconf'] = '"'.$this->lang->line('form_password_confirm').'"';
+ $fields['email'] = '"'.$this->lang->line('form_email').'"';
+ $this->validation->set_message('_username_check', $this->lang->line('error_name_exist'));
+ if($this->use_cap)
+ {
+ $fields['captcha'] = '"'.$this->lang->line('form_captcha').'"';
+ $this->validation->set_message('_captcha_check', $this->lang->line('error_captcha'));
+ }
+ $this->validation->set_fields($fields);
+
+ if ($this->validation->run() == FALSE)
+ {
+ $this->data['form_title'] = $this->lang->line('title_registers');
+ $this->data['username_label'] = $this->lang->line('form_username');
+ $this->data['username_value'] = $this->validation->username;
+ $this->data['username_error'] = $this->validation->username_error;
+ $this->data['password_label'] = $this->lang->line('form_password');
+ $this->data['password_error'] = $this->validation->password_error;
+ $this->data['password_confirm_label'] = $this->lang->line('form_password_confirm');
+ $this->data['password_confirm_error'] = $this->validation->passconf_error;
+ $this->data['email_label'] = $this->lang->line('form_email');
+ $this->data['email_value'] = $this->validation->email;
+ $this->data['email_error'] = $this->validation->email_error;
+ if($this->use_cap)
+ {
+ $cap = $this->aulib->getCaptcha();
+ $this->session->set_userdata('captcha', $cap['word']);
+ $this->data['captcha_label'] = $this->lang->line('form_captcha');
+ $this->data['captcha'] = $cap['image'];
+ $this->data['captcha_error'] = $this->validation->captcha_error;
+ $this->data['captcha_value'] = '<input type="text" name="captcha" value="" size="20" />';
+ }
+ else
+ {
+ $this->data['captcha_label'] = '';
+ $this->data['captcha'] = '';
+ $this->data['captcha_error'] = '';
+ $this->data['captcha_value'] = '';
+ }
+ $this->data['submit_label'] = $this->lang->line('form_ok');
+ $this->_show_view('au/registers.php');
+ }
+ else
+ {
+ $confirm = $this->config->item('registers_via_email');
+ $name = $this->input->post('username');
+ $pass = $this->input->post('password');
+ $email = $this->input->post('email');
+ if( $this->aumodel->registers($name, $pass, $email, $confirm) )
+ {
+ if($confirm)
+ {
+ $this->data['message'] = $this->lang->line('confirm_registers_message');
+ $this->_show_view('au/blank.php');
+ }
+ else
+ header('Location: '.$this->referer_page);
+ }
+ else
+ {
+ $this->data['message'] = $this->lang->line('registers_failure_message');
+ $this->_show_view('au/blank.php');
+ }
+ }
+ }
+
+ /*
+ * Satellite function for register new user
+ * Check if user name is present in DB
+ */
+ function _username_check($new_name=NULL)
+ {
+ return !$this->aumodel->check_name($new_name);
+ }
+
+ /*
+ * Check for correct captcha input
+ */
+ function _captcha_check($captcha)
+ {
+ return ($captcha == $this->session->userdata('captcha'));
+ }
+
+ /*
+ * Page for confirmation from e-mail letter
+ */
+ function confirm()
+ {
+ $id = $this->uri->segment(3);
+ $mess = $this->uri->segment(4);
+ if($this->aumodel->confirmEmail($id, $mess))
+ $this->data['message'] = $this->lang->line('registers_confirmed');
+ else
+ $this->data['message'] = $this->lang->line('registers_fail');
+ $this->_show_view('au/blank.php');
+ }
+
+ /*
+ * Show deny access page
+ */
+ function denyaccess()
+ {
+ $this->data['message'] = $this->lang->line('deny_access');
+ $this->_show_view('au/blank.php');
+ }
+
+ /*
+ * Change password page
+ */
+ function change()
+ {
+ $rules['username'] = "trim|required|min_length[4]|max_length[12]|xss_clean";
+ $rules['password'] = "trim|required|md5";
+ $rules['new_password'] = "trim|required|matches[new_password_conf]|md5";
+ $rules['new_password_conf'] = "trim|required|md5";
+ if($this->use_cap) $rules['captcha'] = "trim|required|callback__captcha_check";
+ $this->validation->set_rules($rules);
+
+ $fields['username'] = '"'.$this->lang->line('form_username').'"';
+ $fields['password'] = '"'.$this->lang->line('form_old_password').'"';
+ $fields['new_password'] = '"'.$this->lang->line('form_new_password').'"';
+ $fields['new_password_conf'] = '"'.$this->lang->line('form_password_confirm').'"';
+ if($this->use_cap)
+ {
+ $fields['captcha'] = '"'.$this->lang->line('form_captcha').'"';
+ $this->validation->set_message('_captcha_check', $this->lang->line('error_captcha'));
+ }
+ $this->validation->set_fields($fields);
+
+ if ($this->validation->run() == FALSE)
+ {
+ $this->data['form_title'] = $this->lang->line('title_login');
+ $this->data['username_label'] = $this->lang->line('form_username');
+ $this->data['username_value'] = $this->validation->username;
+ $this->data['username_error'] = $this->validation->username_error;
+ $this->data['password_label'] = $this->lang->line('form_old_password');
+ $this->data['password_error'] = $this->validation->password_error;
+ $this->data['new_password_label'] = $this->lang->line('form_new_password');
+ $this->data['new_password_error'] = $this->validation->new_password_error;
+ $this->data['new_password_conf_label'] = $this->lang->line('form_password_confirm');
+ $this->data['new_password_conf_error'] = $this->validation->new_password_conf_error;
+ $this->data['autologin_label'] = $this->lang->line('form_check_autologin');
+ if($this->use_cap)
+ {
+ $cap = $this->aulib->getCaptcha();
+ $this->session->set_userdata('captcha', $cap['word']);
+ $this->data['captcha_label'] = $this->lang->line('form_captcha');
+ $this->data['captcha'] = $cap['image'];
+ $this->data['captcha_error'] = $this->validation->captcha_error;
+ $this->data['captcha_value'] = '<input type="text" name="captcha" value="" size="20" />';
+ }
+ else
+ {
+ $this->data['captcha_label'] = '';
+ $this->data['captcha'] = '';
+ $this->data['captcha_error'] = '';
+ $this->data['captcha_value'] = '';
+ }
+ $this->data['submit_label'] = $this->lang->line('form_ok');
+ $this->_show_view('au/change.php');
+ }
+ else
+ {
+ $name = $this->input->post('username');
+ $pass = $this->input->post('password');
+ $new_pass = $this->input->post('new_password');
+ $autologin = $this->input->post('autologin');
+ $user_id = $this->aumodel->login($name, $pass, $autologin);
+ $this->aulib->setSessionId($user_id, $autologin);
+ if( $user_id )
+ {
+ $data = array('password' => $new_pass);
+ $this->aumodel->change($user_id, $data);
+ $this->data['message'] = $this->lang->line('confirm_password_change');
+ $this->_show_view('au/blank.php');
+ }
+ else
+ {
+ $this->data['message'] = $this->lang->line('error_password_change');
+ $this->_show_view('au/blank.php');
+ }
+ }
+ }
+
+ /*
+ * Forgotten pasword page
+ */
+ function forgotten()
+ {
+ $rules['username'] = "trim|required|min_length[4]|max_length[12]|xss_clean";
+ $rules['email'] = "trim|required|valid_email";
+ if($this->use_cap) $rules['captcha'] = "trim|required|callback__captcha_check";
+ $this->validation->set_rules($rules);
+
+ $fields['username'] = '"'.$this->lang->line('form_username').'"';
+ $fields['email'] = '"'.$this->lang->line('form_email').'"';
+ $this->validation->set_message('_username_check', $this->lang->line('error_name_exist'));
+ if($this->use_cap)
+ {
+ $fields['captcha'] = '"'.$this->lang->line('form_captcha').'"';
+ $this->validation->set_message('_captcha_check', $this->lang->line('error_captcha'));
+ }
+ $this->validation->set_fields($fields);
+
+ if ($this->validation->run() == FALSE)
+ {
+ $this->data['form_title'] = $this->lang->line('title_registers');
+ $this->data['username_label'] = $this->lang->line('form_username');
+ $this->data['username_value'] = $this->validation->username;
+ $this->data['username_error'] = $this->validation->username_error;
+ $this->data['email_label'] = $this->lang->line('form_email');
+ $this->data['email_value'] = $this->validation->email;
+ $this->data['email_error'] = $this->validation->email_error;
+ if($this->use_cap)
+ {
+ $cap = $this->aulib->getCaptcha();
+ $this->session->set_userdata('captcha', $cap['word']);
+ $this->data['captcha_label'] = $this->lang->line('form_captcha');
+ $this->data['captcha'] = $cap['image'];
+ $this->data['captcha_error'] = $this->validation->captcha_error;
+ $this->data['captcha_value'] = '<input type="text" name="captcha" value="" size="20" />';
+ }
+ else
+ {
+ $this->data['captcha_label'] = '';
+ $this->data['captcha'] = '';
+ $this->data['captcha_error'] = '';
+ $this->data['captcha_value'] = '';
+ }
+ $this->data['submit_label'] = $this->lang->line('form_ok');
+ $this->_show_view('au/forgotten.php');
+ }
+ else
+ {
+ $name = $this->input->post('username');
+ $email = $this->input->post('email');
+ if( $this->aumodel->forgotten($name, $email) )
+ {
+ $this->data['message'] = $this->lang->line('confirm_forgotten_message');
+ $this->_show_view('au/blank.php');
+ }
+ else
+ {
+ $this->data['message'] = $this->lang->line('forgotten_failure_message');
+ $this->_show_view('au/blank.php');
+ }
+
+ }
+ }
+}
+?>