コード例 #1
0
ファイル: User.php プロジェクト: vladim1/yii2-user
 /**
  * @inheritdoc
  */
 public function scenarios()
 {
     $scenarios = parent::scenarios();
     $scenarios[Module::SCN_ACTIVATE] = ['status'];
     $scenarios[Module::SCN_REGISTER] = ['username', 'password', 'email', 'captcha', 'status'];
     $scenarios[Module::SCN_RESET] = ['password_new', 'password_confirm'];
     $scenarios[Module::SCN_CHANGEPASS] = ['password', 'password_new', 'password_confirm'];
     $scenarios[Module::SCN_INSTALL] = ['username', 'password', 'email', 'status'];
     $scenarios[Module::SCN_NEWEMAIL] = ['password'];
     $scenarios[Module::SCN_RECOVERY] = ['reset_key'];
     $m = $this->_module;
     $settings = [];
     // for admin user and superuser
     $editSettings = $m->getEditSettingsAdmin($this);
     if (is_array($editSettings)) {
         if ($editSettings['changeUsername']) {
             $settings[] = 'username';
         }
         if ($editSettings['changeEmail']) {
             $settings[] = 'email';
         }
     } elseif ($editSettings === true) {
         $settings = ['username', 'email'];
     }
     if (!empty($settings)) {
         $scenarios[Module::SCN_ADMIN] = ['status'] + $settings;
     }
     $currUser = Yii::$app->user;
     if ($currUser->isSuperuser || $currUser->isAdmin) {
         $settings = $currUser->isSuperuser ? $m->superuserEditSettings : $m->adminEditSettings;
         if (is_array($settings) && $settings['createUser']) {
             $scenarios[Module::SCN_ADMIN_CREATE] = ['username', 'password', 'email', 'status'];
         }
     }
     // for normal user
     $settings = ['email_new', 'email_change_key'];
     $editSettings = $m->getEditSettingsUser($this);
     if (is_array($editSettings)) {
         if ($editSettings['changeUsername']) {
             $settings[] = 'username';
         }
         if ($editSettings['changeEmail']) {
             $settings[] = 'email';
         }
     }
     if (!empty($settings)) {
         $scenarios[Module::SCN_PROFILE] = $settings;
     }
     return $scenarios;
 }
コード例 #2
0
ファイル: UserProfile.php プロジェクト: communityii/yii2-user
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $this->_genders = [self::G_MALE => Yii::t('user', 'Male'), self::G_FEMALE => Yii::t('user', 'Female'), self::G_OTHER => Yii::t('user', 'Other')];
     $this->_genderClasses = [self::G_MALE => 'text-info', self::G_FEMALE => 'text-danger', self::G_OTHER => 'text-muted'];
 }