Exemple #1
0
 public function login()
 {
     $this->output->set_content_type('application_json');
     $config = [['field' => 'login', 'label' => 'Login name', 'rules' => 'trim|required|min_length[3]|max_length[50]|alpha_numeric'], ['field' => 'password', 'label' => 'Password', 'rules' => 'trim|required|min_length[5]']];
     $this->form_validation->set_rules($config);
     if ($this->form_validation->run() == false) {
         $this->output->set_output(json_encode(['result' => 0, 'errors' => $this->form_validation->error_array()]));
         return false;
     }
     $login = $this->input->post('login');
     $password = $this->input->post('password');
     if (count($this->User_Model->get(['login' => $login]))) {
         $user = $this->User_Model->get(['login' => $login])[0];
         if (isset($user->password) && Make::Verify($password, $user->password)) {
             $user_data = ['user_id' => $user->user_id, 'login' => $login];
             $this->session->set_userdata($user_data);
             $this->output->set_output(json_encode(['result' => 1]));
         }
     } else {
         $this->output->set_output(json_encode(['result' => 0]));
     }
 }