当前位置: 首页>>代码示例>>PHP>>正文


PHP User::generatePasswordResetToken方法代码示例

本文整理汇总了PHP中app\modules\user\models\User::generatePasswordResetToken方法的典型用法代码示例。如果您正苦于以下问题:PHP User::generatePasswordResetToken方法的具体用法?PHP User::generatePasswordResetToken怎么用?PHP User::generatePasswordResetToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\modules\user\models\User的用法示例。


在下文中一共展示了User::generatePasswordResetToken方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generatePasswordResetToken

 /**
  * @return bool
  */
 public function generatePasswordResetToken()
 {
     if (!$this->validate()) {
         return false;
     }
     $new_password = \Yii::$app->security->generateRandomString(8);
     /** @var User $user */
     $user = User::findOne(['email' => $this->email]);
     $user->password_reset_token = User::generatePasswordResetToken();
     $user->password_hash = User::hashPassword($new_password);
     $user->status = User::USER_STATUS_INACTIVE;
     $user->save();
     $isSend = \Yii::$app->mailer->compose('user/forgot_password', ['user_name' => $user->name, 'token' => $user->password_reset_token, 'new_password' => $new_password])->setFrom(Settings::value('general', 'shopEmail'))->setTo($this->email)->setSubject(\Yii::t('mail', 'New password activation'))->send();
     if (!$isSend) {
         $this->addError(\Yii::t('mail', 'Oops, can\'t deliver letter to such email address.'));
     }
     return $isSend;
 }
开发者ID:vetoni,项目名称:toko,代码行数:21,代码来源:ForgotPasswordForm.php

示例2: onAuthSuccess

 public function onAuthSuccess($client)
 {
     $attributes = $client->getUserAttributes();
     /* @var $auth Auth */
     $auth = Auth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one();
     if (Yii::$app->user->isGuest) {
         if ($auth) {
             // login
             $user = $auth->user;
             Yii::$app->user->login($user);
         } else {
             // signup
             if (isset($attributes['email']) && User::find()->where(['email' => $attributes['email']])->exists()) {
                 Yii::$app->getSession()->setFlash('error', [Yii::t('app', "User with the same email as in {client} account already exists but isn't linked to it. Login using email first to link it.", ['client' => $client->getTitle()])]);
             } else {
                 $password = Yii::$app->security->generateRandomString(6);
                 $user = new User(['username' => $attributes['screen_name'], 'password' => $password, 'role' => 'user', 'email' => $attributes['email']]);
                 if (!empty($attributes['photo'])) {
                     $file = file_get_contents($attributes['photo']);
                     $avatarPath = \app\modules\user\Module::$avatarPath;
                     file_put_contents($avatarPath . '/1.jpg', $file);
                 }
                 $profile = new Profile(['firstname' => $attributes['first_name'], 'lastname' => $attributes['last_name'], 'country' => $attributes['country']]);
                 $user->generateAuthKey();
                 $user->generatePasswordResetToken();
                 $transaction = $user->getDb()->beginTransaction();
                 if ($user->save()) {
                     // Сохраняем профиль
                     $profile->user_id = $user->id;
                     if (!$profile->save()) {
                         print_r($profile->getErrors());
                         die;
                     }
                     $auth = new Auth(['user_id' => $user->id, 'source' => $client->getId(), 'source_id' => (string) $attributes['id']]);
                     if ($auth->save()) {
                         $transaction->commit();
                         Yii::$app->user->login($user);
                     } else {
                         print_r($auth->getErrors());
                     }
                 } else {
                     print_r($user->getErrors());
                 }
             }
         }
     } else {
         // user already logged in
         if (!$auth) {
             // add auth provider
             $auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $client->getId(), 'source_id' => $attributes['id']]);
             $auth->save();
         }
     }
 }
开发者ID:psych88,项目名称:fifa,代码行数:54,代码来源:SignupController.php


注:本文中的app\modules\user\models\User::generatePasswordResetToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。