Skip to content

Commit 495cae8

Browse files
committed
feat: redirect to registration page for first-time admin setup after installation
1 parent e92c4f1 commit 495cae8

File tree

6 files changed

+10
-2
lines changed

6 files changed

+10
-2
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ remember_me.compromised = The login token is not valid anymore which may indicat
421421
forgot_password_title= Forgot Password
422422
forgot_password = Forgot password?
423423
need_account = Need an account?
424+
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.
424425
sign_up_now = Register now.
425426
sign_up_successful = Account was successfully created. Welcome!
426427
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.

routers/install/install.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ func SubmitInstall(ctx *context.Context) {
558558
}
559559
log.Info("Admin account already exist")
560560
u, _ = user_model.GetUserByName(ctx, u.Name)
561+
} else {
562+
ctx.Data["IsAccountCreated"] = true
561563
}
562564

563565
nt, token, err := auth_service.CreateAuthTokenForUserID(ctx, u.ID)

routers/web/auth/auth.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ func SignUp(ctx *context.Context) {
424424

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

427+
ctx.Data["IsFirstTimeRegistration"] = user_model.CountUsers(ctx, nil) == 0
428+
427429
oauth2Providers, err := oauth2.GetOAuth2Providers(ctx, optional.Some(true))
428430
if err != nil {
429431
ctx.ServerError("UserSignUp", err)

templates/post-install.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- the "cup" has a handler, so move it a little leftward to make it visually in the center -->
55
<div class="tw-ml-[-30px]"><img width="160" src="{{AssetUrlPrefix}}/img/loading.png" alt aria-hidden="true"></div>
66
<div class="tw-my-[2em] tw-text-[18px]">
7-
<a id="goto-user-login" href="{{AppSubUrl}}/user/login">{{ctx.Locale.Tr "install.installing_desc"}}</a>
7+
<a id="goto-signup-or-signin" href="{{AppSubUrl}}{{if .IsAccountCreated}}/user/login{{else}}/user/sign_up{{end}}">{{ctx.Locale.Tr "install.installing_desc"}}</a>
88
</div>
99
</div>
1010
</div>

templates/user/auth/signup_inner.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
{{end}}
88
</h4>
99
<div class="ui attached segment">
10+
{{if .IsFirstTimeRegistration}}
11+
<p>{{ctx.Locale.Tr "auth.sign_up_tip"}}</p>
12+
{{end}}
1013
<form class="ui form" action="{{.SignUpLink}}" method="post">
1114
{{.CsrfTokenHtml}}
1215
{{if or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeRegister)}}

web_src/js/features/install.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function initPreInstall() {
104104
}
105105

106106
function initPostInstall() {
107-
const el = document.querySelector('#goto-user-login');
107+
const el = document.querySelector('#goto-signup-or-signin');
108108
if (!el) return;
109109

110110
const targetUrl = el.getAttribute('href');

0 commit comments

Comments
 (0)