Skip to content

Commit 02f156e

Browse files
committed
fix AdminCreateUserForm
1 parent d36aa52 commit 02f156e

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

routers/web/admin/users.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ func NewUser(ctx *context.Context) {
8282
ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
8383
ctx.Data["PageIsAdmin"] = true
8484
ctx.Data["PageIsAdminUsers"] = true
85-
ctx.Data["DefaultUserVisibilityMode"] = setting.Service.DefaultUserVisibilityMode
8685
ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice()
8786

88-
ctx.Data["login_type"] = "0-0"
87+
ctx.Data["Form"] = forms.AdminCreateUserForm{
88+
LoginType: "0-0",
89+
Visibility: setting.Service.DefaultUserVisibilityMode,
90+
}
8991

9092
sources, err := auth.Sources()
9193
if err != nil {
@@ -104,7 +106,7 @@ func NewUserPost(ctx *context.Context) {
104106
ctx.Data["Title"] = ctx.Tr("admin.users.new_account")
105107
ctx.Data["PageIsAdmin"] = true
106108
ctx.Data["PageIsAdminUsers"] = true
107-
ctx.Data["DefaultUserVisibilityMode"] = setting.Service.DefaultUserVisibilityMode
109+
ctx.Data["AllowedUserVisibilityModes"] = setting.Service.AllowedUserVisibilityModesSlice.ToVisibleTypeSlice()
108110

109111
sources, err := auth.Sources()
110112
if err != nil {

templates/admin/user/new.tmpl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class="inline required field {{if .Err_LoginType}}error{{end}}">
1515
<label>{{.locale.Tr "admin.users.auth_source"}}</label>
1616
<div class="ui selection type dropdown">
17-
<input type="hidden" id="login_type" name="login_type" value="{{.login_type}}" data-password="required" required>
17+
<input type="hidden" id="login_type" name="login_type" value="{{.Form.LoginType}}" data-password="required" required>
1818
<div class="text">{{.locale.Tr "admin.users.local"}}</div>
1919
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
2020
<div class="menu">
@@ -29,11 +29,11 @@
2929
<div class="inline field {{if .Err_Visibility}}error{{end}}">
3030
<span class="inline required field"><label for="visibility">{{.locale.Tr "settings.visibility"}}</label></span>
3131
<div class="ui selection type dropdown">
32-
<input type="hidden" id="visibility" name="visibility" value="{{if .visibility}}{{.visibility}}{{else}}{{printf "%d" .DefaultUserVisibilityMode}}{{end}}">
32+
<input type="hidden" id="visibility" name="visibility" value="{{.Form.Visibility}}">
3333
<div class="text">
34-
{{if .DefaultUserVisibilityMode.IsPublic}}{{.locale.Tr "settings.visibility.public"}}{{end}}
35-
{{if .DefaultUserVisibilityMode.IsLimited}}{{.locale.Tr "settings.visibility.limited"}}{{end}}
36-
{{if .DefaultUserVisibilityMode.IsPrivate}}{{.locale.Tr "settings.visibility.private"}}{{end}}
34+
{{if .Form.Visibility.IsPublic}}{{.locale.Tr "settings.visibility.public"}}{{end}}
35+
{{if .Form.Visibility.IsLimited}}{{.locale.Tr "settings.visibility.limited"}}{{end}}
36+
{{if .Form.Visibility.IsPrivate}}{{.locale.Tr "settings.visibility.private"}}{{end}}
3737
</div>
3838
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
3939
<div class="menu">
@@ -50,27 +50,27 @@
5050
</div>
5151
</div>
5252

53-
<div class="required non-local field {{if .Err_LoginName}}error{{end}} {{if eq .login_type "0-0"}}gt-hidden{{end}}">
53+
<div class="required non-local field {{if .Err_LoginName}}error{{end}} {{if eq .Form.LoginType "0-0"}}gt-hidden{{end}}">
5454
<label for="login_name">{{.locale.Tr "admin.users.auth_login_name"}}</label>
55-
<input id="login_name" name="login_name" value="{{.login_name}}">
55+
<input id="login_name" name="login_name" value="{{.Form.LoginName}}">
5656
</div>
5757
<div class="required field {{if .Err_UserName}}error{{end}}">
5858
<label for="user_name">{{.locale.Tr "username"}}</label>
59-
<input id="user_name" type="text" name="user_name" value="{{.user_name}}" autofocus required>
59+
<input id="user_name" type="text" name="user_name" value="{{.Form.UserName}}" autofocus required>
6060
</div>
6161
<div class="required field {{if .Err_Email}}error{{end}}">
6262
<label for="email">{{.locale.Tr "email"}}</label>
63-
<input id="email" name="email" type="email" value="{{.email}}" required>
63+
<input id="email" name="email" type="email" value="{{.Form.Email}}" required>
6464
</div>
65-
<div class="required local field {{if .Err_Password}}error{{end}} {{if not (eq .login_type "0-0")}}gt-hidden{{end}}">
65+
<div class="required local field {{if .Err_Password}}error{{end}} {{if not (eq .Form.LoginType "0-0")}}gt-hidden{{end}}">
6666
<label for="password">{{.locale.Tr "password"}}</label>
67-
<input id="password" name="password" type="password" autocomplete="new-password" value="{{.password}}" {{if eq .login_type "0-0"}}required{{end}}>
67+
<input id="password" name="password" type="password" autocomplete="new-password" value="{{.Form.Password}}" {{if eq .Form.LoginType "0-0"}}required{{end}}>
6868
</div>
6969

70-
<div class="inline field local {{if ne .login_type "0-0"}}gt-hidden{{end}}">
70+
<div class="inline field local {{if ne .Form.LoginType "0-0"}}gt-hidden{{end}}">
7171
<div class="ui checkbox">
7272
<label><strong>{{.locale.Tr "auth.allow_password_change"}}</strong></label>
73-
<input name="must_change_password" type="checkbox" checked>
73+
<input name="must_change_password" type="checkbox" {{if .Form.MustChangePassword}}checked{{end}}>
7474
</div>
7575
</div>
7676

@@ -79,7 +79,7 @@
7979
<div class="inline field">
8080
<div class="ui checkbox">
8181
<label><strong>{{.locale.Tr "admin.users.send_register_notify"}}</strong></label>
82-
<input name="send_notify" type="checkbox" {{if .send_notify}}checked{{end}}>
82+
<input name="send_notify" type="checkbox" {{if .Form.SendNotify}}checked{{end}}>
8383
</div>
8484
</div>
8585
{{end}}

0 commit comments

Comments
 (0)