Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
- class Summer extends Controller {
- // Used for registering and changing password form validation
- var $min_username = 4;
- var $max_username = 20;
- var $min_password = 4;
- var $max_password = 20;
- /*
- *
- */
- function Summer() {
- parent::Controller();
- $this->load->library('Form_validation');
- $this->load->library('DX_Auth');
- $this->load->library('table');
- $this->load->helper('url');
- $this->load->helper('form');
- $this->load->helper('menu');
- }
- /*
- * Main functions
- */
- function index() {
- $data['page_title'] = 'Meridian School - Summer';
- $login_results = $this->dx_auth->is_logged_in();
- $data['login_results'] = $login_results;
- $this->load->view('common/header', $data);
- if ( $login_results ) {
- // $this->load->model('Membership');
- // $this->load->model('Person');
- $this->load->model('Classes');
- $data['summary'] = array (
- 'Child' => $this->Person->get_child_summary($id),
- 'Class' => $this->Class->get_class_summary($id),
- );
- $this->load->view('front/summary', $data);
- }
- $this->load->view('common/footer', $data);
- }
- /* */
- function login() {
- $data['page_title'] = 'Meridian School - Summer Login';
- $login_results = $this->dx_auth->is_logged_in();
- $data['login_results'] = $login_results;
- $this->load->view('common/header', $data);
- if ( ! $login_results) {
- $val = $this->form_validation;
- $val->set_error_delimiters('<div class="formerrors">', '</div>');
- // Set form validation rules
- $val->set_rules(
- 'username',
- 'Username',
- 'trim|required|xss_clean'
- );
- $val->set_rules(
- 'password',
- 'Password',
- 'trim|required|xss_clean'
- );
- $val->set_rules(
- 'remember',
- 'Remember me',
- 'integer'
- );
- // Set captcha rules if login attempts exceed max attempts in config
- if ($this->dx_auth->is_max_login_attempts_exceeded()) {
- $val->set_rules(
- 'captcha',
- 'Confirmation Code',
- 'trim|required|xss_clean|callback_captcha_check'
- );
- }
- if ($val->run() AND
- $this->dx_auth->login(
- $val->set_value('username'),
- $val->set_value('password'),
- $val->set_value('remember') ) ) {
- // Valid user so return true
- redirect('summer/login', 'location');
- } else {
- // Check if the user is failed logged in
- // because user is banned user or not
- if ($this->dx_auth->is_banned()) {
- // Redirect to banned uri
- $this->dx_auth->deny_access('banned');
- } else {
- // Default is we don't show captcha until
- // max login attempts exceeded
- $data['show_captcha'] = FALSE;
- // Show captcha if login attempts exceed max attempts in config
- if ($this->dx_auth->is_max_login_attempts_exceeded()) {
- // Create catpcha
- $this->dx_auth->captcha();
- // Set view data to show captcha on view file
- $data['show_captcha'] = TRUE;
- }
- // Load login page view
- $this->load->view($this->dx_auth->login_view, $data);
- }
- }
- } else {
- redirect('summer', 'location');
- }
- }
- /* */
- function class_info() {
- $data['page_title'] = 'Meridian School - Summer Class Info';
- $data['use_tablesorter'] = TRUE;
- $login_results = $this->dx_auth->is_logged_in();
- $data['login_results'] = $login_results;
- $this->load->view('common/header', $data);
- $this->load->model('Classes');
- $data['class'] = $this->Classes->get_classes();
- $this->load->view('summer/class_info', $data);
- $this->load->view('common/footer', $data);
- }
- /*
- *
- * left for reference
- *
- function users() {
- if ( ! $this->dx_auth->is_logged_in()) {
- redirect('summer/login', 'location');
- } else {
- $this->load->model('Usr_content');
- $data['page_title'] = 'TeachLogic, Inc. - Users';
- $data['login_results'] = TRUE;
- $data['anicol_page'] = 'anicol_bpanel_users';
- $data['use_anicol'] = TRUE;
- $data['use_tablesorter'] = TRUE;
- $this->load->view('bpanel/header', $data);
- $data['tl_comps'] = $this->Usr_content->get_comps(1);
- $data['rep_comps'] = $this->Usr_content->get_comps(2);
- $data['deal_comps'] = $this->Usr_content->get_comps(3);
- $data['ven_comps'] = $this->Usr_content->get_comps(4);
- $data['ug_comps'] = $this->Usr_content->get_comps(5);
- $this->load->view('bpanel/comps', $data);
- $this->load->view('bpanel/footer', $data);
- }
- }
- */
- /* */
- function logout() {
- $this->dx_auth->logout();
- $this->load->model('Pg_content');
- $data['page_title'] = 'Meridian School - Summer Logout';
- $data['login_results'] = FALSE;
- $this->load->view('common/header', $data);
- $data['content'] = '<h2><br />You have been logged out.<br /><br /></h2>';
- $this->load->view('summer/content', $data);
- $this->load->view('common/footer', $data);
- }
- /*
- * Callback functions
- */
- function username_check($username) {
- $result = $this->dx_auth->is_username_available($username);
- if ( ! $result) {
- $this->form_validation->set_message(
- 'username_check',
- 'Username already exist. Please choose another username.'
- );
- }
- return $result;
- }
- /* */
- function email_check($email) {
- $result = $this->dx_auth->is_email_available($email);
- if ( ! $result) {
- $this->form_validation->set_message(
- 'email_check',
- 'Email is already used by another user. Please choose another email address.'
- );
- }
- return $result;
- }
- /* */
- function captcha_check($code) {
- $result = TRUE;
- if ($this->dx_auth->is_captcha_expired()) {
- // Will replace this error msg with $lang
- $this->form_validation->set_message(
- 'captcha_check',
- 'Your confirmation code has expired. Please try again.'
- );
- $result = FALSE;
- } elseif ( ! $this->dx_auth->is_captcha_match($code)) {
- $this->form_validation->set_message(
- 'captcha_check',
- 'Your confirmation code does not match the one in the image. Try again.'
- );
- $result = FALSE;
- }
- return $result;
- }
- /*
- * Login Form functions
- */
- function register() {
- $data['page_title'] = 'Meridian School - Summer Register';
- $data['login_results'] = $this->dx_auth->is_logged_in();
- $this->load->view('common/header', $data);
- $this->load->model('Person');
- $this->load->model('Membership');
- $this->load->model('States');
- if ( ! $this->dx_auth->is_logged_in() AND
- $this->dx_auth->allow_registration) {
- $val = $this->form_validation;
- $val->set_error_delimiters('<div class="formerrors">', '</div>');
- /***
- *** more validation fields needed
- ***/
- $val->set_rules('first_name','First Name', 'alpha_dash|trim|xss_clean');
- $val->set_rules('last_name', 'Last Name', 'alpha_dash|trim|xss_clean');
- $val->set_rules('address1', 'Address', 'alpha_dash|trim|xss_clean');
- $val->set_rules('address2', 'Addr', 'alpha_dash|trim|xss_clean');
- $val->set_rules('city', 'City', 'alpha_dash|trim|xss_clean');
- $val->set_rules('state', 'State', 'alpha_dash|trim|xss_clean');
- $val->set_rules('zip', 'Zip', 'alpha_dash|trim|xss_clean');
- $val->set_rules('work_phone','Work Phone', 'alpha_dash|trim|xss_clean');
- $val->set_rules('other_phone','Other Phone','alpha_dash|trim|xss_clean');
- $val->set_rules('cell', 'Cell Phone', 'alpha_dash|trim|xss_clean');
- $val->set_rules('fax', 'FAX', 'alpha_dash|trim|xss_clean');
- $val->set_rules('email', 'Email', 'valid_email|trim|xss_clean');
- /*
- * Set form validation rules for DX
- */
- $val->set_rules('username', 'Username', 'trim|required|xss_clean|min_length['.$this->min_username.']|max_length['.$this->max_username.']|callback_username_check|alpha_dash' );
- $val->set_rules('password', 'Password', 'trim|required|xss_clean|min_length['.$this->min_password.']|max_length['.$this->max_password.']|matches[confirm_password]'
- );
- $val->set_rules('confirm_password', 'Confirm Password', 'trim|required|xss_clean');
- $val->set_rules('email', 'Email','trim|required|xss_clean|valid_email|callback_email_check');
- if ($this->dx_auth->captcha_registration) {
- $val->set_rules('captcha','Confirmation Code', 'trim|xss_clean|required|callback_captcha_check' );
- }
- /*
- * now check to see if the form in valid
- */
- if ($val->run() AND
- $this->dx_auth->register($val->set_value('username'), $val->set_value('password'), $val->set_value('email'))) {
- /*
- * valid
- */
- $this->Memberships->insert_member();
- $this->Persons->insert_person();
- /*
- * Set success message accordingly
- */
- if ($this->dx_auth->email_activation) {
- $data['auth_message'] = 'You have successfully registered.<br />Please check your email address to activate your account.';
- } else {
- $data['auth_message'] = 'You have successfully registered. '.anchor(site_url($this->dx_auth->login_uri), 'Login');
- }
- /*
- * Load registration success page
- */
- $this->load->view($this->dx_auth->register_success_view, $data);
- } else {
- /*
- * invalid or they oops'd or first time
- */
- $data['states'] = $this->States->get_state_info();
- /***
- *** check the field here
- ***/
- $data['user'] = (object) array(
- 'newpass' => '',
- 'B_Person_Type' => '1', // should be a look up ( ie from a CI helper, but that later
- 'first_name' => '',
- 'last_name' => '',
- 'address1' => '',
- 'address2' => '',
- 'city' => '',
- 'state' => '',
- 'zip' => '',
- 'work_phone' => '',
- 'other_phone' => '',
- 'cell' => '',
- 'fax' => '',
- 'contact_pref' => '',
- 'email' => '',
- );
- /*
- * Is registration using captcha
- */
- if ($this->dx_auth->captcha_registration) {
- $this->dx_auth->captcha();
- }
- /*
- * Load registration page
- */
- $this->load->view($this->dx_auth->register_view);
- }
- }elseif ( ! $this->dx_auth->allow_registration) {
- $data['auth_message'] = 'Registration has been disabled.';
- $this->load->view($this->dx_auth->register_disabled_view, $data);
- } else {
- $data['auth_message'] = 'You have to logout first, before registering.';
- $this->load->view($this->dx_auth->logged_in_view, $data);
- }
- $this->load->view('common/footer', $data);
- }
- /* */
- function forgot_password() {
- $data['page_title'] = 'Meridian School - Summer Forgot Password';
- $data['login_results'] = $this->dx_auth->is_logged_in();
- $this->load->view('common/header', $data);
- $val = $this->form_validation;
- $val->set_error_delimiters('<div class="formerrors">', '</div>');
- // Set form validation rules
- $val->set_rules(
- 'login',
- 'Username or Email address',
- 'trim|required|xss_clean'
- );
- // Validate rules and call forgot password function
- if ($val->run() AND
- $this->dx_auth->forgot_password($val->set_value('login'))) {
- $data['auth_message'] = 'An email has been sent to your email with instructions with how to activate your new password.';
- $this->load->view($this->dx_auth->forgot_password_success_view, $data);
- } else {
- $this->load->view($this->dx_auth->forgot_password_view);
- }
- $this->load->view('common/footer', $data);
- }
- /*
- * Email Referred
- */
- function activate() {
- // Get username and key
- $username = $this->uri->segment(3);
- $key = $this->uri->segment(4);
- // Activate user
- if ($this->dx_auth->activate($username, $key)) {
- $data['auth_message'] = 'Your account have been successfully activated. '.anchor(site_url($this->dx_auth->login_uri), 'Login');
- $this->load->view($this->dx_auth->activate_success_view, $data);
- } else {
- $data['auth_message'] = 'The activation code you entered was incorrect.<br />Please check your email again.';
- $this->load->view($this->dx_auth->activate_failed_view, $data);
- }
- }
- /* */
- function reset_password() {
- // Get username and key
- $username = $this->uri->segment(3);
- $key = $this->uri->segment(4);
- // Reset password
- if ($this->dx_auth->reset_password($username, $key)) {
- $data['auth_message'] = 'You have successfully reset you password, '.anchor(site_url($this->dx_auth->login_uri), 'Login');
- $this->load->view($this->dx_auth->reset_password_success_view, $data);
- } else {
- $data['auth_message'] = 'Reset failed. Your username and key are incorrect.<br />Please check your email again and follow the instructions.';
- $this->load->view($this->dx_auth->reset_password_failed_view, $data);
- }
- }
- /* */
- function _change_password() {
- // Check if user logged in or not
- if ($this->dx_auth->is_logged_in()) {
- $val = $this->form_validation;
- $val->set_error_delimiters('<div class="formerrors">', '</div>');
- // Set form validation
- $val->set_rules(
- 'old_password',
- 'Old Password',
- 'trim|required|xss_clean|min_length['.$this->min_password.']|max_length['.$this->max_password.']'
- );
- $val->set_rules(
- 'new_password',
- 'New Password',
- 'trim|required|xss_clean|min_length['.$this->min_password.']|max_length['.$this->max_password.']|matches[confirm_new_password]'
- );
- $val->set_rules(
- 'confirm_new_password',
- 'Confirm new Password',
- 'trim|required|xss_clean'
- );
- // Validate rules and change password
- if ($val->run() AND
- $this->dx_auth->change_password($val->set_value('old_password'), $val->set_value('new_password'))) {
- $data['auth_message'] = 'Your password has successfully been changed.';
- $this->load->view($this->dx_auth->change_password_success_view, $data);
- } else {
- $this->load->view($this->dx_auth->change_password_view);
- }
- } else {
- // Redirect to login page
- $this->dx_auth->deny_access('login');
- }
- }
- /* */
- function _cancel_account() {
- // Check if user logged in or not
- if ($this->dx_auth->is_logged_in()) {
- $val = $this->form_validation;
- $val->set_error_delimiters('<div class="formerrors">', '</div>');
- // Set form validation rules
- $val->set_rules('password', 'Password', "trim|required|xss_clean");
- // Validate rules and change password
- if ($val->run() AND
- $this->dx_auth->cancel_account($val->set_value('password'))) {
- // Redirect to homepage
- redirect('', 'location');
- } else {
- $this->load->view($this->dx_auth->cancel_account_view);
- }
- } else {
- // Redirect to login page
- $this->dx_auth->deny_access('login');
- }
- }
- /*
- * Special
- */
- function _chk_pw($username='tweak', $new_password='gamer') {
- //Load user lib
- $this->load->model('dx_auth/users', 'users');
- //Try to get the user -if found
- if (($row = $this->users->get_user_by_username($username)) &&
- $row->num_rows()) {
- $encode_pw = $this->dx_auth->_encode($new_password);
- $crypt_pw = crypt($encode_pw);
- print 'You gave the username: <b>'. $username. '</b><br />';
- print 'You gave the password: <b>'. $new_password. '</b><br />';
- print 'Password hash for database row: <b>'. $crypt_pw. '</b><br />';
- } else {
- print 'Username not found';
- }
- }
- /* */
- function recaptcha_check() {
- $result = $this->dx_auth->is_recaptcha_match();
- if ( ! $result) {
- $this->form_validation->set_message(
- 'recaptcha_check',
- 'Your confirmation code does not match the one in the image. Try again.'
- );
- }
- return $result;
- }
- /* */
- function register_recaptcha() {
- if ( ! $this->dx_auth->is_logged_in() AND
- $this->dx_auth->allow_registration) {
- $val = $this->form_validation;
- $val->set_error_delimiters('<div class="formerrors">', '</div>');
- // Set form validation rules
- $val->set_rules(
- 'username',
- 'Username',
- 'trim|required|xss_clean|min_length['.$this->min_username.']|max_length['.$this->max_username.']|callback_username_check|alpha_dash'
- );
- $val->set_rules(
- 'password',
- 'Password',
- 'trim|required|xss_clean|min_length['.$this->min_password.']|max_length['.$this->max_password.']|matches[confirm_password]'
- );
- $val->set_rules(
- 'confirm_password',
- 'Confirm Password',
- 'trim|required|xss_clean'
- );
- $val->set_rules(
- 'email',
- 'Email',
- 'trim|required|xss_clean|valid_email|callback_email_check'
- );
- // Is registration using captcha
- if ($this->dx_auth->captcha_registration) {
- // Set recaptcha rules.
- // IMPORTANT: Do not change 'recaptcha_response_field'
- // because it's used by reCAPTCHA API,
- // This is because the limitation of reCAPTCHA, not DX Auth library
- $val->set_rules(
- 'recaptcha_response_field',
- 'Confirmation Code',
- 'trim|xss_clean|required|callback_recaptcha_check'
- );
- }
- // Run form validation and register user if it's pass the validation
- if ($val->run() AND
- $this->dx_auth->register($val->set_value('username'), $val->set_value('password'), $val->set_value('email'))) {
- // Set success message accordingly
- if ($this->dx_auth->email_activation) {
- $data['auth_message'] = 'You have successfully registered. Check your email address to activate your account.';
- } else {
- $data['auth_message'] = 'You have successfully registered. '.anchor(site_url($this->dx_auth->login_uri), 'Login');
- }
- // Load registration success page
- $this->load->view($this->dx_auth->register_success_view, $data);
- } else {
- // Load registration page
- $this->load->view('auth/register_recaptcha_form');
- }
- } elseif ( ! $this->dx_auth->allow_registration) {
- $data['auth_message'] = 'Registration has been disabled.';
- $this->load->view($this->dx_auth->register_disabled_view, $data);
- } else {
- $data['auth_message'] = 'You have to logout first, before registering.';
- $this->load->view($this->dx_auth->logged_in_view, $data);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement