Add post-installation redirect based on admin account status (#34493)
Some checks are pending
release-nightly / nightly-binary (push) Waiting to run
release-nightly / nightly-docker-rootful (push) Waiting to run
release-nightly / nightly-docker-rootless (push) Waiting to run
cron-translations / crowdin-pull (push) Has been skipped

This PR adds a feature to direct users to appropriate pages after system
installation:
- If no admin credentials were provided during installation, redirect to
the registration page with a prominent notice about creating the first
administrative account
- If admin credentials were already set, redirect directly to the login
page


![4d396ad132d9b57fc4f45a62117177f1](https://github.com/user-attachments/assets/3a5d8700-9194-4d3b-a862-e64c8c347932)

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Kerwin Bryant
2025-06-22 02:48:06 +08:00
committed by GitHub
parent 7de114a332
commit 0548c10293
7 changed files with 32 additions and 4 deletions

View File

@ -831,6 +831,20 @@ type CountUserFilter struct {
IsActive optional.Option[bool]
}
// HasUsers checks whether there are any users in the database, or only one user exists.
func HasUsers(ctx context.Context) (ret struct {
HasAnyUser, HasOnlyOneUser bool
}, err error,
) {
res, err := db.GetEngine(ctx).Table(&User{}).Cols("id").Limit(2).Query()
if err != nil {
return ret, fmt.Errorf("error checking user existence: %w", err)
}
ret.HasAnyUser = len(res) != 0
ret.HasOnlyOneUser = len(res) == 1
return ret, nil
}
// CountUsers returns number of users.
func CountUsers(ctx context.Context, opts *CountUserFilter) int64 {
return countUsers(ctx, opts)