generatePasswordResetToken() public method

Generates new password reset token
 public function generateToken()
 {
     $mobile = $this->_session['passwordResetMobile'];
     $this->_user = User::findByMobile($mobile);
     if (!User::isPasswordResetTokenValid($this->_user->password_reset_token)) {
         $this->_user->generatePasswordResetToken();
     }
     return $this->_user->save(false);
 }
示例#2
0
 public function actionInit()
 {
     //$auth = Yii::$app->authManager;
     $user = new User();
     $user->username = "******";
     $user->email = "*****@*****.**";
     $user->status = 10;
     $user->setPassword("abc@1234");
     $user->generatePasswordResetToken();
     $user->generateAuthKey();
     $user->save();
 }
示例#3
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     $model->setScenario('create_user');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $model->generatePasswordResetToken();
         $model->save(false);
         return $this->redirect(['view', 'id' => $model->id]);
     }
     $model->status = User::STATUS_ACTIVE;
     $model->group = User::GROUP_READER;
     return $this->render('create', ['model' => $model]);
 }
示例#4
0
 public function insert(UserDto $userDto)
 {
     $user = new User();
     $qUserDto = new UserDto();
     $qUserDto->setScenario('admin-query');
     if ($user->load(['User' => ArrayHelper::toArray($userDto)])) {
         $user->setPassword($userDto->password);
         $user->generateAuthKey();
         $user->generatePasswordResetToken();
         $user->insert();
         return ArrayHelper::toArray($user, ['common\\models\\User' => $qUserDto->activeAttributes()]);
     } else {
         return [];
     }
 }
示例#5
0
 public function successCallback($client)
 {
     $attributes = $client->getUserAttributes();
     /** @var Auth $auth */
     $auth = Auth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one();
     $attributes['login'] = $attributes['login'] ? $attributes['login'] : $attributes['last_name'] . ' ' . $attributes['first_name'];
     if (Yii::$app->user->isGuest) {
         if ($auth) {
             // login
             $user = $auth->user;
             $user->username = $attributes['login'];
             $user->photo = $attributes['photo'];
             $user->save();
             Yii::$app->user->login($user);
         } else {
             // signup
             if (isset($attributes['email']) && isset($attributes['username']) && 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 {
                 $user = new User(['username' => $attributes['login'], 'email' => $attributes['email'], 'first_name' => $attributes['first_name'], 'last_name' => $attributes['last_name'], 'sex' => $attributes['sex'], 'photo' => $attributes['photo'], 'password' => Yii::$app->security->generateRandomString(6)]);
                 $user->generateAuthKey();
                 $user->generatePasswordResetToken();
                 $transaction = $user->getDb()->beginTransaction();
                 if ($user->save()) {
                     $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();
         }
     }
 }
 public function safeUp()
 {
     $this->alterColumn('{{user}}', 'email', 'drop not null');
     $auth = Yii::$app->authManager;
     // создание разрешения на все
     $permission = $auth->createPermission($this->permissionName);
     $permission->description = 'Доступ ко всем функциям системы';
     $auth->add($permission);
     // создание роли супер администратора
     $role = $auth->createRole($this->roleName);
     $role->description = 'Супер администратор';
     $auth->add($role);
     $auth->addChild($role, $permission);
     $user = new common\models\User();
     $user->username = $this->userLogin;
     $user->setPassword($this->userPassword);
     $user->generateAuthKey();
     $user->generatePasswordResetToken();
     $user->save();
     $auth->assign($role, $user->id);
 }
 /**
  * Loads attributes to the user model. You should override this method if you are going to add new fields to the
  * registration form. You can read more in special guide.
  *
  * By default this method set all attributes of this model to the attributes of User model, so you should properly
  * configure safe attributes of your User model.
  *
  * @param User $user
  */
 protected function loadAttributes(\common\models\User $user)
 {
     $user->setAttributes($this->attributes);
     $user->generatePasswordResetToken();
     $user->is_provider = 0;
     $user->registered_by();
     $user->generateInviteHash();
     $user->generatePhoneVerificationHash();
     $user->generateRoleCode();
     $user->created_at = time();
     $user->updated_at = time();
     $user->status = 20;
 }
示例#8
0
 /**
  * Logs in a user.
  *
  * @return mixed
  */
 public function onAuthSuccess($client)
 {
     $data = Yii::$app->getRequest()->getQueryParam("auth_key");
     if (!$this->getInviteKey($data)) {
         Yii::$app->session->setFlash("error", "Not have permision");
         return $this->redirect(["/"]);
     }
     $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) {
             $user = $auth->user;
             Yii::$app->user->login($user);
             return $this->redirect("site/user");
         } else {
             // signup
             $email = isset($attributes['email']) ? $attributes['email'] : "";
             $invite = Invitation::find()->where(['send_key' => $data, 'email' => $email])->one();
             if (isset($attributes['name']) && !empty($invite)) {
                 $password = Yii::$app->security->generateRandomString(8);
                 if (!isset($attributes['email'])) {
                     $attributes['email'] = '';
                 }
                 $fileName = null;
                 $picturePath = null;
                 if (isset($attributes['picture']) && isset($attributes['picture']['data']) && isset($attributes['picture']['data']['url'])) {
                     $picturePath = $attributes['picture']['data']['url'];
                 } elseif (isset($attributes['profile_image_url'])) {
                     $picturePath = $attributes['profile_image_url'];
                 }
                 // COMMENT: ADD PHOTO FROM FACEBOOK DATA TO DATABASE method file_put_contents - http://php.net/manual/ru/function.file-put-contents.php
                 if ($picturePath) {
                     $photoFile = file_get_contents($picturePath);
                     $security = new \yii\base\Security();
                     $fileName = $security->generateRandomString() . '.jpg';
                     $directory = Yii::getAlias('@frontend/web/' . Yii::$app->params['user-photos-directory']);
                     file_put_contents($directory . DIRECTORY_SEPARATOR . $fileName, $photoFile);
                 }
                 $user = new User(['username' => $attributes['name'], 'email' => $attributes['email'], 'password' => $password, 'image' => $fileName, 'sex' => !empty($attributes['gender']) ? $attributes['gender'] : "", 'country' => !empty($attributes['hometown']['name']) ? $attributes['hometown']['name'] : "", 'created_at' => time(), 'updated_at' => time()]);
                 $user->generateAuthKey();
                 $user->generatePasswordResetToken();
                 $transaction = $user->getDb()->beginTransaction();
                 if ($user->save()) {
                     $auth = new Auth(['user_id' => $user->id, 'source' => $client->getId(), 'source_id' => (string) $attributes['id'], 'email' => $attributes['email']]);
                     $invite->status = Invitation::STATUS_SIGNUP;
                     $invite->save();
                     if ($auth->save()) {
                         $transaction->commit();
                         Yii::$app->user->login($user);
                         return $this->redirect(["/"]);
                     } else {
                         print_r($auth->getErrors());
                     }
                 } else {
                     print_r($user->getErrors());
                 }
             } else {
                 Yii::$app->session->setFlash("error", "Email not equals");
                 return $this->redirect(['site/invite', 'auth_key' => $data]);
             }
         }
     } 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();
         }
     }
 }