Exemplo n.º 1
0
 public function addUserPro()
 {
     $this->load->model("dao/DaoUser");
     $this->load->model("dto/DtoUser");
     $user = new DtoUser();
     $userDao = new DaoUser();
     $this->load->library('form_validation');
     $this->load->helper('form');
     $this->form_validation->set_rules('username', 'Username', 'required|trim');
     $this->form_validation->set_rules('password', 'Password', 'required|trim');
     $this->form_validation->set_rules('confirm_password', 'Confirm Password', 'required|trim');
     $this->form_validation->set_rules('usertype', 'User Type', 'required|trim');
     $this->form_validation->set_rules('status', 'Status', 'required|trim');
     if ($this->form_validation->run() == FALSE) {
         echo json_encode(array("ERROR" => true, "ERR_MSG" => validation_errors()));
     } else {
         if ($this->input->post('password') != $this->input->post('confirm_password')) {
             echo json_encode(array("ERROR" => true, "ERR_MSG" => "Your password are mismatch. Please enter again."));
         } else {
             $user->setUsername($this->input->post('username'));
             $user->setPassword($this->input->post('password'));
             $user->setUsertype($this->input->post('usertype'));
             $user->setActive($this->input->post("status"));
             if ($userDao->check_duplicate_user_by_username($user->getUsername()) > 0) {
                 $data["ERROR"] = true;
                 $data["ERR_MSG"] = "User already exist.";
             } else {
                 $userDao->create_new_user($user);
                 $data["ERROR"] = false;
                 $data["ERR_MSG"] = "User has been inserted sucessfully.";
             }
             echo json_encode($data);
         }
     }
 }