Advertisement
Guest User

Signup

a guest
Jun 20th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. public function register()
  2.     {
  3.         $fname    = htmlentities($this->input->post('fname'));
  4.         $lname    = htmlentities($this->input->post('lname'));
  5.         $email    = htmlentities($this->input->post('email'));
  6.         $password = $this->input->post('password');
  7.         $type     = (int) $this->input->post('type');
  8.         $role = $type ? 10 : 20;
  9.         $now = date('Y-m-d h:i:s');  
  10.         $numbers = range(1,999);
  11.         $username = $fname.$lname;
  12.         $email_status = $this->business_model->select_num_rows('user',
  13.                         ['email' => $email]);
  14.         if($email_status > 0 ){
  15.             # if this email already exist
  16.              echo json_encode(array('condition' => "error", 'data' => 'This email already associated with another account..')); exit;
  17.         }
  18.         $users = $this->business_model->search_all_data('user ',['username' =>
  19.         $username]);
  20.         foreach ($users as $user){
  21.         $n = (int)substr($user['username'],strlen($username)); 
  22.          if($n) unset($numbers[array_search($n,$numbers)]);
  23.         }
  24.         $suffix = array_shift($numbers);
  25.         $username .= $suffix;
  26.          if(!empty($email) and (!empty($password))){
  27.             $password_hash =  password_hash($password, PASSWORD_DEFAULT);
  28.             $user_data = array('username' =>
  29.             $username,'password_hash' =>$password_hash, 'email' =>$email,
  30.             'created' =>$now,'status' =>0 ,'role' =>$role);
  31.             $resp_id = $this->business_model->insert_data("user",$user_data,'yes');
  32.             if($resp_id){
  33.             $person_data = array('user_id' =>$resp_id,'first_name' => $fname ,'last_name' =>$lname);   
  34.             $resp_id = $this->business_model->insert_data("person",$person_data);
  35.             echo json_encode(array('condition' => "success", 'data' => 'Account has been created please verify your email.')); exit;    
  36.             }else{
  37.             echo json_encode(array('condition' => "error", 'data' => 'Something went wrong.')); exit;  
  38.             }
  39.         }else{
  40.             # if user Directly try to access the registration controller
  41.             redirect('Welcome');   
  42.         }
  43.        
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement