Пример #1
0
 public function register()
 {
     $this->output->set_content_type('application/json');
     $config = [['field' => 'login', 'label' => 'Login Name', 'rules' => 'trim|required|min_length[2]|max_length[50]|is_unique[user.login]'], ['field' => 'email', 'label' => 'Email Address', 'rules' => 'trim|required|valid_email|is_unique[user.email]'], ['field' => 'password', 'label' => 'Password', 'rules' => 'trim|required|min_length[5]|max_length[50]'], ['field' => 'confirm_password', 'label' => 'Password Confirmation', 'rules' => 'required|matches[password]']];
     $this->form_validation->set_message('is_unique', 'The {field} field already exist please choose another one');
     $this->form_validation->set_rules($config);
     if ($this->form_validation->run() == false) {
         $this->output->set_output(json_encode(['result' => 0, 'error' => $this->form_validation->error_array()]));
         return false;
     }
     $data = ['login' => $this->input->post('login'), 'email' => $this->input->post('email'), 'password' => Make::Hash($this->input->post('password')), 'date_added' => date('Y-m-d H:i:s')];
     $insert = $this->User_Model->insert($data);
     if ($insert) {
         $this->output->set_output(json_encode(['result' => 1]));
     } else {
         $this->output->set_output(json_encode(['result' => 0, 'error' => 'The user not created']));
     }
 }