Advertisement
Guest User

Untitled

a guest
Aug 12th, 2011
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.61 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class User extends CI_Controller {
  4.  
  5.     /**
  6.      * Index Page for this controller.
  7.      *
  8.      * Maps to the following URL
  9.      *      http://example.com/index.php/user
  10.      *  - or -  
  11.      *      http://example.com/index.php/user/index
  12.      *  - or -
  13.      * Since this controller is set as the default controller in
  14.      * config/routes.php, it's displayed at http://example.com/
  15.      *
  16.      * So any other public methods not prefixed with an underscore will
  17.      * map to /index.php/welcome/<method_name>
  18.      * @see http://codeigniter.com/user_guide/general/urls.html
  19.      */
  20.     function User()
  21.     {
  22.         parent :: __construct();
  23.         $this->view_data['base_url'] = base_url();
  24.        
  25.         $this->load->model('User_model');
  26.     }
  27.    
  28.     function index()
  29.     {
  30.         $this->register();
  31.     }
  32.    
  33.     function register()
  34.     {
  35.        
  36.         $this->form_validation->set_rules('username', 'Username', 'trim|required|alpha_numeric|min_length[6]|xss_clean|strtolower|callback_usernameNotExists');
  37.         $this->form_validation->set_rules('password', 'Password', 'trim|required|alpha_numeric|min_length[6]|xss_clean');
  38.         $this->form_validation->set_rules('passwordConfirm', 'Confirm Password', 'trim|required|alpha_numeric|min_length[6]|xss_clean|matches[password]');
  39.         $this->form_validation->set_rules('email', 'Email', 'trim|required|min_length[6]|xss_clean|valid_email|callback_emailNotExists');
  40.         $this->form_validation->set_rules('firstName', 'First Name', 'trim|required|alpha_numeric|xss_clean');
  41.         $this->form_validation->set_rules('lastName', 'Last Name', 'trim|required|alpha_numeric|xss_clean');
  42.        
  43.         if ($this->form_validation->run() == FALSE)
  44.         {
  45.             $this->load->view('view_register', $this->view_data);
  46.         }
  47.         else
  48.         {
  49.             $username = $this->input->post('username');
  50.             $password = $this->input->post('password');
  51.             $email = $this->input->post('email');
  52.             $firstName = $this->input->post('firstName');
  53.             $lastName = $this->input->post('lastName');
  54.            
  55.             $registrationKey =  substr(md5(mt_rand()), 0, 5);
  56.            
  57.             $this->User_model->registerUser($username, $password, $email, $firstName, $lastName, $registrationKey);
  58.            
  59.             $this->load->library('email');
  60.             $this->email->from('kowmanagement@kansasoutlawwrestling.com', 'KOW Management');
  61.             $this->email->to($email);
  62.             $this->email->subject('KOW Manager Account Registration');
  63.             $this->email->message('Hello '.$firstName.' '.$lastName.' Welcome to our website!<br /><br />You, or someone using your email address, has completed registration at '.myDomainName().'. You can complete registration by clicking the following link:<br /><br />' . anchor('http://www.'.myDomainName().'/manager/verify.php?userID='.$userID.'&verifyHash='.$verifyHash.'", http://www.'.myDomainName().'/manager/verify.php?userID='.$userID.'&verifyHash='.$verifyHash.''));
  64.             $this->email->send();
  65.         }
  66.        
  67.     }
  68.    
  69.     function registerConfirm()
  70.     {
  71.         $registrationKey = $this->uri->segment(3);
  72.        
  73.         if ($registrationKey == '')
  74.         {
  75.             echo 'No registration key found in URL';
  76.             exist();
  77.         }
  78.        
  79.         $registrationConfirmed = $this->Register_model->confirmRegistration($registrationKey);
  80.        
  81.         if ($registrationConfirmed)
  82.         {
  83.             echo 'You have successfully registered!';
  84.         }
  85.         else
  86.         {
  87.             echo 'You have failed to register!';
  88.         }
  89.     }
  90.    
  91.     function usernameNotExists($username)
  92.     {
  93.         $this->form_validation->set_message('usernameNotExists', ' That %s already exists inside the database!');
  94.        
  95.         if($this->User_model->checkExistsUsername($username))
  96.         {
  97.             return false;
  98.         }
  99.         else
  100.         {
  101.             return true;
  102.         }
  103.     }
  104.    
  105.     function emailNotExists($email)
  106.     {
  107.         $this->form_validation->set_message('emailNotExists', ' That %s already exists inside the database!');
  108.        
  109.         if($this->User_model->checkExistsEmail($email))
  110.         {
  111.             return false;
  112.         }
  113.         else
  114.         {
  115.             return true;
  116.         }
  117.     }
  118.    
  119.     function myDomainName()
  120.     {
  121.         $my_domain = $_SERVER['HTTP_HOST'];
  122.         $my_domain = str_replace('www.', '', $my_domain);
  123.         return $my_domain;
  124.     }
  125. }
  126.  
  127. /* End of file welcome.php */
  128. /* Location: ./application/controllers/welcome.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement