fix user update screen in backend
This commit is contained in:
parent
ccc50457d3
commit
c191ce6c7d
@ -11,7 +11,7 @@ class UserUpdate extends User {
|
||||
public $selected_accounts = [];
|
||||
|
||||
public $role;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @formatter:off
|
||||
@ -21,10 +21,12 @@ class UserUpdate extends User {
|
||||
return [
|
||||
[['username','email'], 'required' ],
|
||||
['email' ,'email' ],
|
||||
['email' ,'unique' , 'targetClass' => User::className(), 'targetAttribute' => 'email'],
|
||||
['username' ,'unique', 'targetClass' => User::className(), 'targetAttribute' => 'username'],
|
||||
// ['email' ,'unique' , 'targetClass' => User::className(), 'targetAttribute' => 'email'],
|
||||
// ['username' ,'unique', 'targetClass' => User::className(), 'targetAttribute' => 'username'],
|
||||
[['password_plain' ,'password_repeat'] ,'string','min' =>6 ],
|
||||
[['password_repeat'] ,'validatePasswordRepeat' ],
|
||||
[['username'] ,'validateUsername' ],
|
||||
[['email'] ,'validateEmail' ],
|
||||
['selected_accounts',function ($attribute, $params) {
|
||||
if (!is_array($this->$attribute)) {
|
||||
$this->addError($attribute, 'Invalid array');
|
||||
@ -33,13 +35,13 @@ class UserUpdate extends User {
|
||||
],
|
||||
[['role'], 'required'],
|
||||
[['role'], 'string', 'max' => 20],
|
||||
|
||||
|
||||
['status', 'default', 'value' => self::STATUS_ACTIVE],
|
||||
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @formatter:on
|
||||
*/
|
||||
@ -52,15 +54,37 @@ class UserUpdate extends User {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function validateEmail($attribute, $params) {
|
||||
if (! $this->hasErrors ()) {
|
||||
if ( !empty($this->email) ){
|
||||
$user = User::findOne(['email' => $this->email]);
|
||||
if ( isset($user) && $user->id != $this->id){
|
||||
$this->addError ( $attribute, "Az email már használatban van (".$user->username.")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function validateUsername($attribute, $params) {
|
||||
if (! $this->hasErrors ()) {
|
||||
if ( !empty($this->email) ){
|
||||
$user = User::findOne(['username' => $this->username]);
|
||||
if ( isset($user) && $user->id != $this->id){
|
||||
$this->addError ( $attribute, "A felhasználónév már használatban van (".$user->username.")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function attributeLabels() {
|
||||
return [
|
||||
|
||||
return [
|
||||
|
||||
'status' => 'Státusz',
|
||||
'email' => 'E-mail',
|
||||
'username' => 'Felhasználónév',
|
||||
'created_at' => 'Létrehozás dátuma',
|
||||
'password_plain' => Yii::t ( 'app', 'Jelszó' ),
|
||||
'password_repeat' => Yii::t ( 'app', 'Jelszó újra' )
|
||||
'password_repeat' => Yii::t ( 'app', 'Jelszó újra' )
|
||||
]
|
||||
;
|
||||
}
|
||||
@ -78,7 +102,7 @@ class UserUpdate extends User {
|
||||
}
|
||||
}
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
parent::afterSave($insert, $changedAttributes);
|
||||
parent::afterSave($insert, $changedAttributes);
|
||||
$am = Yii::$app->authManager;
|
||||
$am->revokeAll($this->id);
|
||||
$role = $am->getRole($this->role);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user