/**
  * @param bool $performValidation
  *
  * @return bool
  */
 public function sendEmail($performValidation = true)
 {
     if ($performValidation and !$this->validate()) {
         return false;
     }
     $this->user->generateConfirmationToken();
     $this->user->save(false);
     return Yii::$app->mailer->compose(Yii::$app->getModule('user-management')->mailerOptions['passwordRecoveryFormViewFile'], ['user' => $this->user])->setFrom(Yii::$app->getModule('user-management')->mailerOptions['from'])->setTo($this->email)->setSubject(UserManagementModule::t('front', 'Password reset for') . ' ' . Yii::$app->name)->send();
 }
예제 #2
0
 /**
  * @param bool $performValidation
  *
  * @return bool
  */
 public function changePassword($performValidation = true)
 {
     if ($performValidation and !$this->validate()) {
         return false;
     }
     $this->user->password = $this->password;
     $this->user->removeConfirmationToken();
     return $this->user->save();
 }
 /**
  * @param bool $performValidation
  *
  * @return bool|User
  */
 public function registerUser($performValidation = true)
 {
     if ($performValidation and !$this->validate()) {
         return false;
     }
     $user = new User();
     $user->password = $this->password;
     if (Yii::$app->getModule(\Yii::$app->user->moduleAliasName)->useEmailAsLogin) {
         $user->email = $this->username;
         // If email confirmation required then we save user with "inactive" status
         // and without username (username will be filled with email value after confirmation)
         if (Yii::$app->getModule(\Yii::$app->user->moduleAliasName)->emailConfirmationRequired) {
             $user->status = User::STATUS_INACTIVE;
             $user->generateConfirmationToken();
             $user->save(false);
             $this->saveProfile($user);
             if ($this->sendConfirmationEmail($user)) {
                 return $user;
             } else {
                 $this->addError('username', UserManagementModule::t('front', 'Could not send confirmation email'));
             }
         } else {
             $user->username = $this->username;
         }
     } else {
         $user->username = $this->username;
     }
     if ($user->save()) {
         $this->saveProfile($user);
         return $user;
     } else {
         $this->addError('username', UserManagementModule::t('front', 'Login has been taken'));
     }
 }
예제 #4
0
 /**
  * @return mixed|string|\yii\web\Response
  */
 public function actionCreate()
 {
     $model = new User(['scenario' => 'newUser']);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->renderIsAjax('create', compact('model'));
 }
 public function safeUp()
 {
     $user = new User();
     $user->superadmin = 1;
     $user->status = User::STATUS_ACTIVE;
     $user->username = '******';
     $user->password = '******';
     $user->save(false);
 }