Ejemplo n.º 1
0
 public function loginAction($ajax = false)
 {
     $this->layout = 'ajax';
     $login = new \modules\users\models\Users('login');
     $resp = ['accessGranted' => false, 'errors' => '', 'redirect' => ''];
     // For ajax response
     if ($login->validate()) {
         $resp['accessGranted'] = true;
         $resp['redirect'] = Uri_helper::url();
         $this->input->cookie('failed-attempts', 0);
         $userInfo = $this->permissions->getUserInformation();
         $this->input->cookie('fullname', $userInfo->fullname);
         $this->input->cookie('email', $userInfo->email);
         $this->input->cookie('password', $userInfo->password);
         $this->input->cookie('image', $userInfo->image);
     } else {
         // Failed Attempts
         $fa = $this->input->cookie('failed-attempts') ? $this->input->cookie('failed-attempts') : 0;
         $fa++;
         $this->input->cookie('failed-attempts', $fa);
         // Error message
         $resp['errors'] = $this->Language->phrase('please_enter_a_valid_email_and_password') . $fa;
     }
     return json_encode($resp);
 }