Finds a token by params.

@param integer $userId
@param string  $code
@param integer $type

@return Token
544143
public function findTokenByParams($userId, $code, $type)
    {
        return $this->findToken([
            'user_id' => $userId,
            'code'    => $code,
            'type'    => $type,
        ])->one();
    }
392489
public function attemptMobileChange($code)
    {
        /** @var Token $token */
        $token = Token::find()->where([
            'user_id' => $this->id,
            'code' => $code
        ])->andWhere(['in', 'type', [Token::TYPE_CONFIRM_NEW_MOBILE, Token::TYPE_CONFIRM_OLD_MOBILE]])->one();
        if (empty($this->unconfirmed_mobile) || $token === null || $token->isExpired) {
            Yii::$app->session->setFlash('danger', Yii::t('user', 'Your confirmation token is invalid or expired'));
        } else {
            $token->delete();
            if (empty($this->unconfirmed_mobile)) {
                Yii::$app->session->setFlash('danger', Yii::t('user', 'An error occurred processing your request'));
            } elseif (static::find()->where(['mobile' => $this->unconfirmed_mobile])->exists() == false) {
                if ($this->getSetting('mobileChangeStrategy') == Settings::STRATEGY_SECURE) {
                    switch ($token->type) {
                        case Token::TYPE_CONFIRM_NEW_MOBILE:
                            $this->flags |= self::NEW_MOBILE_CONFIRMED;
                            Yii::$app->session->setFlash('success', Yii::t('user', 'Awesome, almost there. Now you need to input the confirmation code sent to your old mobile'));
                            break;
                        case Token::TYPE_CONFIRM_OLD_MOBILE:
                            $this->flags |= self::OLD_MOBILE_CONFIRMED;
                            Yii::$app->session->setFlash('success', Yii::t('user', 'Awesome, almost there. Now you need to input the confirmation code sent to your new mobile'));
                            break;
                    }
                }
                if ($this->getSetting('mobileChangeStrategy') == Settings::STRATEGY_DEFAULT
                    || ($this->flags & self::NEW_MOBILE_CONFIRMED && $this->flags & self::OLD_MOBILE_CONFIRMED)) {
                    $this->mobile = $this->unconfirmed_mobile;
                    $this->unconfirmed_mobile = null;
                    Yii::$app->session->setFlash('success', Yii::t('user', 'Your mobile address has been changed'));
                }
                $this->save(false);
            }
        }
    }
296090
public function verifyToken($token, $userId)
	{
		$user = $this->repository->get($userId);
		$now = new DateTime();

		if ($user) {
			$dateDiff = $now->diff($user->reset_password_requested_at);

			$totalHours = ($dateDiff->d * 24) + $dateDiff->h;

			// remove token older than 2h
			if ($totalHours > 2) {
				$update = [
					'reset_password_requested_at' => NULL,
					'reset_password_token' => NULL,
				];
				$this->repository->update($userId, $update);

				return FALSE;
			}

			if (Passwords::verify($token, $user->reset_password_token)) {
				$update = [
					'reset_password_requested_at' => NULL,
					'reset_password_token' => NULL,
				];
				$this->repository->update($userId, $update);

				return TRUE;
			}
		}

		return FALSE;
	}
124317
public function getForgotPasswordConfirm($userId, $passwordResetCode)
    {
        // Find the user using the password reset code
        if(!$user = Sentinel::findById($userId))
        {
            // Redirect to the forgot password page
            return Redirect::route('forgot-password')->with('error', Lang::get('base.auth.forgot_password_confirm.error'));
        }

        // Show the page
        return View('auth.forgot-password-confirm', compact('userId', 'passwordResetCode'));
    }
660137
public function getAuthorizationCode($code)
    {
        if (isset($this->authorizationCodes[$code])) {
            return $this->authorizationCodes[$code];
        }

        return null;
    }
1319622
protected function getTokenByAuthorizationCodeGrant($code)
    {
        try {
            $token = $this->getAuthorizationServer()->getAccessToken('authorization_code', [
                'code' => $code,
            ]);

            $this->getFrameworkBridge()->persistUserToken($token);

            return $token;
        } catch (IdentityProviderException $e) {
            return null;
        }
    }
646343
public function generateToken($userId)
    {
        $user = $this->users->find($userId);

        if (! is_null($user)) {
            $user->generateActivationToken();
            $user->setStatus(Status::INACTIVE);
        }
    }
1289791
public function findUserByPersistenceCode($code)
    {
        $persistence = $this->findByPersistenceCode($code);

        if ($persistence)
        {
            return $persistence->getUser();
        }

        return false;
    }
478597
public static function findByUser( $parentId, $parentType, $userId, $type = ModelComment::TYPE_COMMENT ) {

		return static::find()->where( 'parentId=:pid AND parentType=:ptype AND createdBy=:uid AND type=:type', [ ':pid' => $parentId, ':ptype' => $parentType, ':uid' => $userId, ':type' => $type ] )->one();
	}
203576
public function findForUser($id, $userId)
    {
        return Passport::token()->where('id', $id)->where('user_id', $userId)->first();
    }
979855
public function scopeWhereLikedBy(Builder $query, $type, $userId)
    {
        $userId = $this->getLikerUserId($userId);

        return $query->whereHas('likesAndDislikes', function (Builder $innerQuery) use ($type, $userId) {
            $innerQuery->where('user_id', $userId);
            $innerQuery->where('type_id', $this->getLikeTypeId($type));
        });
    }
419280
public function getVerify($userId, $sessionCode)
    {
        $validSession = $this->serviceRagnarok->validUserSession($userId, $sessionCode);

        if ($validSession->success) {
            $data = $validSession->response->data;
            $this->userRagnarok->make($data);

            if (session('environment') == 1) {
                session()->put('dashboard', true);
            }

            return redirect()->to('/');
        }

        return $this->getLogout();

    }
832026
public function findByUserId($userId)
    {
        $select = $this->getSelect();
        $select->where(array('user_id' => $userId));

        return $this->select($select);
    }
515359
public function get( $code, $type = null )
	{
		if( isset( $this->prodmap[$code] ) ) {
			return $this->prodmap[$code];
		}

		$manager = \Aimeos\MShop::create( $this->getContext(), 'product' );

		$search = $manager->createSearch();
		$search->setConditions( $search->compare( '==', 'product.code', $code ) );

		$result = $manager->searchItems( $search );

		if( ( $item = reset( $result ) ) !== false )
		{
			$this->prodmap[$code] = $item->getId();
			return $this->prodmap[$code];
		}
	}
452949
public function fromCode($code, $context)
    {
        $tokens = token_get_all($code);

        return $this->fromTokens($tokens, $context);
    }
473158
public function createToken(UserInterface $user, string $operator = null): TokenInterface
    {
        return $this->getOperator($operator ?? $this->config->defaultOperator())->createToken($user);
    }
1010148
public function readByCode(string $code, int $expirationInSeconds): ?TokenInterface
    {
        $schema = $this->getDatabaseSchema();
        return $this->readEnabledTokenByColumnWithExpirationCheck(
            $code,
            $schema->getTokensCodeColumn(),
            $expirationInSeconds,
            $schema->getTokensCodeCreatedAtColumn()
        );
    }