Advertisement
Guest User

Untitled

a guest
Aug 1st, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.92 KB | None | 0 0
  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('confirm_password', 'Confirm Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric|matches[password]');
  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_address', 'Email Address', 'trim|required|xss_clean|valid_email|callback__email_exists');
  83.         return $this->form_validation->run();
  84.     }
  85.    
  86.     public function _username_exists($str)
  87.     {
  88.         if ($this->users_model->is_username_available($this->input->post('username')))
  89.         {
  90.             return FALSE;
  91.         }
  92.         else
  93.         {
  94.             return TRUE;
  95.         }
  96.     }
  97.    
  98.     public function _email_address_exists($str)
  99.     {
  100.         if ($this->users_model->is_email_address_available($this->input->post('email_address')))
  101.         {
  102.             return FALSE;
  103.         }
  104.         else
  105.         {
  106.             return TRUE;
  107.         }
  108.     }
  109.    
  110.     public function submit()
  111.     {
  112.         if ( $this->form_is_valid() )
  113.         {
  114.             $post_username = $this->input->post( 'username' );
  115.             $post_password = $this->input->post( 'password' );
  116.             $post_first_name =  $this->input->post( 'first_name' );
  117.             $post_last_name =  $this->input->post( 'last_name' );
  118.             $post_email_address =  $this->input->post( 'email_address' );
  119.            
  120.             $user_data = $this->mylib->create_user( $post_username, $post_password, $post_first_name, $post_last_name, $post_email_address );
  121.            
  122.             if ( $user_data )
  123.             {
  124.                 $this->mylib->send_email(
  125.                     'registration_email',
  126.                     'KOW Manager Registration Details',
  127.                     $user_data
  128.                 );
  129.                
  130.                 $output_array = array(
  131.                     'error' => FALSE,
  132.                     'message' => 'Successful registration! We will be emailing you a confirmation email shortly!'
  133.                 );
  134.             }
  135.             else
  136.             {
  137.                 $output_array = array(
  138.                     'error' => TRUE,
  139.                     'message' => 'There was a problem creating the user! Please try again!!'
  140.                 );
  141.             }
  142.         }
  143.         else
  144.         {
  145.             $output_array = array(
  146.                 'error' => TRUE,
  147.                 'message' => 'The form was not validated!'
  148.             );
  149.         }
  150.        
  151.         echo json_encode($output_array);    
  152.     }
  153.    
  154. }
  155.  
  156. /* End of file register.php */
  157. /* Location: ./application/controllers/register.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement