Creates new confirmation token and sends it to the user.

@return boolean
977783
public function resend()
    {
        if (!$this->validate()) {
            return false;
        }
        /** @var UserToken $token */
        $token = new UserToken(['user_id' => $this->user->id, 'type' => UserToken::TYPE_CONFIRMATION]);
        $token->save(false);
        Yii::$app->sendMail($this->user->email,Yii::t('yuncms', 'Confirm account on {0}', Yii::$app->name),'user/confirmation',['user' => $this->user, 'token' => $token]);
        Yii::$app->session->setFlash('info', Yii::t('yuncms', 'A message has been sent to your email address. It contains a confirmation link that you must click to complete registration.'));
        return true;
    }
1234619
private static function create_login_token() {
        global $SESSION;

        $state = [
            'token' => random_string(32),
            'created' => time() // Server time - not user time.
        ];

        if (!isset($SESSION->logintoken)) {
            $SESSION->logintoken = [];
        }

        // Overwrite any previous values.
        $SESSION->logintoken[self::$logintokenkey] = $state;

        return $state;
    }
1085238
public function sendEmail()
    {
        if (!$this->validate()) {
            return false;
        }

        /** @var \amnah\yii2\user\models\UserToken $userToken */
        $user = $this->getUser();
        $userToken = $this->module->model("UserToken");

        // calculate type based on user status
        if ($user->status == $user::STATUS_INACTIVE) {
            $type = $userToken::TYPE_EMAIL_ACTIVATE;
        } //elseif ($user->status == $user::STATUS_UNCONFIRMED_EMAIL) {
        else {
            $type = $userToken::TYPE_EMAIL_CHANGE;
        }

        // generate userToken and send email confirmation
        $userToken = $userToken::generate($user->id, $type);
        return $user->sendEmailConfirmation($userToken);
    }
464873
public function generateToken()
    {
        do {
            $token = sha1(microtime());
        } while ($this->newQuery()->where(['token' => $token])->count() > 0);

        return $token;
    }
857593
public function beforeValidationOnCreate()
    {
        // Timestamp the confirmaton
        $this->createdAt = time();

        // Generate a random confirmation code
        $this->code = preg_replace('/[^a-zA-Z0-9]/', '', base64_encode(openssl_random_pseudo_bytes(24)));

        // Set status to non-confirmed
        $this->reset = 'N';
    }
515762
public function confirmEmailAction()
    {
        $code = $this->dispatcher->getParam('code');

        $confirmation = EmailConfirmations::findFirstByCode($code);

        if (!$confirmation) {
            return $this->dispatcher->forward([
                'controller' => 'index',
                'action' => 'index'
            ]);
        }

        if ($confirmation->confirmed != 'N') {
            return $this->dispatcher->forward([
                'controller' => 'session',
                'action' => 'login'
            ]);
        }

        $confirmation->confirmed = 'Y';

        $confirmation->user->active = 'Y';

        /**
         * Change the confirmation to 'confirmed' and update the user to 'active'
         */
        if (!$confirmation->save()) {

            foreach ($confirmation->getMessages() as $message) {
                $this->flash->error($message);
            }

            return $this->dispatcher->forward([
                'controller' => 'index',
                'action' => 'index'
            ]);
        }

        /**
         * Identify the user in the application
         */
        $this->auth->authUserById($confirmation->user->id);

        /**
         * Check if the user must change his/her password
         */
        if ($confirmation->user->mustChangePassword == 'Y') {

            $this->flash->success('The email was successfully confirmed. Now you must change your password');

            return $this->dispatcher->forward([
                'controller' => 'users',
                'action' => 'changePassword'
            ]);
        }

        $this->flash->success('The email was successfully confirmed');

        return $this->dispatcher->forward([
            'controller' => 'users',
            'action' => 'index'
        ]);
    }
1276944
public function getRefreshToken()
    {
        if (is_string($this->refresh_token) && $this->isValidToken() ){

            $this->refreshToken = $this->token_type . ' ' . $this->refresh_token;

            return $this->refreshToken;
        }

        return false;
    }
654408
public function createAuthToken() {
    $url = URIResource::Make($this->path, array($this->id, 'tokens'));
    $token = $this->client->post($url, null);
    return new EndpointsToken($token);
  }
479394
protected function secureEmailChange() {
    $this->defaultEmailChange();
    /** @var Token $token */
    $token = Yii::createObject([
      'class' => Token::className(),
      'userId' => $this->user->id,
      'type' => Token::TYPE_CONFIRM_OLD_EMAIL,
    ]);
    $token->save(false);
    $this->mailer->sendReconfirmationMessage($this->user, $token);

    // unset flags if they exist
    $this->user->flags &= ~User::NEW_EMAIL_CONFIRMED;
    $this->user->flags &= ~User::OLD_EMAIL_CONFIRMED;
    $this->user->save(false);

    Yii::$app->session->setFlash('info', Yii::t('users', 'We have sent confirmation links to both old and new email addresses. You must click both links to complete your request'));
  }
1103058
public function generateToken()
    {
        $token = Mage::helper('core')->getRandomString(16);
        $this->addCookie(self::COOKIE_TOKEN, $token);
        $this->addCookie(self::COOKIE_TOKEN_CHECKSUM, $this->getChecksum(array('token' => $token)));
        return $this;
    }
6690
protected function createNewTokens()
    {
        $logger = $this->getLogger();
        $logger->debug('Starting request to create fresh access & refresh tokens');

        $body = [
            'client_id' => 'anonymous',
            'grant_type' => 'password',
            'response_type' => 'token',
            'scope' => 'openid',
            'username' => $this->credentials->getUsername(),
            'password' => $this->credentials->getPassword(),
        ];

        $response = $this->sendPostRequest($body);

        $logger->debug('Successfully retrieved new access & refresh tokens', $response);

        return [
            'accessToken' => new Token(
                $response['access_token'],
                $this->tokenExtractor->extract($response['access_token'])
            ),
            'refreshToken' => new Token(
                $response['refresh_token'],
                $this->tokenExtractor->extract($response['refresh_token'])
            ),
        ];
    }
358994
public function generateToken()
    {
        $adminUser = $this->auth->getUser();
        $refreshToken = $adminUser->getRefreshToken();

        if ($refreshToken) {
            $accessToken = $this->client->getAccessToken(
                $this->configFactory->getTokenUrl(),
                $this->buildUrlParams(
                    $this->helper->encryptor->decrypt($refreshToken)
                )
            );

            if (is_string($accessToken)) {
                return $accessToken;
            }
        }

        return false;
    }
348598
protected function checkToken()
    {
        $query = $this->query;
        $signature = $this->sign(
            $this->token,
            isset($query['timestamp']) ? $query['timestamp'] : '',
            isset($query['nonce']) ? $query['nonce'] : ''
        );
        return isset($query['signature']) && $signature === $query['signature'];
    }
584808
protected function Init()
    {
        $this->confirm = ContentRegisterConfirm::Schema()->ByContent($this->Content());
        $this->confirmer = new Confirmer();
        $this->isValid = $this->confirmer->Check(Request::GetArray());
        if ($this->isValid)
        {
            $this->OnSuccess();
        }
        else if ($this->confirm->GetErrorUrl())
        {
            Response::Redirect(FrontendRouter::Url($this->confirm->GetErrorUrl()));
            return true;
        }
        return parent::Init();
    }
209268
public function create()
    {
        $this->validate();

        $claims        = $this->processOptions();
        $claims['d']   = $this->data;
        $claims['v']   = 0;
        $claims['iat'] = time();

        try {
            $token = JWT::encode($claims, $this->secret, 'HS256');
        } catch (\Exception $e) {
            throw new TokenException($e->getMessage(), null, $e);
        }

        if (($tokenSize = mb_strlen($token, '8bit')) > static::MAX_TOKEN_SIZE) {
            throw new TokenException(
                sprintf('The generated token is larger than %d bytes (%d)', static::MAX_TOKEN_SIZE, $tokenSize)
            );
        }

        return $token;
    }
258137
public function authenticate()
    {
        $confirm = $this->getServiceLocator()
                        ->get( 'Grid\User\Model\ConfirmHash' );

        if ( $confirm->has( $this->hash ) )
        {
            $user = $this->getModel()
                         ->findByEmail( $confirm->find( $this->hash ) );

            if ( ! empty( $user ) )
            {
                $user->confirmed = true;

                if ( $user->save() )
                {
                    $confirm->delete( $this->hash );
                    return new Result( Result::SUCCESS, $user );
                }
                else
                {
                    return new Result( Result::FAILURE_UNCATEGORIZED, null );
                }
            }
        }
        else
        {
            return new Result( Result::FAILURE_CREDENTIAL_INVALID, null );
        }

        return new Result( Result::FAILURE_IDENTITY_NOT_FOUND, null );
    }
601925
protected function createToken()
    {
        $token = $this->getToken()->createApplicationToken(
            $this->connect->getSaml()->getMetadata()->getServiceProvider()->getEntityID(),
            $this->connect->getSaml()->getPrivateKey()
        );
        return $token['token'];
    }