Authored by wuxiao

后台用户添加

... ... @@ -24,6 +24,27 @@ class AdminController extends BaseController
*/
public function actionList()
{
if (Yii::$app->request->isPost){
$model = new Admin;
$model->username = Yii::$app->request->post('username');
$model->email = Yii::$app->request->post('email');
$model->setPassword(Yii::$app->request->post('password'));
$model->generateAuthKey();
$model->generatePasswordResetToken();
if ($model->save()){
if (($roleName = Yii::$app->request->post('role')) && ($role = $this->authManager->getRole($roleName))){
if (!$this->authManager->assign($role,$model->getId())){
Yii::$app->session->setFlash('error', '分配用户组失败。');
}
}
Yii::$app->session->setFlash('success', '加入成功。');
}else{
//Yii::$app->session->setFlash('error', '加入失败。');
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
}
}
$list = Admin::find()->all();
//所有权限
... ...
... ... @@ -40,12 +40,12 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
<input type="password" name="password" class="form-control" required="required" placeholder="密码">
</div>
<div class="col-sm-5">
<?php echo Html::dropDownList('role', null,$roles, ['class' => 'width300 select-basic', 'required'=>"required"]);?>
<?php echo Html::dropDownList('role', null,$roles, ['class' => 'width300 select-basic']);?>
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<button class="btn btn-primary mr5" id="upload_button">加入</button>
<button class="btn btn-primary mr5" id="upload_button" onclick="return confirm('确定加入?')">加入</button>
</div>
</div>
</div><!-- row -->
... ...