Showing
2 changed files
with
23 additions
and
2 deletions
@@ -24,6 +24,27 @@ class AdminController extends BaseController | @@ -24,6 +24,27 @@ class AdminController extends BaseController | ||
24 | */ | 24 | */ |
25 | public function actionList() | 25 | public function actionList() |
26 | { | 26 | { |
27 | + if (Yii::$app->request->isPost){ | ||
28 | + $model = new Admin; | ||
29 | + $model->username = Yii::$app->request->post('username'); | ||
30 | + $model->email = Yii::$app->request->post('email'); | ||
31 | + $model->setPassword(Yii::$app->request->post('password')); | ||
32 | + $model->generateAuthKey(); | ||
33 | + $model->generatePasswordResetToken(); | ||
34 | + | ||
35 | + if ($model->save()){ | ||
36 | + if (($roleName = Yii::$app->request->post('role')) && ($role = $this->authManager->getRole($roleName))){ | ||
37 | + if (!$this->authManager->assign($role,$model->getId())){ | ||
38 | + Yii::$app->session->setFlash('error', '分配用户组失败。'); | ||
39 | + } | ||
40 | + } | ||
41 | + Yii::$app->session->setFlash('success', '加入成功。'); | ||
42 | + }else{ | ||
43 | + //Yii::$app->session->setFlash('error', '加入失败。'); | ||
44 | + Yii::$app->session->setFlash('warning', current($model->getFirstErrors())); | ||
45 | + } | ||
46 | + } | ||
47 | + | ||
27 | $list = Admin::find()->all(); | 48 | $list = Admin::find()->all(); |
28 | 49 | ||
29 | //所有权限 | 50 | //所有权限 |
@@ -40,12 +40,12 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) | @@ -40,12 +40,12 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) | ||
40 | <input type="password" name="password" class="form-control" required="required" placeholder="密码"> | 40 | <input type="password" name="password" class="form-control" required="required" placeholder="密码"> |
41 | </div> | 41 | </div> |
42 | <div class="col-sm-5"> | 42 | <div class="col-sm-5"> |
43 | - <?php echo Html::dropDownList('role', null,$roles, ['class' => 'width300 select-basic', 'required'=>"required"]);?> | 43 | + <?php echo Html::dropDownList('role', null,$roles, ['class' => 'width300 select-basic']);?> |
44 | </div> | 44 | </div> |
45 | </div> | 45 | </div> |
46 | <div class="form-group"> | 46 | <div class="form-group"> |
47 | <div class="col-sm-3"> | 47 | <div class="col-sm-3"> |
48 | - <button class="btn btn-primary mr5" id="upload_button">加入</button> | 48 | + <button class="btn btn-primary mr5" id="upload_button" onclick="return confirm('确定加入?')">加入</button> |
49 | </div> | 49 | </div> |
50 | </div> | 50 | </div> |
51 | </div><!-- row --> | 51 | </div><!-- row --> |
-
Please register or login to post a comment