Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持用户名中出现 . _ - 这些常用的字符 #352

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/modules/system/controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/astaxie/beego/validation"
"github.com/phachon/mm-wiki/app/models"
"github.com/phachon/mm-wiki/app/utils"
"regexp"
"strings"
)

Expand Down Expand Up @@ -52,7 +53,7 @@ func (this *UserController) Save() {
if username == "" {
this.jsonError("用户名不能为空!")
}
if !v.AlphaNumeric(username, "username").Ok {
if !v.Match(username, regexp.MustCompile(`^[a-zA-Z0-9\.\-\_]+$`), "match").Ok {
this.jsonError("用户名格式不正确!")
}
if givenName == "" {
Expand Down
2 changes: 1 addition & 1 deletion views/system/user/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<input type="text" name="username" class="form-control" placeholder="请输入用户名" value="">
</div>
<div class="col-sm-3 form-comment">
<span class="text-danger"> * 只能由数字和字母组成</span>
<span class="text-danger"> * 只能由数字字母及 . _ - 组成</span>
</div>
</div>
<div class="form-group">
Expand Down