Logs the given user into the system.

@param \Tilmeld\Entities\User $user The user.
@param bool $alwaysSendAuthHeader When true, a custom header with the auth
token will be sent.
@return bool True on success, false on failure.
541632
public static function login($user, $sendAuthHeader) {
    if (isset($user->guid) && $user->enabled) {
      $token = self::$config['jwt_builder']($user);
      $appUrlParts = parse_url(self::$config['app_url']);
      setcookie(
          'TILMELDAUTH',
          $token,
          time() + self::$config['jwt_expire'],
          $appUrlParts['path'],
          $appUrlParts['host'],
          $appUrlParts['scheme'] === 'https',
          false // Allow JS access (for CSRF protection).
      );
      if ($sendAuthHeader) {
        header("X-TILMELDAUTH: $token");
      }
      self::fillSession($user);
      return true;
    }
    return false;
  }
1322616
public function isOwner(User $user)
    {
        $owner = $this->getOwner();
        if ($owner !== null && $user->getId() === $owner->getUser()->getId()) {
            return true;
        }

        return false;
    }
785500
public function verifyPassword(User $user, string $password): bool
    {
        $this->enforcePasswordStrength($password);

        $auth = $this->authenticationProvider->findByUserId($user->getId());
        if (!$auth) {
            throw new NoSuchUserException();
        }

        return password_verify($password, $auth->getHash());
    }
741184
public function isGrantedTo($user): bool
    {
        $userModel = config('auth.providers.users.model');

        if (is_int($user) && !$userModel::find($user)) {
            return false;
        }

        return $this->users()->where('user_id', is_int($user) ? $user : $user->id)->exists();
    }
256396
public function notifyPasswordReset(User $user, $plainPassword)
    {
        $fromEmail = $this->container->getParameter("default_mail_from");
        $fromName = $this->container->getParameter("default_mail_from_name");
        $appName = $this->container->getParameter("default_app_name");
        $subject = "[$appName] Cambio de datos";
        $toEmail = $user->getEmail();
        $toName = $user->getFirstname();
        $body = $this->container->get('templating')->render('FlowcodeUserBundle:Email:notifyPasswordReset.html.twig', array('user' => $user, 'plainPassword' => $plainPassword));

        $this->mailSender->send($toEmail, $toName, $fromEmail, $fromName, $subject, $body, true);
    }
254673
public function setUser(User $user)
    {
        $this->user = $user;
        $this->user->addTweet($this);

        return $this;
    }
973605
public function setUserLoggedIn(AdminUser $user): string
    {
        $_SESSION['admin_logged'] = true;
        $_SESSION['admin_id'] = $user->getId();
        $_SESSION['admin_login'] = $user->getLogin();
        $_SESSION['admin_sid'] = Users::getInstance()->startSession($user->getId());

        if (!defined('USER_ID')) {
            define('USER_ID', $user->getId());
        }

        App::add('User "' . $user->getLogin() . '" logged in.');

        return $_SESSION['admin_sid'];
    }
813992
public function onAsyncUserCreate(User $user)
    {
        if ($user['groupId']) {
            return;
        }

        $defaultGroupId = wei()->setting('user.defaultGroupId', 0);
        if ($defaultGroupId) {
            $user->updateGroup($defaultGroupId);
        }
    }
4914
public function logUser(User $user)
    {
        $this->strictEventDispatcher->dispatch('log', 'Log\LogUserLogin', array($user));
        $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
        $this->container->get('security.token_storage')->setToken($token);
    }
136662
public function login(AuthenticatableContract $user, $remember = false)
    {
        $this->updateSession($user->getAuthIdentifier());

        // If the user should be permanently "remembered" by the application we will
        // queue a permanent cookie that contains the encrypted copy of the user
        // identifier. We will then decrypt this later to retrieve the users.
        if ($remember) {
            $this->ensureRememberTokenIsSet($user);

            $this->queueRecallerCookie($user);
        }

        // If we have an event dispatcher instance set we will fire an event so that
        // any listeners will hook into the authentication events and run actions
        // based on the login and logout events fired from the guard instances.
        $this->fireLoginEvent($user, $remember);

        $this->setUser($user);
    }
87113
protected function approveRequest($authRequest, $user)
    {
        $authRequest->setUser(new User($user->getKey()));

        $authRequest->setAuthorizationApproved(true);

        return $this->convertResponse(
            $this->server->completeAuthorizationRequest($authRequest, new Psr7Response)
        );
    }
1217500
public function createUser(User $user)
    {
        $query = $this->handler->createInsertQuery();
        $query
            ->insertInto($this->handler->quoteTable('ezuser'))
            ->set(
                $this->handler->quoteColumn('contentobject_id'),
                $query->bindValue($user->id, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('login'),
                $query->bindValue($user->login)
            )->set(
                $this->handler->quoteColumn('email'),
                $query->bindValue($user->email)
            )->set(
                $this->handler->quoteColumn('password_hash'),
                $query->bindValue($user->passwordHash)
            )->set(
                $this->handler->quoteColumn('password_hash_type'),
                $query->bindValue($user->hashAlgorithm, null, \PDO::PARAM_INT)
            );
        $query->prepare()->execute();

        $query = $this->handler->createInsertQuery();
        $query
            ->insertInto($this->handler->quoteTable('ezuser_setting'))
            ->set(
                $this->handler->quoteColumn('user_id'),
                $query->bindValue($user->id, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('is_enabled'),
                $query->bindValue($user->isEnabled, null, \PDO::PARAM_INT)
            )->set(
                $this->handler->quoteColumn('max_login'),
                $query->bindValue($user->maxLogin, null, \PDO::PARAM_INT)
            );
        $query->prepare()->execute();
    }
746575
public function iAuthenticateAs($user)
    {
        if (!isset($this->users[$user])) {
            throw new ClientErrorResponseException(
                'User ' . $user . ' does not exist'
            );
        }

        $this->addGuzzleHeader(
            'Authorization',
            'Bearer ' . $this->users[$user]
        );
    }
241637
public function verifyEmail(User $user, $token)
    {
        $this->_prepareEmail($user, __d('wasabi_core', 'Verify your email address'));
        $this->_email->template('Wasabi/Core.User/verify');
        $this->_email->viewVars([
            'user' => $user,
            'verifyEmailLink' => [
                'plugin' => 'Wasabi/Core',
                'controller' => 'Users',
                'action' => 'verifyByToken',
                'token' => $token
            ],
            'instanceName' => Wasabi::getInstanceName()
        ]);
    }
1165106
public function save(User $user) : bool
    {
        if (!$user->save()) {
            throw new \RuntimeException($this->i18n->t('setrun/user', 'Saving error'));
        }
        return true;
    }
863178
public function encryptUserData(AbstractUser $user)
    {
        // data (we use short syntax to reduce the size of the cookie or session)
        $data = [
            // username
            'u'  => $user->getUsername(),
            // valid until
            'vu' => time() + $this->getTokenTtl(),
            // auth provider driver
            'ap' => $user->getAuthProviderName(),
            // user provider driver
            'up' => $user->getUserProviderName()
        ];

        // build and add token to $data
        $token = $this->getCrypt()->encrypt($this->jsonEncode($data), $this->getEncryptionKey());
        $token = urlencode(rtrim($token, '='));

        return $token;
    }
695990
public function loginOAuthUser(OAuthUserContract $user)
    {
        /** @noinspection PhpUndefinedFieldInspection */
        $responseBody = $user->accessTokenResponseBody;
        /** @noinspection PhpUndefinedFieldInspection */
        $token = $user->token;

        $dfUser = $this->createShadowOAuthUser($user);
        $dfUser->last_login_date = Carbon::now()->toDateTimeString();
        $dfUser->confirm_code = null;
        $dfUser->save();

        $map = OAuthTokenMap::whereServiceId($this->id)->whereUserId($dfUser->id)->first();
        if (empty($map)) {
            OAuthTokenMap::create(
                [
                    'user_id'    => $dfUser->id,
                    'service_id' => $this->id,
                    'token'      => $token,
                    'response'   => $responseBody
                ]);
        } else {
            $map->update(['token' => $token, 'response' => $responseBody]);
        }
        Session::setUserInfoWithJWT($dfUser);
        $response = Session::getPublicInfo();
        $response['oauth_token'] = $token;
        if (isset($responseBody['id_token'])) {
            $response['id_token'] = $responseBody['id_token'];
        }

        return $response;
    }