コード例 #1
0
 /**
  * Resets password.
  *
  * @return boolean if password was reset.
  */
 public function resetPassword()
 {
     $user = $this->_user;
     $user->password = $this->password;
     $user->scenario = 'resetPass';
     $user->auth_key = User::generateNewAuthKey();
     $user->password_hash = User::setNewPassword($this->password);
     $user->removePasswordResetToken();
     //echo "<pre>";print_r($user);die;   //Here we need to make a password hash string and then we will save ,,but pending due to wait for upload(as password mail will be sending only when site is live)
     return $user->save();
 }
コード例 #2
0
 /**
  * To show the Change Password for the currently logged in user
  * @return : view for the change password (For the currently logged in user)
  */
 public function actionChangePassword()
 {
     if (!Yii::$app->user->isGuest) {
         $model = Yii::$app->user->getIdentity();
         $model->scenario = 'changePassword';
         if ($model->load(Yii::$app->request->post())) {
             if ($model->validate()) {
                 $model->auth_key = User::generateNewAuthKey();
                 $model->password_hash = User::setNewPassword($model->password);
                 if ($model->update()) {
                     if (SEND_PASSWORD_CHANGE_MAIL) {
                         User::sendMail('change-password-email', $model, $model->email, 'Password changed for - ' . SITE_NAME);
                     }
                     Yii::$app->session->setFlash('success', FLASH_1020, true);
                     return $this->redirect(Url::to(['/usermgmt/user/logout']));
                 } else {
                     Yii::$app->session->setFlash('danger', FLASH_1021, true);
                 }
             }
             //$model->errors;
         }
         return $this->render('change-password', ['model' => $model]);
     } else {
         $this->goHome();
     }
 }
コード例 #3
0
ファイル: User.php プロジェクト: pranjalcodefire/yii-usermgmt
 public function register()
 {
     if (NEW_REGISTRATION_IS_ALLOWED) {
         $modelDetail = new UserDetail();
         $model = new User();
         $model->scenario = 'addUser';
         if ($model->load(Yii::$app->request->post())) {
             $file = \yii\web\UploadedFile::getInstance($model, 'img_path');
             if (isset($file) && !empty($file)) {
                 $filePath = USER_DIRECTORY_PATH . DS . USER_PROFILE_IMAGES_DIRECTORY . DS;
                 $model->img_path = Yii::$app->custom->uploadFile($file, $filePath);
             }
             if ($model->validate()) {
                 $model->auth_key = User::generateNewAuthKey();
                 $model->password_hash = User::setNewPassword($model->password);
                 if (isset($model->phone_number)) {
                     $model->phone_number = str_replace("-", "", $model->phone_number);
                 }
                 if (isset($model->dob)) {
                     $model->dob = date("Y-m-d", strtotime($model->dob));
                 }
                 if ($model->save(false)) {
                     /** Associated Model linking ***/
                     $modelDetail->user_id = $model->id;
                     $model->link("userDetail", $modelDetail);
                     $userGroups = RoleAndPermission::find()->onCondition(['type' => '1'])->asArray()->all();
                     $roleNames = [];
                     foreach ($userGroups as $userGroup) {
                         $roleNames[] = $userGroup['name'];
                     }
                     if (in_array(DEFAULT_ROLE_NAME, $roleNames)) {
                         $userRole = new AuthAssignment();
                         $userRole->item_name = DEFAULT_ROLE_NAME;
                         $userRole->user_id = $model->id;
                     }
                     $model->link("userRole", $userRole);
                     /** Associated Model linking ***/
                     if ($model->save(false)) {
                         if (!SEND_REGISTRATION_MAIL) {
                             User::sendMail('welcome-email', $model, $model->email, 'Welcome to - ' . SITE_NAME);
                         }
                         Yii::$app->session->setFlash('success', 'Please verify your Email. A verification link has been sent to your Email Address.');
                         return array('redirect' => true, 'url' => Url::to(['/usermgmt/user/login']));
                     } else {
                         Yii::$app->session->setFlash('success', 'Your registration was not successful.');
                         return array('redirect' => true, 'url' => Yii::$app->homeUrl);
                     }
                 }
             }
         }
         return array('render' => "register", 'model' => $model);
     } else {
         Yii::$app->session->setFlash('danger', 'Currently new registrations are not allowed by administrator. Please try later.');
         return array('redirect' => true, 'url' => Yii::$app->homeUrl);
     }
 }