0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-21 10:14:40 +02:00

feat: redirect to registration page for first-time admin setup after installation

This commit is contained in:
Kerwin Bryant 2025-05-17 03:43:03 +00:00
parent e92c4f1808
commit 495cae8c1a
6 changed files with 10 additions and 2 deletions

View File

@ -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 <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.

View File

@ -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)

View File

@ -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)

View File

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

View File

@ -7,6 +7,9 @@
{{end}}
</h4>
<div class="ui attached segment">
{{if .IsFirstTimeRegistration}}
<p>{{ctx.Locale.Tr "auth.sign_up_tip"}}</p>
{{end}}
<form class="ui form" action="{{.SignUpLink}}" method="post">
{{.CsrfTokenHtml}}
{{if or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeRegister)}}

View File

@ -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');