add role to user
This commit is contained in:
@@ -9,6 +9,8 @@ class UserUpdate extends User {
|
||||
public $password_plain;
|
||||
public $password_repeat;
|
||||
public $selected_accounts = [];
|
||||
|
||||
public $role;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -28,7 +30,9 @@ class UserUpdate extends User {
|
||||
$this->addError($attribute, 'Invalid array');
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
[['role'], 'required'],
|
||||
[['role'], 'string', 'max' => 20],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -68,10 +72,11 @@ class UserUpdate extends User {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function afterSave($insert, $changedAttributes) {
|
||||
parent::afterSave ( $insert, $changedAttributes );
|
||||
// $am = Yii::$app->authManager;
|
||||
// $role = $am->getRole('admin');
|
||||
// Yii::$app->authManager->assign($role, $this->id);
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
parent::afterSave($insert, $changedAttributes);
|
||||
$am = Yii::$app->authManager;
|
||||
$am->revokeAll($this->id);
|
||||
$role = $am->getRole($this->role);
|
||||
Yii::$app->authManager->assign($role, $this->id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user