Skip to content

Commit

Permalink
Fix new user form for non-local users (go-gitea#8826)
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks committed Nov 4, 2019
1 parent 1c65ecc commit a7e76ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions routers/admin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
}

u := &models.User{
Name: form.UserName,
Email: form.Email,
Passwd: form.Password,
IsActive: true,
LoginType: models.LoginPlain,
MustChangePassword: form.MustChangePassword,
Name: form.UserName,
Email: form.Email,
Passwd: form.Password,
IsActive: true,
LoginType: models.LoginPlain,
}

if len(form.LoginType) > 0 {
Expand All @@ -95,9 +94,12 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
u.LoginName = form.LoginName
}
}
if !password.IsComplexEnough(form.Password) {
ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserNew, &form)
return
if u.LoginType == models.LoginPlain {
if !password.IsComplexEnough(form.Password) {
ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserNew, &form)
return
}
u.MustChangePassword = form.MustChangePassword
}
if err := models.CreateUser(u); err != nil {
switch {
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/user/new.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<input id="password" name="password" type="password" value="{{.password}}" {{if eq .login_type "0-0"}}required{{end}}>
</div>

<div class="inline field">
<div class="inline field local{{if ne .login_type "0-0"}} hide{{end}}">
<div class="ui checkbox">
<label><strong>{{.i18n.Tr "auth.allow_password_change" }}</strong></label>
<input name="must_change_password" type="checkbox" checked>
Expand Down

0 comments on commit a7e76ae

Please sign in to comment.