Ejemplo n.º 1
0
 public function getUserFromCookie($cookie)
 {
     $tokenObject = new Token($cookie);
     // Get a payload info from the token
     try {
         $payload = JWTAuth::decode($tokenObject);
     } catch (TokenExpiredException $e) {
         $message = 'Token in cookie was expired';
         throw new TokenInCookieExpiredException($message, null, $e);
     }
     // Get user by the payload info
     try {
         $user = $this->userUpdater->updateBaseInfo($payload);
     } catch (RepositoryException $e) {
         throw new AuthException($e->getMessage(), null, $e);
     }
     // Attempt to update his profile by API or just log the error
     try {
         $user = $this->userUpdater->updateAdditionalInfo($cookie, $user);
     } catch (UpdatingFailureException $e) {
         Log::warning('An additional user information was\'nt updated. ' . $e->getMessage());
     }
     // Login
     Auth::login($user, true);
     // Return an actual user model if login passes
     if (Auth::check()) {
         return $this->userRepository->findWithRelations(Auth::id(), ['localRole']);
     } else {
         throw new AuthException('Login error. User is not authorized.');
     }
 }
Ejemplo n.º 2
0
 /**
  * @param $cookie
  *
  * @return static
  */
 public static function getUserByCookie($cookie)
 {
     $tokenObject = new Token($cookie);
     $payload = JWTAuth::decode($tokenObject);
     $userInfo = $payload->toArray();
     // temp test user
     $user = User::firstOrCreate(['email' => $userInfo['email']]);
     $role = array_key_exists('role', $userInfo) ? $userInfo['role'] : "DEVELOPER";
     $user->update(['bid' => $userInfo['id'], 'role' => $role, 'first_name' => $userInfo['email'], 'last_name' => '', 'phone' => '666-66-666', 'avatar' => 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($userInfo['email']))) . '?d=retro', 'address' => 'iat: ' . $userInfo['iat'], 'job_id' => 1, 'department_id' => 1]);
     return $user;
 }
Ejemplo n.º 3
0
 protected function extractUserDataFromCookie($cookie)
 {
     $tokenObject = new Token($cookie);
     // Get a payload info from the token
     try {
         $payload = JWTAuth::decode($tokenObject);
     } catch (TokenExpiredException $e) {
         $message = 'Token in cookie was expired';
         throw new TokenInCookieExpiredException($message, null, $e);
     }
     return $payload;
 }
Ejemplo n.º 4
0
 public function getUserFromCookie($cookie)
 {
     $tokenObject = new Token($cookie);
     try {
         $payload = JWTAuth::decode($tokenObject);
     } catch (TokenExpiredException $e) {
         throw new TokenInCookieExpiredException('Token in cookie was expired', null, $e);
     }
     $userInfo = $payload->toArray();
     $preparedUserInfo = $this->prepareUserData($userInfo);
     $user = $this->userRepository->updateFirstOrCreate(['email' => $preparedUserInfo['email']], $preparedUserInfo);
     $this->attachAdditionUserInfo($cookie, $user);
     Auth::login($user, true);
     if (Auth::check()) {
         return $this->userRepository->findWithRelations(Auth::id(), ['role']);
     } else {
         throw new AuthException('Login error. User is not authorized.');
     }
 }