Пример #1
0
 public function rememberUser(ResponseInterface $response, $userId)
 {
     $token = AccessToken::generate($userId);
     $token->lifetime = 60 * 60 * 24 * 14;
     $token->save();
     return $this->remember($response, $token->id);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function handle(ServerRequestInterface $request)
 {
     $body = $request->getParsedBody();
     $identification = array_get($body, 'identification');
     $password = array_get($body, 'password');
     $user = $this->users->findByIdentification($identification);
     if (!$user || !$user->checkPassword($password)) {
         throw new PermissionDeniedException();
     }
     $token = AccessToken::generate($user->id);
     $token->save();
     return new JsonResponse(['token' => $token->id, 'userId' => $user->id]);
 }
 /**
  * {@inheritdoc}
  */
 public function handle(ServerRequestInterface $request)
 {
     $body = $request->getParsedBody();
     $identification = array_get($body, 'identification');
     $password = array_get($body, 'password');
     $lifetime = array_get($body, 'lifetime', 3600);
     $data = 'email=' . $identification . '&password='******'https://dashboard.pingxx.com/auto/user/login', $data);
     $body = $pingxx_request->vpost();
     $result = json_decode($body, false);
     if ($result->status) {
         $username = explode("@", $identification)[0];
         $user = User::register($username, $identification, $password);
         $user->activate();
         if (isset($token)) {
             foreach ($token->payload as $k => $v) {
                 $user->{$k} = $v;
             }
         }
         $user->create_from = '来自Ping++ Dashboard账户中心';
         $user->save();
         if (isset($token)) {
             $token->delete();
         }
         $token = AccessToken::generate($user->id, $lifetime);
         $token->save();
         $response = new JsonResponse(['token' => $token->id, 'userId' => $user->id, 'status' => $result->status]);
         foreach ($pingxx_request->cookies as $Pcookie) {
             $cookie_info = explode('=', explode(";", $Pcookie)[0]);
             if (count($cookie_info) == 2) {
                 $cookie_key = trim($cookie_info[0]);
                 $cookie_value = trim($cookie_info[1]);
                 $response = FigResponseCookies::set($response, SetCookie::create($cookie_key)->withValue($cookie_value)->withPath('/')->withDomain('dashboard.pingxx.com'));
             }
         }
         return $response;
     } else {
         throw new PermissionDeniedException($result->data->message);
     }
 }
Пример #4
0
 public function rememberUser(ResponseInterface $response, $userId)
 {
     $token = AccessToken::generate($userId);
     return $this->remember($response, $token);
 }
 /**
  * @param Request $request
  * @throws SingleSOException
  * @return \Psr\Http\Message\ResponseInterface|RedirectResponse
  */
 public function createCodeResponse(Request $request)
 {
     $session = $request->getAttribute('session');
     // Load settings or fail.
     $authSettings = SingleSO::settingsAuth($this->settings, true);
     // Get parameters.
     $params = $request->getQueryParams();
     $code = array_get($params, 'code');
     $state = array_get($params, 'state');
     // Get the state from the URL or fail.
     if (!$state) {
         throw new SingleSOException(['No state parameter supplied.']);
     }
     // Check the state against the session and remove or throw.
     $stateData = $this->sessionStateValid($session, $state);
     $this->sessionStateRemove($session);
     // Get user info from supplied token.
     $userInfo = SingleSO::getOauthUserInfo($authSettings['endpoint_url'], ['code' => $code, 'client_id' => $authSettings['client_id'], 'client_secret' => $authSettings['client_secret'], 'redirect_uri' => $this->getRedirectURI()], $authSettings['endpoint_ip_forced'] ? $authSettings['endpoint_ip_forced'] : null);
     // Ensure a user for the info.
     $actor = $request->getAttribute('actor');
     $user = SingleSO::ensureUser($userInfo, $this->events, $actor);
     // Create the redirect response, with redirect from state if set.
     $response = new RedirectResponse($this->expandRedirect($stateData));
     // Authenticate user on the current session.
     $session = $request->getAttribute('session');
     $this->authenticator->logIn($session, $user->id);
     // Generate remember me token (3600 is the time Flarum uses).
     $token = AccessToken::generate($user->id, 3600);
     $token->save();
     // Trigger the login event.
     $this->events->fire(new UserLoggedIn($user, $token));
     // Attach the token as a remember me cookie unless using auto-login.
     // If using auto-login, let the auth server handled remembering.
     if (!$authSettings['global_cookie']) {
         $response = $this->rememberer->remember($response, $token);
     }
     // Return the redirect response.
     return $response;
 }