Commit 4f37eeabe80d37b897fd7c125233c4f4016b6af0
1 parent
a1f2032a
Exists in
master
app-ht
1. F 创建账号的时候做用户名校验
Showing
2 changed files
with
20 additions
and
8 deletions
Show diff stats
app-ht/config/main.php
... | ... | @@ -91,18 +91,12 @@ $config = [ |
91 | 91 | 'site/index', |
92 | 92 | 'site/region', |
93 | 93 | 'site/editor-upload', |
94 | - 'site/ajax-item-top', | |
95 | - 'site/ajax-member-top', | |
96 | - 'site/ajax-instant', | |
97 | - 'site/ajax-wares-tab', | |
98 | - 'site/ajax-member-chart', | |
94 | + | |
99 | 95 | 'my/default/index', // 个人中心登陆即可 |
100 | 96 | 'my/default/do-update', |
101 | 97 | 'my/default/password', |
102 | 98 | 'my/default/do-password', |
103 | - 'device/index', | |
104 | - 'device/index/index', | |
105 | - 'test/index', | |
99 | + 'dashboard/index', | |
106 | 100 | ] |
107 | 101 | ], |
108 | 102 | ... | ... |
app-ht/modules/system/controllers/AccountController.php
... | ... | @@ -120,6 +120,14 @@ class AccountController extends BaseController |
120 | 120 | $mobile = isset($post['mobile']) ? $post['mobile'] : ''; |
121 | 121 | $is_enable = isset($post['is_enable']) ? 1 : 0; |
122 | 122 | |
123 | + if ('' == $username || !(preg_match("/^[0-9a-zA-Z]{6,10}$/", $username))) { | |
124 | + Yii::$app->session->setFlash('danger', '用户名不能是空格,并且必须是6~12位的英文或数字'); | |
125 | + return $this->redirect(['/system/account/create']); | |
126 | + } | |
127 | + if ('' == $realname) { | |
128 | + Yii::$app->session->setFlash('danger', '名称不能是空格'); | |
129 | + return $this->redirect(['/system/account/create']); | |
130 | + } | |
123 | 131 | // 用户名不允许有冒号 |
124 | 132 | if (strpos($username, ':') !== false) { |
125 | 133 | Yii::$app->session->setFlash('danger', '用户名不能包含冒号,请重新输入'); |
... | ... | @@ -197,7 +205,17 @@ class AccountController extends BaseController |
197 | 205 | $is_enable = isset($post['is_enable']) ? 1 : 0; |
198 | 206 | |
199 | 207 | $model = $this->findModel($id); |
208 | + $username = trim($username); | |
209 | + $realname = trim($realname); | |
200 | 210 | |
211 | + if ('' == $username || !(preg_match("/^[0-9a-zA-Z]{6,10}$/", $username))) { | |
212 | + Yii::$app->session->setFlash('danger', '用户名不能是空格,并且必须是6~12位的英文或数字'); | |
213 | + return $this->redirect(['/system/account/update', 'id' => $model->id]); | |
214 | + } | |
215 | + if ('' == $realname) { | |
216 | + Yii::$app->session->setFlash('danger', '名称不能是空格'); | |
217 | + return $this->redirect(['/system/account/update', 'id' => $model->id]); | |
218 | + } | |
201 | 219 | // 用户名不允许有冒号 |
202 | 220 | if (strpos($username, ':') !== false) { |
203 | 221 | Yii::$app->session->setFlash('danger', '用户名不能包含冒号,请重新输入'); | ... | ... |