Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show OpenID Connect and OAuth on signup page #20242

Merged
merged 5 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
18 changes: 18 additions & 0 deletions routers/web/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,16 @@ func SignUp(ctx *context.Context) {

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

orderedOAuth2Names, oauth2Providers, err := oauth2.GetActiveOAuth2Providers()
if err != nil {
ctx.ServerError("UserSignUp", err)
return
}

ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
ctx.Data["OAuth2Providers"] = oauth2Providers
context.SetCaptchaData(ctx)

ctx.Data["PageIsSignUp"] = true

// Show Disabled Registration message if DisableRegistration or AllowOnlyExternalRegistration options are true
Expand All @@ -408,7 +417,16 @@ func SignUpPost(ctx *context.Context) {

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

orderedOAuth2Names, oauth2Providers, err := oauth2.GetActiveOAuth2Providers()
if err != nil {
ctx.ServerError("UserSignUp", err)
return
}

ctx.Data["OrderedOAuth2Names"] = orderedOAuth2Names
ctx.Data["OAuth2Providers"] = oauth2Providers
context.SetCaptchaData(ctx)

ctx.Data["PageIsSignUp"] = true

// Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true
Expand Down
3 changes: 3 additions & 0 deletions templates/user/auth/signin_navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<a class="{{if .PageIsLogin}}active {{end}}item" rel="nofollow" href="{{AppSubUrl}}/user/login">
{{.locale.Tr "auth.login_userpass"}}
</a>
<a class="{{if .PageIsSignUp}}active{{end}} item" rel="nofollow" href="{{AppSubUrl}}/user/sign_up">
{{.locale.Tr "auth.create_new_account"}}
</a>
{{if .EnableOpenIDSignIn}}
<a class="{{if .PageIsLoginOpenID}}active {{end}}item" rel="nofollow" href="{{AppSubUrl}}/user/login/openid">
{{svg "fontawesome-openid"}}
Expand Down
1 change: 1 addition & 0 deletions templates/user/auth/signup.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{template "base/head" .}}
<div role="main" aria-label="{{.Title}}" class="page-content user signin{{if .LinkAccountMode}} icon{{end}}">
{{template "user/auth/signin_navbar" .}}
<div class="ui middle very relaxed page grid">
{{template "user/auth/signup_inner" .}}
</div>
Expand Down
23 changes: 23 additions & 0 deletions templates/user/auth/signup_inner.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@
</div>
{{end}}
{{end}}

{{if and .OrderedOAuth2Names .OAuth2Providers}}
<div class="ui attached segment">
<div class="oauth2 center">
<div id="oauth2-login-loader" class="ui disabled centered loader"></div>
<div>
<div id="oauth2-login-navigator">
<p>{{.i18n.Tr "sign_in_with"}}</p>
{{range $key := .OrderedOAuth2Names}}
{{$provider := index $.OAuth2Providers $key}}
<a href="{{AppSubUrl}}/user/oauth2/{{$key}}">
<img
alt="{{$provider.DisplayName}}{{if eq $provider.Name "openidConnect"}} ({{$key}}){{end}}"
title="{{$provider.DisplayName}}{{if eq $provider.Name "openidConnect"}} ({{$key}}){{end}}"
class="{{$provider.Name}} oauth-login-image"
src="{{AppSubUrl}}{{$provider.Image}}"
></a>
{{end}}
</div>
</div>
</div>
</div>
{{end}}
</form>
</div>
</div>