Advertisement
Guest User

Untitled

a guest
May 6th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 21.68 KB | None | 0 0
  1. <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Summer extends Controller {
  4.  
  5.     // Used for registering and changing password form validation
  6.     var $min_username = 4;
  7.     var $max_username = 20;
  8.     var $min_password = 4;
  9.     var $max_password = 20;
  10.  
  11. /*
  12.  *
  13.  */
  14.     function Summer() {
  15.  
  16.         parent::Controller();
  17.  
  18.         $this->load->library('Form_validation');
  19.         $this->load->library('DX_Auth');
  20.         $this->load->library('table');
  21.  
  22.         $this->load->helper('url');
  23.         $this->load->helper('form');
  24.  
  25.         $this->load->helper('menu');
  26.     }
  27.  
  28. /*
  29.  * Main functions
  30.  */
  31.     function index() {
  32.  
  33.         $data['page_title'] = 'Meridian School - Summer';
  34.  
  35.         $login_results =  $this->dx_auth->is_logged_in();
  36.         $data['login_results'] = $login_results;
  37.         $this->load->view('common/header', $data);
  38.  
  39.         if ( $login_results ) {
  40.  
  41. //            $this->load->model('Membership');
  42. //            $this->load->model('Person');
  43.             $this->load->model('Classes');
  44.  
  45.             $data['summary'] = array (
  46.                 'Child' => $this->Person->get_child_summary($id),
  47.                 'Class' => $this->Class->get_class_summary($id),
  48.             );
  49.  
  50.             $this->load->view('front/summary', $data);
  51.         }
  52.  
  53.         $this->load->view('common/footer', $data);
  54.     }
  55.  
  56. /* */
  57.     function login() {
  58.  
  59.         $data['page_title'] = 'Meridian School - Summer Login';
  60.  
  61.         $login_results =  $this->dx_auth->is_logged_in();
  62.         $data['login_results'] = $login_results;
  63.         $this->load->view('common/header', $data);
  64.  
  65.         if ( ! $login_results) {
  66.  
  67.             $val = $this->form_validation;
  68.             $val->set_error_delimiters('<div class="formerrors">', '</div>');
  69.  
  70.             // Set form validation rules
  71.             $val->set_rules(
  72.                 'username',
  73.                 'Username',
  74.                 'trim|required|xss_clean'
  75.             );
  76.  
  77.             $val->set_rules(
  78.                 'password',
  79.                 'Password',
  80.                 'trim|required|xss_clean'
  81.             );
  82.  
  83.             $val->set_rules(
  84.                 'remember',
  85.                 'Remember me',
  86.                 'integer'
  87.             );
  88.  
  89.             // Set captcha rules if login attempts exceed max attempts in config
  90.             if ($this->dx_auth->is_max_login_attempts_exceeded()) {
  91.  
  92.                 $val->set_rules(
  93.                     'captcha',
  94.                     'Confirmation Code',
  95.                     'trim|required|xss_clean|callback_captcha_check'
  96.                 );
  97.             }
  98.  
  99.             if ($val->run() AND
  100.                 $this->dx_auth->login(
  101.                     $val->set_value('username'),
  102.                     $val->set_value('password'),
  103.                     $val->set_value('remember') ) ) {
  104.  
  105.                 // Valid user so return true
  106.                 redirect('summer/login', 'location');
  107.  
  108.             } else {
  109.  
  110.                 // Check if the user is failed logged in
  111.                 //    because user is banned user or not
  112.                 if ($this->dx_auth->is_banned()) {
  113.  
  114.                     // Redirect to banned uri
  115.                     $this->dx_auth->deny_access('banned');
  116.  
  117.                 } else {
  118.  
  119.                     // Default is we don't show captcha until
  120.                     //    max login attempts exceeded
  121.                     $data['show_captcha'] = FALSE;
  122.  
  123.                     // Show captcha if login attempts exceed max attempts in config
  124.                     if ($this->dx_auth->is_max_login_attempts_exceeded()) {
  125.  
  126.                         // Create catpcha
  127.                         $this->dx_auth->captcha();
  128.  
  129.                         // Set view data to show captcha on view file
  130.                         $data['show_captcha'] = TRUE;
  131.                     }
  132.  
  133.                     // Load login page view
  134.                     $this->load->view($this->dx_auth->login_view, $data);
  135.                 }
  136.             }
  137.  
  138.         } else {
  139.  
  140.             redirect('summer', 'location');
  141.         }
  142.     }
  143.  
  144. /* */
  145.     function class_info() {
  146.  
  147.         $data['page_title'] = 'Meridian School - Summer Class Info';
  148.  
  149.         $data['use_tablesorter'] = TRUE;
  150.         $login_results =  $this->dx_auth->is_logged_in();
  151.         $data['login_results'] = $login_results;
  152.         $this->load->view('common/header', $data);
  153.  
  154.  
  155.         $this->load->model('Classes');
  156.  
  157.         $data['class'] = $this->Classes->get_classes();
  158.         $this->load->view('summer/class_info', $data);
  159.  
  160.         $this->load->view('common/footer', $data);
  161.     }
  162.  
  163.  
  164.  
  165.  
  166.  
  167. /*
  168.  *
  169.  * left for reference
  170.  *
  171.     function users() {
  172.  
  173.         if ( ! $this->dx_auth->is_logged_in()) {
  174.  
  175.             redirect('summer/login', 'location');
  176.  
  177.         } else {
  178.  
  179.             $this->load->model('Usr_content');
  180.  
  181.             $data['page_title'] = 'TeachLogic, Inc. - Users';
  182.             $data['login_results'] = TRUE;
  183.  
  184.             $data['anicol_page'] = 'anicol_bpanel_users';
  185.             $data['use_anicol'] = TRUE;
  186.             $data['use_tablesorter'] = TRUE;
  187.  
  188.             $this->load->view('bpanel/header', $data);
  189.  
  190.             $data['tl_comps'] = $this->Usr_content->get_comps(1);
  191.             $data['rep_comps'] = $this->Usr_content->get_comps(2);
  192.             $data['deal_comps'] = $this->Usr_content->get_comps(3);
  193.             $data['ven_comps'] = $this->Usr_content->get_comps(4);
  194.             $data['ug_comps'] = $this->Usr_content->get_comps(5);
  195.  
  196.             $this->load->view('bpanel/comps', $data);
  197.  
  198.             $this->load->view('bpanel/footer', $data);
  199.         }
  200.     }
  201. */
  202.  
  203. /* */
  204.     function logout() {
  205.  
  206.         $this->dx_auth->logout();
  207.  
  208.         $this->load->model('Pg_content');
  209.  
  210.         $data['page_title'] = 'Meridian School - Summer Logout';
  211.  
  212.         $data['login_results'] = FALSE;
  213.         $this->load->view('common/header', $data);
  214.  
  215.         $data['content'] = '<h2><br />You have been logged out.<br /><br /></h2>';
  216.         $this->load->view('summer/content', $data);
  217.  
  218.         $this->load->view('common/footer', $data);
  219.     }
  220.  
  221.  
  222. /*
  223.  * Callback functions
  224.  */
  225.     function username_check($username) {
  226.  
  227.         $result = $this->dx_auth->is_username_available($username);
  228.  
  229.         if ( ! $result) {
  230.  
  231.             $this->form_validation->set_message(
  232.                 'username_check',
  233.                 'Username already exist. Please choose another username.'
  234.             );
  235.         }
  236.  
  237.         return $result;
  238.     }
  239.  
  240. /* */
  241.     function email_check($email) {
  242.  
  243.         $result = $this->dx_auth->is_email_available($email);
  244.  
  245.         if ( ! $result) {
  246.  
  247.             $this->form_validation->set_message(
  248.                 'email_check',
  249.                 'Email is already used by another user. Please choose another email address.'
  250.             );
  251.         }
  252.  
  253.         return $result;
  254.     }
  255.  
  256. /* */
  257.     function captcha_check($code) {
  258.  
  259.         $result = TRUE;
  260.  
  261.         if ($this->dx_auth->is_captcha_expired()) {
  262.  
  263.             // Will replace this error msg with $lang
  264.             $this->form_validation->set_message(
  265.                 'captcha_check',
  266.                 'Your confirmation code has expired. Please try again.'
  267.             );
  268.  
  269.             $result = FALSE;
  270.  
  271.         } elseif ( ! $this->dx_auth->is_captcha_match($code)) {
  272.  
  273.             $this->form_validation->set_message(
  274.                 'captcha_check',
  275.                 'Your confirmation code does not match the one in the image. Try again.'
  276.             );
  277.  
  278.             $result = FALSE;
  279.         }
  280.  
  281.         return $result;
  282.     }
  283.  
  284.  
  285. /*
  286.  * Login Form functions
  287.  */
  288. function register() {
  289.  
  290.         $data['page_title'] = 'Meridian School - Summer Register';
  291.  
  292.         $data['login_results'] = $this->dx_auth->is_logged_in();
  293.  
  294.         $this->load->view('common/header', $data);
  295.  
  296.         $this->load->model('Person');
  297.         $this->load->model('Membership');
  298.         $this->load->model('States');
  299.  
  300.         if ( ! $this->dx_auth->is_logged_in() AND
  301.                 $this->dx_auth->allow_registration) {
  302.    
  303.             $val = $this->form_validation;
  304.             $val->set_error_delimiters('<div class="formerrors">', '</div>');
  305.  
  306. /***
  307.  *** more validation fields needed
  308.  ***/
  309.             $val->set_rules('first_name','First Name',  'alpha_dash|trim|xss_clean');
  310.             $val->set_rules('last_name', 'Last Name',   'alpha_dash|trim|xss_clean');
  311.             $val->set_rules('address1',  'Address',     'alpha_dash|trim|xss_clean');
  312.             $val->set_rules('address2',  'Addr',        'alpha_dash|trim|xss_clean');
  313.             $val->set_rules('city',      'City',        'alpha_dash|trim|xss_clean');
  314.             $val->set_rules('state',     'State',       'alpha_dash|trim|xss_clean');
  315.             $val->set_rules('zip',       'Zip',         'alpha_dash|trim|xss_clean');
  316.             $val->set_rules('work_phone','Work Phone',  'alpha_dash|trim|xss_clean');
  317.             $val->set_rules('other_phone','Other Phone','alpha_dash|trim|xss_clean');
  318.             $val->set_rules('cell',      'Cell Phone',  'alpha_dash|trim|xss_clean');
  319.             $val->set_rules('fax',       'FAX',         'alpha_dash|trim|xss_clean');
  320.             $val->set_rules('email',     'Email',      'valid_email|trim|xss_clean');
  321.  
  322. /*
  323.  * Set form validation rules for DX
  324.  */
  325.             $val->set_rules('username',  'Username',      'trim|required|xss_clean|min_length['.$this->min_username.']|max_length['.$this->max_username.']|callback_username_check|alpha_dash' );
  326.  
  327.             $val->set_rules('password',  'Password',       'trim|required|xss_clean|min_length['.$this->min_password.']|max_length['.$this->max_password.']|matches[confirm_password]'
  328.             );
  329.  
  330.             $val->set_rules('confirm_password', 'Confirm Password', 'trim|required|xss_clean');
  331.  
  332.             $val->set_rules('email', 'Email','trim|required|xss_clean|valid_email|callback_email_check');
  333.  
  334.             if ($this->dx_auth->captcha_registration) {
  335.                 $val->set_rules('captcha','Confirmation Code', 'trim|xss_clean|required|callback_captcha_check' );
  336.             }
  337.  
  338. /*
  339.  * now check to see if the form in valid
  340.  */
  341.             if ($val->run() AND
  342.                $this->dx_auth->register($val->set_value('username'), $val->set_value('password'), $val->set_value('email'))) {
  343.  
  344. /*
  345.  * valid
  346.  */
  347.                 $this->Memberships->insert_member();
  348.                 $this->Persons->insert_person();
  349.  
  350. /*
  351.  * Set success message accordingly
  352.  */
  353.                 if ($this->dx_auth->email_activation) {
  354.  
  355.                     $data['auth_message'] = 'You have successfully registered.<br />Please check your email address to activate your account.';
  356.  
  357.                 } else {
  358.  
  359.                     $data['auth_message'] = 'You have successfully registered. '.anchor(site_url($this->dx_auth->login_uri), 'Login');
  360.                 }
  361. /*
  362.  * Load registration success page
  363.  */
  364.                 $this->load->view($this->dx_auth->register_success_view, $data);
  365.  
  366.              } else {
  367. /*
  368.  * invalid or they oops'd or first time
  369.  */
  370.                 $data['states'] = $this->States->get_state_info();
  371.  
  372. /***
  373.  *** check the field here
  374.  ***/
  375.                 $data['user'] = (object) array(
  376.                     'newpass'      => '',
  377.                     'B_Person_Type' => '1',   // should be a look up ( ie from a CI helper, but that later
  378.                     'first_name'   => '',
  379.                     'last_name'    => '',
  380.                     'address1'     => '',
  381.                     'address2'     => '',
  382.                     'city'         => '',
  383.                     'state'        => '',
  384.                     'zip'          => '',
  385.                     'work_phone'   => '',
  386.                     'other_phone'  => '',
  387.                     'cell'         => '',
  388.                     'fax'          => '',
  389.                     'contact_pref' => '',
  390.                     'email'        => '',
  391.                 );
  392. /*
  393.  * Is registration using captcha
  394.  */
  395.                 if ($this->dx_auth->captcha_registration) {
  396.  
  397.                     $this->dx_auth->captcha();
  398.                 }
  399. /*
  400.  * Load registration page
  401.  */
  402.                 $this->load->view($this->dx_auth->register_view);
  403.                 }
  404.             }elseif ( ! $this->dx_auth->allow_registration) {
  405.  
  406.             $data['auth_message'] = 'Registration has been disabled.';
  407.             $this->load->view($this->dx_auth->register_disabled_view, $data);
  408.  
  409.         } else {
  410.  
  411.             $data['auth_message'] = 'You have to logout first, before registering.';
  412.             $this->load->view($this->dx_auth->logged_in_view, $data);
  413.         }
  414.  
  415.         $this->load->view('common/footer', $data);
  416.     }
  417.  
  418. /* */
  419.     function forgot_password() {
  420.  
  421.         $data['page_title'] = 'Meridian School - Summer Forgot Password';
  422.  
  423.         $data['login_results'] = $this->dx_auth->is_logged_in();
  424.  
  425.         $this->load->view('common/header', $data);
  426.  
  427.         $val = $this->form_validation;
  428.         $val->set_error_delimiters('<div class="formerrors">', '</div>');
  429.  
  430.         // Set form validation rules
  431.         $val->set_rules(
  432.             'login',
  433.             'Username or Email address',
  434.             'trim|required|xss_clean'
  435.         );
  436.  
  437.         // Validate rules and call forgot password function
  438.         if ($val->run() AND
  439.             $this->dx_auth->forgot_password($val->set_value('login'))) {
  440.  
  441.             $data['auth_message'] = 'An email has been sent to your email with instructions with how to activate your new password.';
  442.             $this->load->view($this->dx_auth->forgot_password_success_view, $data);
  443.  
  444.         } else {
  445.  
  446.             $this->load->view($this->dx_auth->forgot_password_view);
  447.         }
  448.  
  449.         $this->load->view('common/footer', $data);
  450.     }
  451.  
  452.  
  453. /*
  454.  * Email Referred
  455.  */
  456.     function activate() {
  457.  
  458.         // Get username and key
  459.         $username = $this->uri->segment(3);
  460.         $key = $this->uri->segment(4);
  461.  
  462.         // Activate user
  463.         if ($this->dx_auth->activate($username, $key)) {
  464.  
  465.             $data['auth_message'] = 'Your account have been successfully activated. '.anchor(site_url($this->dx_auth->login_uri), 'Login');
  466.             $this->load->view($this->dx_auth->activate_success_view, $data);
  467.  
  468.         } else {
  469.  
  470.             $data['auth_message'] = 'The activation code you entered was incorrect.<br />Please check your email again.';
  471.             $this->load->view($this->dx_auth->activate_failed_view, $data);
  472.         }
  473.     }
  474.  
  475. /* */
  476.     function reset_password() {
  477.  
  478.         // Get username and key
  479.         $username = $this->uri->segment(3);
  480.         $key = $this->uri->segment(4);
  481.  
  482.         // Reset password
  483.         if ($this->dx_auth->reset_password($username, $key)) {
  484.  
  485.             $data['auth_message'] = 'You have successfully reset you password, '.anchor(site_url($this->dx_auth->login_uri), 'Login');
  486.             $this->load->view($this->dx_auth->reset_password_success_view, $data);
  487.  
  488.         } else {
  489.  
  490.             $data['auth_message'] = 'Reset failed. Your username and key are incorrect.<br />Please check your email again and follow the instructions.';
  491.             $this->load->view($this->dx_auth->reset_password_failed_view, $data);
  492.         }
  493.     }
  494.  
  495. /* */
  496.     function _change_password() {
  497.  
  498.         // Check if user logged in or not
  499.         if ($this->dx_auth->is_logged_in()) {
  500.  
  501.             $val = $this->form_validation;
  502.             $val->set_error_delimiters('<div class="formerrors">', '</div>');
  503.  
  504.             // Set form validation
  505.             $val->set_rules(
  506.                 'old_password',
  507.                 'Old Password',
  508.                 'trim|required|xss_clean|min_length['.$this->min_password.']|max_length['.$this->max_password.']'
  509.             );
  510.  
  511.             $val->set_rules(
  512.                 'new_password',
  513.                 'New Password',
  514.                 'trim|required|xss_clean|min_length['.$this->min_password.']|max_length['.$this->max_password.']|matches[confirm_new_password]'
  515.             );
  516.  
  517.             $val->set_rules(
  518.                 'confirm_new_password',
  519.                 'Confirm new Password',
  520.                 'trim|required|xss_clean'
  521.             );
  522.  
  523.             // Validate rules and change password
  524.             if ($val->run() AND
  525.                 $this->dx_auth->change_password($val->set_value('old_password'), $val->set_value('new_password'))) {
  526.  
  527.                 $data['auth_message'] = 'Your password has successfully been changed.';
  528.                 $this->load->view($this->dx_auth->change_password_success_view, $data);
  529.             } else {
  530.  
  531.                 $this->load->view($this->dx_auth->change_password_view);
  532.             }
  533.         } else {
  534.  
  535.             // Redirect to login page
  536.             $this->dx_auth->deny_access('login');
  537.         }
  538.     }
  539.  
  540. /* */
  541.     function _cancel_account() {
  542.  
  543.         // Check if user logged in or not
  544.         if ($this->dx_auth->is_logged_in()) {
  545.  
  546.             $val = $this->form_validation;
  547.             $val->set_error_delimiters('<div class="formerrors">', '</div>');
  548.  
  549.             // Set form validation rules
  550.             $val->set_rules('password', 'Password', "trim|required|xss_clean");
  551.  
  552.             // Validate rules and change password
  553.             if ($val->run() AND
  554.                 $this->dx_auth->cancel_account($val->set_value('password'))) {
  555.  
  556.                 // Redirect to homepage
  557.                 redirect('', 'location');
  558.  
  559.             } else {
  560.  
  561.                 $this->load->view($this->dx_auth->cancel_account_view);
  562.             }
  563.  
  564.         } else {
  565.  
  566.             // Redirect to login page
  567.             $this->dx_auth->deny_access('login');
  568.         }
  569.     }
  570.  
  571.  
  572. /*
  573.  * Special
  574.  */
  575.     function _chk_pw($username='tweak', $new_password='gamer') {
  576.  
  577.         //Load user lib
  578.         $this->load->model('dx_auth/users', 'users');
  579.  
  580.         //Try to get the user -if found
  581.         if (($row = $this->users->get_user_by_username($username)) &&
  582.             $row->num_rows()) {
  583.  
  584.             $encode_pw = $this->dx_auth->_encode($new_password);
  585.             $crypt_pw  = crypt($encode_pw);
  586.  
  587.             print 'You gave the username: <b>'. $username. '</b><br />';
  588.             print 'You gave the password: <b>'. $new_password. '</b><br />';
  589.             print 'Password hash for database row: <b>'. $crypt_pw. '</b><br />';
  590.  
  591.         } else {
  592.  
  593.             print 'Username not found';
  594.         }
  595.     }
  596.  
  597. /* */
  598.     function recaptcha_check() {
  599.  
  600.         $result = $this->dx_auth->is_recaptcha_match();
  601.  
  602.         if ( ! $result) {
  603.  
  604.             $this->form_validation->set_message(
  605.                 'recaptcha_check',
  606.                 'Your confirmation code does not match the one in the image. Try again.'
  607.             );
  608.         }
  609.  
  610.         return $result;
  611.     }
  612.  
  613. /* */
  614.     function register_recaptcha() {
  615.  
  616.         if ( ! $this->dx_auth->is_logged_in() AND
  617.             $this->dx_auth->allow_registration) {
  618.  
  619.             $val = $this->form_validation;
  620.             $val->set_error_delimiters('<div class="formerrors">', '</div>');
  621.  
  622.             // Set form validation rules
  623.             $val->set_rules(
  624.                 'username',
  625.                 'Username',
  626.                 'trim|required|xss_clean|min_length['.$this->min_username.']|max_length['.$this->max_username.']|callback_username_check|alpha_dash'
  627.             );
  628.  
  629.             $val->set_rules(
  630.                 'password',
  631.                 'Password',
  632.                 'trim|required|xss_clean|min_length['.$this->min_password.']|max_length['.$this->max_password.']|matches[confirm_password]'
  633.             );
  634.  
  635.             $val->set_rules(
  636.                 'confirm_password',
  637.                 'Confirm Password',
  638.                 'trim|required|xss_clean'
  639.             );
  640.  
  641.             $val->set_rules(
  642.                 'email',
  643.                 'Email',
  644.                 'trim|required|xss_clean|valid_email|callback_email_check'
  645.             );
  646.  
  647.             // Is registration using captcha
  648.             if ($this->dx_auth->captcha_registration) {
  649.  
  650.                 // Set recaptcha rules.
  651.                 // IMPORTANT: Do not change 'recaptcha_response_field'
  652.                 //  because it's used by reCAPTCHA API,
  653.                 // This is because the limitation of reCAPTCHA, not DX Auth library
  654.  
  655.                 $val->set_rules(
  656.                     'recaptcha_response_field',
  657.                     'Confirmation Code',
  658.                     'trim|xss_clean|required|callback_recaptcha_check'
  659.                 );
  660.             }
  661.  
  662.             // Run form validation and register user if it's pass the validation
  663.             if ($val->run() AND
  664.                 $this->dx_auth->register($val->set_value('username'), $val->set_value('password'), $val->set_value('email'))) {
  665.  
  666.                 // Set success message accordingly
  667.                 if ($this->dx_auth->email_activation) {
  668.  
  669.                     $data['auth_message'] = 'You have successfully registered. Check your email address to activate your account.';
  670.  
  671.                 } else {
  672.  
  673.                     $data['auth_message'] = 'You have successfully registered. '.anchor(site_url($this->dx_auth->login_uri), 'Login');
  674.                 }
  675.  
  676.                 // Load registration success page
  677.                 $this->load->view($this->dx_auth->register_success_view, $data);
  678.  
  679.             } else {
  680.  
  681.                 // Load registration page
  682.                 $this->load->view('auth/register_recaptcha_form');
  683.             }
  684.  
  685.         } elseif ( ! $this->dx_auth->allow_registration) {
  686.  
  687.             $data['auth_message'] = 'Registration has been disabled.';
  688.             $this->load->view($this->dx_auth->register_disabled_view, $data);
  689.  
  690.         } else {
  691.  
  692.             $data['auth_message'] = 'You have to logout first, before registering.';
  693.             $this->load->view($this->dx_auth->logged_in_view, $data);
  694.         }
  695.     }
  696. }
  697. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement