Example #1
0
 public function auth()
 {
     $this->_methodName = 'auth';
     $this->resolveParams();
     $arNeed = ['email' => 'required|email|max:200', 'passwd' => 'required|min:8|max:32'];
     if (Auth::check()) {
         throw new \App\Exceptions\ExceptionApiAuthAlready(['email' => $this->_request_params['email']], $this->_typeName, $this->_methodName);
     }
     $this->checkAttr($arNeed);
     $auth_user = \App\Users::whereEmail($this->_request_params['email'])->first();
     if (is_null($auth_user)) {
         $auth_user = \App\Admin::whereEmail($this->_request_params['email'])->first();
         if (is_null($auth_user)) {
             throw new \App\Exceptions\ExceptionApiUserNotFound(['email' => $this->_request_params['email']], $this->_typeName, $this->_methodName);
         }
     }
     if (Hash::check($this->_request_params['passwd'], $auth_user->password)) {
         Auth::login($auth_user->email);
         $user = Auth::user();
         $this->_arData['data']['token'] = Auth::getToken();
         if (!$this->checkUserUnable() && !Auth::checkAdmin()) {
             $this->_arData['warning'] = 'NOT_FULL_USER_INFO';
         }
     } else {
         throw new \App\Exceptions\ExceptionApiAuthFail(['email' => $this->_request_params['email']], $this->_typeName, $this->_methodName);
     }
     return $this;
 }