diff options
author | zeripath <art27@cantab.net> | 2019-05-28 07:18:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-28 07:18:40 +0100 |
commit | bd9ed96da50de283485a4e274b414b7dd1d22ba6 (patch) | |
tree | 2d0e8382785ee1942664b69b054e86eb27e35a97 /routers | |
parent | 69d81b656978a03ff277a611f5c3d9ef1814d001 (diff) | |
download | gitea-bd9ed96da50de283485a4e274b414b7dd1d22ba6.tar.gz gitea-bd9ed96da50de283485a4e274b414b7dd1d22ba6.zip |
Install page - Handle invalid administrator username better (#7060)
* Install page - detect invalid admin username before installing
* Also fix #6954
Diffstat (limited to 'routers')
-rw-r--r-- | routers/install.go | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/routers/install.go b/routers/install.go index cc8be065a8..c95abebea7 100644 --- a/routers/install.go +++ b/routers/install.go @@ -215,18 +215,42 @@ func InstallPost(ctx *context.Context, form auth.InstallForm) { return } - // Check admin password. - if len(form.AdminName) > 0 && len(form.AdminPasswd) == 0 { - ctx.Data["Err_Admin"] = true - ctx.Data["Err_AdminPasswd"] = true - ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_password"), tplInstall, form) - return - } - if form.AdminPasswd != form.AdminConfirmPasswd { - ctx.Data["Err_Admin"] = true - ctx.Data["Err_AdminPasswd"] = true - ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplInstall, form) - return + // Check admin user creation + if len(form.AdminName) > 0 { + // Ensure AdminName is valid + if err := models.IsUsableUsername(form.AdminName); err != nil { + ctx.Data["Err_Admin"] = true + ctx.Data["Err_AdminName"] = true + if models.IsErrNameReserved(err) { + ctx.RenderWithErr(ctx.Tr("install.err_admin_name_is_reserved"), tplInstall, form) + return + } else if models.IsErrNamePatternNotAllowed(err) { + ctx.RenderWithErr(ctx.Tr("install.err_admin_name_pattern_not_allowed"), tplInstall, form) + return + } + ctx.RenderWithErr(ctx.Tr("install.err_admin_name_is_invalid"), tplInstall, form) + return + } + // Check Admin email + if len(form.AdminEmail) == 0 { + ctx.Data["Err_Admin"] = true + ctx.Data["Err_AdminEmail"] = true + ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_email"), tplInstall, form) + return + } + // Check admin password. + if len(form.AdminPasswd) == 0 { + ctx.Data["Err_Admin"] = true + ctx.Data["Err_AdminPasswd"] = true + ctx.RenderWithErr(ctx.Tr("install.err_empty_admin_password"), tplInstall, form) + return + } + if form.AdminPasswd != form.AdminConfirmPasswd { + ctx.Data["Err_Admin"] = true + ctx.Data["Err_AdminPasswd"] = true + ctx.RenderWithErr(ctx.Tr("form.password_not_match"), tplInstall, form) + return + } } if form.AppURL[len(form.AppURL)-1] != '/' { |