Guest User

Untitled

a guest
Jul 31st, 2012
95
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Register extends CI_Controller {
  4.  
  5.     function __construct()
  6.     {
  7.         parent::__construct();
  8.         $this->load->model('users/users_model');
  9.     }
  10.    
  11.     public function index()
  12.     {
  13.         $msgBoxMsgs = array();
  14.         $cssPageAddons = '';
  15.         $jsPageAddons =  '<script src="'.base_url().'assets/js/plugins.js"></script><script src="'.base_url().'assets/js/jquery.validate.js"></script><script src="'.base_url().'assets/js/script.js"></script><script src="'.base_url().'assets/js/validate/register.js"></script>';
  16.         $metaAddons = '';
  17.         $siteTitle = 'KOW Manager Register';
  18.        
  19.         $bodyContent = '/usermanagement/forms/register_form';//which view file
  20.         $bodyType = 'full';//type of template      
  21.            
  22.         if(count($msgBoxMsgs) !== 0)
  23.         {
  24.             $msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs));
  25.         }
  26.         else
  27.         {
  28.             $msgBoxes = array('display' => 'none');
  29.         }
  30.        
  31.         if(isset($siteTitle) && (empty($siteTitle)) )
  32.         {
  33.             $siteTitle = $this->metatags->SiteTitle();
  34.         }
  35.        
  36.         $this->data = compact(
  37.                 'msgBoxes',
  38.                 'cssPageAddons',
  39.                 'jsPageAddons',
  40.                 'siteTitle',
  41.                 'bodyType',
  42.                 'bodyContent'
  43.             );
  44.         $this->load->view('usermanagement/index', $this->data);
  45.     }
  46.    
  47.     public function is_username_available()
  48.     {
  49.         if ( $this->users_model->is_username_available($this->input->post('username')) )
  50.         {
  51.             // available
  52.             echo('true');
  53.         }
  54.         else
  55.         {
  56.             // not available
  57.             echo('false');
  58.         }        
  59.     }
  60.    
  61.     public function is_email_available()
  62.     {
  63.         if ( $this->users_model->is_email_available($this->input->post('email_address')))
  64.         {
  65.             // available
  66.             echo('true');
  67.         }
  68.         else
  69.         {
  70.             // not available
  71.             echo('false');
  72.         }        
  73.     }
  74.    
  75.     private function form_is_valid()
  76.     {
  77.         $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric|strtolower|callback_username_exists');
  78.         $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric');
  79.         $this->form_validation->set_rules('password_confirm', 'Confirm Password', 'trim|required|xss_clean|matches[password]|min_length[6]|max_length[12]|alpha_numeric');
  80.         $this->form_validation->set_rules('first_name', 'First Name', 'trim|required|xss_clean|alpha');  
  81.         $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required|xss_clean|alpha');
  82.         $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email|callback_email_address_exists');
  83.  
  84.         return $this->form_validation->run();
  85.     }
  86.    
  87.     public function username_exists($str)
  88.     {
  89.         if ($this->users_model->is_username_available($this->input->post('username')))
  90.         {
  91.             $this->form_validation->set_message('username', 'Testing');
  92.             return FALSE;
  93.         }
  94.         else
  95.         {
  96.             return TRUE;
  97.         }
  98.     }
  99.    
  100.     public function email_address_exists($str)
  101.     {
  102.         if ($this->users_model->is_email_address_available($this->input->post('email_address')))
  103.         {
  104.             $this->form_validation->set_message('email_address', 'Testing2');
  105.             return FALSE;
  106.         }
  107.         else
  108.         {
  109.             return TRUE;
  110.         }
  111.     }
  112.    
  113.     private function get_post( $post_var )
  114.     {
  115.         return $this->input->post( $post_var );
  116.     }
  117.    
  118.     private function create_user( $post_username, $post_password, $post_first_name, $post_last_name, $post_email_address )
  119.     {
  120.         $return = $this->mylib->create_user( $post_username, $post_password, $post_first_name, $post_last_name, $post_email_address );
  121.        
  122.         $user_data =
  123.        
  124.         if( $return )
  125.         {
  126.             $this->mylib->send_email(
  127.                 'activation',
  128.                 'KOW Manager Registration Details',
  129.                 $user_data
  130.             );
  131.         }
  132.        
  133.         return $return;
  134.     }
  135.    
  136.     public function submit()
  137.     {
  138.         if ( $this->form_is_valid() )
  139.         {
  140.             $post_username = $this->get_post( 'username' );
  141.             $post_password = $this->get_post( 'password' );
  142.             $post_first_name = $this->get_post( 'first_name' );
  143.             $post_last_name = $this->get_post( 'last_name' );
  144.             $post_email_address = $this->get_post( 'email_address' );
  145.            
  146.             if ( $this->create_user( $post_username, $post_password, $post_first_name, $post_last_name, $post_email_address ) )
  147.             {
  148.                 $output_array = array(
  149.                     'error' => FALSE,
  150.                     'message' => 'Successful registration! We will be emailing you a confirmation email shortly!'
  151.                 );
  152.             }
  153.             else
  154.             {
  155.                 $output_array = array(
  156.                     'error' => TRUE,
  157.                     'message' => 'There was a problem creating the user! Please try again!!'
  158.                 );
  159.             }
  160.         }
  161.         else
  162.         {
  163.             $output_array = array(
  164.                 'error' => TRUE,
  165.                 'message' => 'The form was not validated!'
  166.             );
  167.         }
  168.        
  169.         echo json_encode($output_array);    
  170.     }
  171.    
  172. }
  173.  
  174. /* End of file register.php */
  175. /* Location: ./application/controllers/register.php */
RAW Paste Data