Skip to content

Commit 8d5c3d3

Browse files
authored
Install page - Handle invalid administrator username better (#7060) (#7063)
* Install page - detect invalid admin username before installing * Also fix #6954
1 parent 706d85b commit 8d5c3d3

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

options/locale/locale_en-US.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ sqlite_helper = File path for the SQLite3 database.<br>Enter an absolute path if
9393
err_empty_db_path = The SQLite3 database path cannot be empty.
9494
no_admin_and_disable_registration = You cannot disable user self-registration without creating an administrator account.
9595
err_empty_admin_password = The administrator password cannot be empty.
96+
err_empty_admin_email = The administrator email cannot be empty.
97+
err_admin_name_is_reserved = Administrator Username is invalid, username is reserved
98+
err_admin_name_pattern_not_allowed = Administrator Username is invalid, username is pattern is not allowed
99+
err_admin_name_is_invalid = Administrator Username is invalid
96100

97101
general_title = General Settings
98102
app_name = Site Title

routers/install.go

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,18 +213,42 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) {
213213
return
214214
}
215215

216-
// Check admin password.
217-
if len(form.AdminName) > 0 && len(form.AdminPasswd) == 0 {
218-
ctx.Data["Err_Admin"] = true
219-
ctx.Data["Err_AdminPasswd"] = true
220-
ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_password"), tplInstall, form)
221-
return
222-
}
223-
if form.AdminPasswd != form.AdminConfirmPasswd {
224-
ctx.Data["Err_Admin"] = true
225-
ctx.Data["Err_AdminPasswd"] = true
226-
ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplInstall, form)
227-
return
216+
// Check admin user creation
217+
if len(form.AdminName) > 0 {
218+
// Ensure AdminName is valid
219+
if err := models.IsUsableUsername(form.AdminName); err != nil {
220+
ctx.Data["Err_Admin"] = true
221+
ctx.Data["Err_AdminName"] = true
222+
if models.IsErrNameReserved(err) {
223+
ctx.RenderWithErr(ctx.Tr("install.err_admin_name_is_reserved"), tplInstall, form)
224+
return
225+
} else if models.IsErrNamePatternNotAllowed(err) {
226+
ctx.RenderWithErr(ctx.Tr("install.err_admin_name_pattern_not_allowed"), tplInstall, form)
227+
return
228+
}
229+
ctx.RenderWithErr(ctx.Tr("install.err_admin_name_is_invalid"), tplInstall, form)
230+
return
231+
}
232+
// Check Admin email
233+
if len(form.AdminEmail) == 0 {
234+
ctx.Data["Err_Admin"] = true
235+
ctx.Data["Err_AdminEmail"] = true
236+
ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_email"), tplInstall, form)
237+
return
238+
}
239+
// Check admin password.
240+
if len(form.AdminPasswd) == 0 {
241+
ctx.Data["Err_Admin"] = true
242+
ctx.Data["Err_AdminPasswd"] = true
243+
ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_password"), tplInstall, form)
244+
return
245+
}
246+
if form.AdminPasswd != form.AdminConfirmPasswd {
247+
ctx.Data["Err_Admin"] = true
248+
ctx.Data["Err_AdminPasswd"] = true
249+
ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplInstall, form)
250+
return
251+
}
228252
}
229253

230254
if form.AppURL[len(form.AppURL)-1] != '/' {

0 commit comments

Comments
 (0)