Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,21 @@ 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)
cond := builder.NewCond()
cond = cond.And(builder.Eq{"type": UserTypeIndividual})

exists, err := sess.Where(cond).Limit(1).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)
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +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_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 <b>%s</b>. 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.
Expand Down
4 changes: 2 additions & 2 deletions routers/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,6 @@ 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)
Expand Down Expand Up @@ -609,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)
}
4 changes: 3 additions & 1 deletion routers/web/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,9 @@ func SignUp(ctx *context.Context) {

ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/sign_up"

ctx.Data["IsFirstTimeRegistration"] = user_model.CountUsers(ctx, nil) == 0
hasUsers, _ := user_model.HasUsers(ctx)

ctx.Data["IsFirstTimeRegistration"] = !hasUsers

oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, optional.Some(true))
if err != nil {
Expand Down