user_logout example


  public function logout() {
    $this->userLogout();
    return new Response(NULL, 204);
  }

  /** * Logs the user out. */
  protected function userLogout() {
    user_logout();
  }

  /** * Checks whether a user is logged in or not. * * @return \Symfony\Component\HttpFoundation\Response * The response. */
  public function loginStatus() {
    if ($this->currentUser()->isAuthenticated()) {
      $response = new Response(self::LOGGED_IN);
    }


  /** * Logout users if site is in maintenance mode and user is not exempt. * * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event * The event to process. */
  public function onMaintenanceModeRequest(RequestEvent $event) {
    // If the site is offline, log out unprivileged users.     if ($this->account->isAuthenticated()) {
      user_logout();
      // Redirect to homepage.       $event->setResponse(
        new RedirectResponse(Url::fromRoute('<front>')->toString())
      );
    }
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    

  public function resetPass(Request $request$uid$timestamp$hash) {
    $account = $this->currentUser();
    // When processing the one-time login link, we have to make sure that a user     // isn't already logged in.     if ($account->isAuthenticated()) {
      // The current user is already logged in.       if ($account->id() == $uid) {
        user_logout();
        // We need to begin the redirect process again because logging out will         // destroy the session.         return $this->redirect(
          'user.reset',
          [
            'uid' => $uid,
            'timestamp' => $timestamp,
            'hash' => $hash,
          ]
        );
      }
      
Home | Imprint | This part of the site doesn't use cookies.