From 495cae8c1a2657e79f3d252eb399659487039198 Mon Sep 17 00:00:00 2001 From: Kerwin Bryant Date: Sat, 17 May 2025 03:43:03 +0000 Subject: [PATCH] feat: redirect to registration page for first-time admin setup after installation --- options/locale/locale_en-US.ini | 1 + routers/install/install.go | 2 ++ routers/web/auth/auth.go | 2 ++ templates/post-install.tmpl | 2 +- templates/user/auth/signup_inner.tmpl | 3 +++ web_src/js/features/install.ts | 2 +- 6 files changed, 10 insertions(+), 2 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index b6411f7777..69aad0c5f3 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -421,6 +421,7 @@ remember_me.compromised = The login token is not valid anymore which may indicat forgot_password_title= Forgot Password forgot_password = Forgot password? need_account = Need an account? +sign_up_tip = You are registering the first account in the system. Upon successful registration, you will become the Super Administrator. Please carefully remember your username and password, as losing this information could cause significant inconvenience later. sign_up_now = Register now. sign_up_successful = Account was successfully created. Welcome! confirmation_mail_sent_prompt_ex = A new confirmation email has been sent to %s. Please check your inbox within the next %s to complete the registration process. If your registration email address is incorrect, you can sign in again and change it. diff --git a/routers/install/install.go b/routers/install/install.go index 2962f3948f..bd7810e809 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -558,6 +558,8 @@ func SubmitInstall(ctx *context.Context) { } log.Info("Admin account already exist") u, _ = user_model.GetUserByName(ctx, u.Name) + } else { + ctx.Data["IsAccountCreated"] = true } nt, token, err := auth_service.CreateAuthTokenForUserID(ctx, u.ID) diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index 69b9d285b7..f07e821e01 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -424,6 +424,8 @@ func SignUp(ctx *context.Context) { ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up" + ctx.Data["IsFirstTimeRegistration"] = user_model.CountUsers(ctx, nil) == 0 + oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, optional.Some(true)) if err != nil { ctx.ServerError("UserSignUp", err) diff --git a/templates/post-install.tmpl b/templates/post-install.tmpl index 0c9aa35c90..44099ce29d 100644 --- a/templates/post-install.tmpl +++ b/templates/post-install.tmpl @@ -4,7 +4,7 @@
- {{ctx.Locale.Tr "install.installing_desc"}} + {{ctx.Locale.Tr "install.installing_desc"}}
diff --git a/templates/user/auth/signup_inner.tmpl b/templates/user/auth/signup_inner.tmpl index d66568199d..a3f6e1471f 100644 --- a/templates/user/auth/signup_inner.tmpl +++ b/templates/user/auth/signup_inner.tmpl @@ -7,6 +7,9 @@ {{end}}
+ {{if .IsFirstTimeRegistration}} +

{{ctx.Locale.Tr "auth.sign_up_tip"}}

+ {{end}}
{{.CsrfTokenHtml}} {{if or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeRegister)}} diff --git a/web_src/js/features/install.ts b/web_src/js/features/install.ts index 34df4757f9..bd8e57265c 100644 --- a/web_src/js/features/install.ts +++ b/web_src/js/features/install.ts @@ -104,7 +104,7 @@ function initPreInstall() { } function initPostInstall() { - const el = document.querySelector('#goto-user-login'); + const el = document.querySelector('#goto-signup-or-signin'); if (!el) return; const targetUrl = el.getAttribute('href');