Domain\Auth\AuthService::byCredentials PHP Method

byCredentials() public method

public byCredentials ( array $credentials, string $type ) : array
$credentials array
$type string
return array
    public function byCredentials(array $credentials, $type)
    {
        $email = array_get($credentials, 'username');
        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $credentials['email'] = $email;
            unset($credentials['username']);
        }
        $credentials['owner_type'] = $type;
        try {
            // attempt to verify the credentials and create a token for the user
            if (!($token = JWTAuth::attempt($credentials))) {
                return ['error' => 'invalid_credentials'];
            }
        } catch (JWTException $e) {
            // something went wrong whilst attempting to encode the token
            return ['error' => 'could_not_create_token'];
        }
        return $this->getUser($token);
    }

Usage Example

コード例 #1
0
 public function login(AuthRequest $request)
 {
     $data = $request->only(['username', 'password']);
     $type = $request->get('type');
     $type = "Domain\\{$type}\\{$type}";
     $remember = $request->get('remember');
     $response = $this->auth->byCredentials($data, $type, $remember);
     if (isset($response['error'])) {
         return response()->json($response, 403);
     }
     return response()->json($response);
 }