diff --git a/models/user/user.go b/models/user/user.go index d7331d79f0b09..e805d7485f91f 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -831,6 +831,18 @@ type CountUserFilter struct { IsActive optional.Option[bool] } +// HasUsers returns true if any user exists in the database. +// It performs a much more efficient check than counting all users. +func HasUsers(ctx context.Context) (bool, error) { + sess := db.GetEngine(ctx) + exists, err := sess.Exist(new(User)) + if err != nil { + return false, fmt.Errorf("error checking user existence: %w", err) + } + + return exists, nil +} + // CountUsers returns number of users. func CountUsers(ctx context.Context, opts *CountUserFilter) int64 { return countUsers(ctx, opts) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 4384ebc3d7541..8ff98e16c78eb 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. 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 2962f3948fea1..68f402b210dd7 100644 --- a/routers/install/install.go +++ b/routers/install/install.go @@ -607,5 +607,7 @@ func SubmitInstall(ctx *context.Context) { // InstallDone shows the "post-install" page, makes it easier to develop the page. // The name is not called as "PostInstall" to avoid misinterpretation as a handler for "POST /install" func InstallDone(ctx *context.Context) { //nolint + hasUsers, _ := user_model.HasUsers(ctx) + ctx.Data["IsAccountCreated"] = hasUsers ctx.HTML(http.StatusOK, tplPostInstall) } diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index 69b9d285b78cc..bb9bb66f49ed0 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -424,6 +424,10 @@ func SignUp(ctx *context.Context) { ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up" + hasUsers, _ := user_model.HasUsers(ctx) + + ctx.Data["IsFirstTimeRegistration"] = !hasUsers + 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 0c9aa35c9093a..44099ce29d5d0 100644 --- a/templates/post-install.tmpl +++ b/templates/post-install.tmpl @@ -4,7 +4,7 @@
{{ctx.Locale.Tr "auth.sign_up_tip"}}
+ {{end}}