Esempio n. 1
0
 /**
  * Attempt to authenticate the user and return the token.
  *
  * @param array $credentials
  * @param array $customClaims
  *
  * @return false|string
  */
 public function attempt(array $credentials = [], array $customClaims = [])
 {
     if (!$this->auth->byCredentials($credentials)) {
         return false;
     }
     return $this->fromUser($this->auth->user(), $customClaims);
 }
Esempio n. 2
0
 public function postIndex(Request $request, JWTAuth $jwt, AuthInterface $auth)
 {
     $credentials = $request->only('email', 'password');
     try {
         if ($auth->byCredentials($credentials)) {
             if ($auth->user()->group == User::GROUP_DISABLED) {
                 throw new UserDisabledException('Account has been disabled.');
             }
             $extraInfo = ['user' => $auth->user(), 'code' => Crypt::encrypt(md5($credentials['password']))];
             if ($token = $jwt->fromUser($auth->user(), $extraInfo)) {
                 event(new UserLoggedIn($auth->user()));
                 return $this->jsonResponse(['token' => $token]);
             }
         }
     } catch (JWTException $e) {
         return $this->jsonResponse(['Error creating JWT token'], 401);
     } catch (UserDisabledException $e) {
         return $this->jsonResponse([$e->getMessage()], 401);
     }
     return $this->jsonResponse(['Invalid username or password'], 401);
 }