コード例 #1
0
 /**
  * User Account Verification
  * Module permission check requires either user-admin or user-group-admin
  * priviliges to continue.
  * @return mixed
  * @param type $id
  * @return type
  */
 public function actionVerify($id, $alt = FALSE)
 {
     $identityClass = \Yii::$app->user->identityClass;
     $user = $identityClass::findOne(['id' => $id]);
     if (isset($user)) {
         if ($user->status == 0) {
             $user->status = 10;
             $model = new \humanized\user\models\notifications\AccountActivationConfirmation();
             if (isset($id) ? $model->loadMail($id) : $model->load(\Yii::$app->request->post()) && $model->validate()) {
                 $model->sendEmail();
             }
         } else {
             $user->status = 0;
         }
         $user->save(false);
     }
     if ($alt == TRUE) {
         return $this->redirect(['account/index', 'id' => $id]);
     }
     return $this->redirect(['index']);
 }
コード例 #2
0
ファイル: User.php プロジェクト: Humanized/yii2-user
 /**
  * Extra steps are taken in scenarios where user account password are handled
  * 
  * 
  * @return type
  */
 public function afterSave($insert, $changedAttributes)
 {
     if ($insert) {
         if ($this->status == self::STATUS_INACTIVE && $this->_module->params['enableAdminVerification'] == TRUE) {
             $model = new AccountActivationRequest(['email' => $this->email]);
             if (!($model->validate() && $model->sendEmail())) {
                 return false;
             }
         }
         //Either password is generated automatically without admin account verification enabled
         $cond1 = $this->generatePassword && !$this->_module->params['enableAdminVerification'];
         //Or the status has changed from inactive to active
         $cond2 = isset($changedAttributes['status']) && $this->status != 0;
         //Send email for account verification by user
         if ($cond1 || $cond2) {
             $model = new AccountActivationConfirmation(['email' => $this->email]);
             if (!($model->validate() && $model->sendEmail())) {
                 return false;
             }
             if ($cond2) {
             }
         }
     }
     if ($this->_module->params['enableRBAC']) {
         $this->_saveRoles($insert);
     }
     //Status is false and pending admin verification
     return parent::afterSave($insert, $changedAttributes);
 }