Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function register()
- {
- $fname = htmlentities($this->input->post('fname'));
- $lname = htmlentities($this->input->post('lname'));
- $email = htmlentities($this->input->post('email'));
- $password = $this->input->post('password');
- $type = (int) $this->input->post('type');
- $role = $type ? 10 : 20;
- $now = date('Y-m-d h:i:s');
- $numbers = range(1,999);
- $username = $fname.$lname;
- $email_status = $this->business_model->select_num_rows('user',
- ['email' => $email]);
- if($email_status > 0 ){
- # if this email already exist
- echo json_encode(array('condition' => "error", 'data' => 'This email already associated with another account..')); exit;
- }
- $users = $this->business_model->search_all_data('user ',['username' =>
- $username]);
- foreach ($users as $user){
- $n = (int)substr($user['username'],strlen($username));
- if($n) unset($numbers[array_search($n,$numbers)]);
- }
- $suffix = array_shift($numbers);
- $username .= $suffix;
- if(!empty($email) and (!empty($password))){
- $password_hash = password_hash($password, PASSWORD_DEFAULT);
- $user_data = array('username' =>
- $username,'password_hash' =>$password_hash, 'email' =>$email,
- 'created' =>$now,'status' =>0 ,'role' =>$role);
- $resp_id = $this->business_model->insert_data("user",$user_data,'yes');
- if($resp_id){
- $person_data = array('user_id' =>$resp_id,'first_name' => $fname ,'last_name' =>$lname);
- $resp_id = $this->business_model->insert_data("person",$person_data);
- echo json_encode(array('condition' => "success", 'data' => 'Account has been created please verify your email.')); exit;
- }else{
- echo json_encode(array('condition' => "error", 'data' => 'Something went wrong.')); exit;
- }
- }else{
- # if user Directly try to access the registration controller
- redirect('Welcome');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement