Verify the user given a verify registration token

@param  TokenEntity $token
@return UserEntity
@throws OutOfBoundsException
961606
public function verifyRegistration(TokenEntity $token)
    {
        if ($token->isNew()) {
            throw new OutOfBoundsException('NOT_FOUND', self::TOKEN_NOT_FOUND);
        }

        if ((int) $token->getTokenTypeId() !== TokenEntity::TYPE_VERIFY_REGISTRATION) {
            throw new OutOfBoundsException('NOT_FOUND', self::INCORRECT_TOKEN_TYPE);
        }

        if ($token->getExpires() < time()) {
            throw new OutOfBoundsException('EXPIRED', self::TOKEN_EXPIRED);
        }

        $user = $this->findById($token->getUserId());

        // Token looks good; verify user and delete the token
        $user->setVerified(true);

        $this->userMapper->persist($user);

        $this->tokenMapper->delete($token);

        return $user;
    }
1237326
public function verifyEmailToken($token)
	{
		$this->debug->groupCollapsed(__METHOD__);
		$return = false;
		$token = base64_decode($token);
		$vals = array(
			'token_hash' => $this->db->quoteValue(sha1($token)),
		);
		$query = Str::quickTemp('SELECT * FROM `email_tokens`
			WHERE `token_hash` = [::token_hash::]', $vals);
		$rows = $this->db->query($query)[0];
		$this->debug->table($rows, 'rows');
		if ($rows) {
			// found token in table
			$return = $rows[0]['userid'];
			// remove the token
			$where = $vals;
			$this->db->rowMan('email_tokens', null, $where);
			$this->log('pwForgotTokenSuccess', $rows[0]['userid']);
		} else {
			$this->log('pwForgotTokenFail');
		}
		$this->debug->groupEnd();
		return $return;
	}
213057
public function verifyTwoFactor(UserInterface $user, $token, $remember = false)
    {
        $this->getTwoFactorStrategy()->verify($user, $token);

        // mark the user as 2FA verified, now and for the session
        $user->markTwoFactorVerified();

        // the user is now considered fully signed in
        // now we want to perform the sign in so an event is recorded
        // and a remember me token is generated, if needed
        if (!$user->isSignedIn()) {
            $this->signInUser($user, '2fa', $remember);
        }

        $saved = $this->getStorage()
                      ->twoFactorVerified($user,
                                          $this->request,
                                          $this->response);
        if (!$saved) {
            throw new AuthException('Unable to mark user session as two-factor verified');
        }

        return $this;
    }
586748
public static function validateToken($tokenString)
    {
        $tokens = ApiToken::find(new AndGroup(
            [
                new Equals("Token", $tokenString),
                new GreaterThan("Expires", "now", true)
            ]
        ));

        if (count($tokens) != 1) {
            throw new TokenInvalidException();
        }

        /** @var ApiToken $token */
        $token = $tokens[0];
        $settings = ApiSettings::singleton();
        if ($settings->extendTokenExpirationOnUse) {
            $token->Expires = $settings->tokenExpiration;
            $token->save();
        }

        return $token->AuthenticatedUser;
    }
563473
public function findUserByToken(PasswordResetToken $token): User
    {
        foreach ($this->userRepositories as $repository) {
            $user = $repository->findByPasswordResetToken($token);

            if ($user) {
                return $user;
            }
        }

        throw UserNotFound::withToken($token);
    }
154432
public function authenticate(TokenInterface $token)
    {
        if (!$this->supports($token)) {
            return null;
        }

        $user = $token->getUser();

        if (!($user instanceof UserInterface)) {
            return null;
        }

        $user = $this->userProvider->refreshUser($user);
        $this->userChecker->checkPostAuth($user);

        $authenticatedToken = new JoomlaToken(
            $user,
            $user->getPassword(),
            $this->providerKey,
            $user->getRoles()
        );
        $authenticatedToken->setAttributes($token->getAttributes());

        return $authenticatedToken;
    }
100084
public function verifyByToken($tokenString)
    {
        $this->loadModel('Wasabi/Core.Tokens');

        if (!$this->request->is('get')) {
            throw new MethodNotAllowedException();
        }

        /** @var Token $token */
        if ($tokenString && (bool)($token = $this->Tokens->findByToken($tokenString)) &&
            !$token->hasExpired() && !$token->used
        ) {
            /** @var User $user */
            $user = $this->Users->get($token->user_id);

            /** @var Connection $connection */
            $connection = $this->Users->connection();
            $connection->begin();
            if ($this->Users->verify($user)) {
                $this->Tokens->invalidateExistingTokens($user->id, TokensTable::TYPE_EMAIL_VERIFICATION);
                $connection->commit();
            } else {
                $connection->rollback();
            }
        }

        $this->render(null, 'Wasabi/Core.support');
    }
416279
public static function fromToken(TokenInterface $token)
    {
        $user = $token->getUser();

        if ($user instanceof UserInterface) {
            return self::fromAccount($user);
        }

        throw new InvalidArgumentException('The user class must implement "Fxp\Component\Security\Model\UserInterface"');
    }
469615
public static function findIdentityByAccessToken($token, $type = null)
    {
        $self = static::buildNoInitModel();
        return static::findOne([$self->accessTokenAttribute => $token]);
    }
69167
public function getByRememberToken(int $id, string $token) : ?Authenticatable
    {
        $model = $this->getModel();

        $user = $model->newQuery()
                      ->where($model->getAuthIdentifierName(), $id)
                      ->first();

        if ($user === null) {
            return null;
        }

        $rememberToken = $user->getRememberToken();

        return !empty($rememberToken) && hash_equals($rememberToken, $token) ? $user : null;
    }
183398
public function validateRandomSessionToken(string $token): bool
    {
        if (!isset($this->session[$this->name])) {
            return false;
        }

        return $token == $this->session[$this->name];
    }
497894
protected function verifyCsrfToken($token=null)
    {
        if ($this->options['csrfTokenEnabled']) {
            $token || $token = $this->request->getParam($this->options['csrfTokenName']);
            
            $data = static::getCsrfTokenData();
            
            $res = FormToken::instance()->verify($token, $data);
            
            if ($res['errcode']) {
                $this->stop()->errorInfo = $res;
            }
        }
        
        return $this->errorInfo;
    }
892198
public function retrieveByToken($identifier, $token)
    {
        return $this->getRepository()->findOneBy([
            $this->getEntity()->getKeyName()           => $identifier,
            $this->getEntity()->getRememberTokenName() => $token
        ]);
    }
280142
public function afterTokenVerification(Entity $user, $options = []) {
		if ($user->get('token_is_expired') === true) {
			return false;
		}

		if ($options['tokenField'] === $this->_field('emailToken')) {
			$user->set([
				$this->_field('emailVerified') => true,
				$this->_field('emailToken') => null,
				$this->_field('emailTokenExpires') => null
			], [
				'guard' => false
			]);
		}

		return $this->_table->save($user, ['validate' => false]);
	}
570258
protected function validateToken($token)
    {
        if (!$token) return false;
        try {
            $invitation = UserInvitation::where('token', $token)
                ->where('state', 'pending')->first();
            if ($invitation) {
                if ( $invitation->token === $token) return $invitation;
            }
        } catch (ModelNotFoundException $e) {
            return false;
        }

        return false;
    }
1026160
public static function findForAuthToken($identifier, $token) {
		return self::where(self::META_USER_PRIMARY_KEY, '=', $identifier)
			->where('remember_token', '=', $token)
			->first();
	}
706262
public function getByApiToken(int $id, string $token) : ?Authenticatable
    {
        $model = $this->getModel();

        $user = $model->newQuery()
                      ->where($model->getAuthIdentifierName(), $id)
                      ->first();

        if ($user === null) {
            return null;
        }

        $apiToken = $user->getApiToken();

        return !empty($apiToken) && hash_equals($apiToken, $token) ? $user : null;
    }