add role to user
This commit is contained in:
@@ -10,6 +10,8 @@ class UserCreate extends User{
|
||||
public $password_repeat;
|
||||
public $selected_accounts = [];
|
||||
|
||||
public $role;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -28,6 +30,9 @@ class UserCreate extends User{
|
||||
['username' ,'unique' ],
|
||||
[['password_plain' ,'password_repeat'] ,'string','min' =>6 ],
|
||||
[['password_repeat'] ,'validatePasswordRepeat' ],
|
||||
|
||||
[['role'], 'required'],
|
||||
[['role'], 'string', 'max' => 20],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -66,9 +71,9 @@ class UserCreate extends User{
|
||||
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
parent::afterSave($insert, $changedAttributes);
|
||||
// $am = Yii::$app->authManager;
|
||||
// $role = $am->getRole('admin');
|
||||
// Yii::$app->authManager->assign($role, $this->id);
|
||||
$am = Yii::$app->authManager;
|
||||
$role = $am->getRole($this->role);
|
||||
Yii::$app->authManager->assign($role, $this->id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user