Skip to content

Commit b845119

Browse files
AJ ONealtechknowlogick
AJ ONeal
authored andcommitted
UX of link account (Step 1) (#5006)
* Show either sign up OR sign in * disambiguate fresh start from adding recovery options * use tabs to switch between account link flows * add active to tab body as well * changes as per discussion * handle specific error; fix missing err typo
1 parent a2ee2a3 commit b845119

File tree

5 files changed

+79
-14
lines changed

5 files changed

+79
-14
lines changed

options/locale/locale_en-US.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ sign_in_with = Sign In With
99
sign_out = Sign Out
1010
sign_up = Register
1111
link_account = Link Account
12-
link_account_signin_or_signup = Sign in with existing credentials to link your existing account to this account. Or register a new one.
1312
register = Register
1413
website = Website
1514
version = Version
@@ -230,6 +229,12 @@ twofa_passcode_incorrect = Your passcode is incorrect. If you misplaced your dev
230229
twofa_scratch_token_incorrect = Your scratch code is incorrect.
231230
login_userpass = Sign In
232231
login_openid = OpenID
232+
oauth_signup_tab = Register New Account
233+
oauth_signup_title = Add Email and Password (for Account Recovery)
234+
oauth_signup_submit = Complete Account
235+
oauth_signin_tab = Link to Existing Account
236+
oauth_signin_title = Sign In to Authorize Linked Account
237+
oauth_signin_submit = Link Account
233238
openid_connect_submit = Connect
234239
openid_connect_title = Connect to an existing account
235240
openid_connect_desc = The chosen OpenID URI is unknown. Associate it with a new account here.

routers/user/auth.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,30 @@ func LinkAccount(ctx *context.Context) {
664664
return
665665
}
666666

667-
ctx.Data["user_name"] = gothUser.(goth.User).NickName
668-
ctx.Data["email"] = gothUser.(goth.User).Email
667+
uname := gothUser.(goth.User).NickName
668+
email := gothUser.(goth.User).Email
669+
ctx.Data["user_name"] = uname
670+
ctx.Data["email"] = email
671+
672+
if len(email) != 0 {
673+
u, err := models.GetUserByEmail(email)
674+
if err != nil && !models.IsErrUserNotExist(err) {
675+
ctx.ServerError("UserSignIn", err)
676+
return
677+
}
678+
if u != nil {
679+
ctx.Data["user_exists"] = true
680+
}
681+
} else if len(uname) != 0 {
682+
u, err := models.GetUserByName(uname)
683+
if err != nil && !models.IsErrUserNotExist(err) {
684+
ctx.ServerError("UserSignIn", err)
685+
return
686+
}
687+
if u != nil {
688+
ctx.Data["user_exists"] = true
689+
}
690+
}
669691

670692
ctx.HTML(200, tplLinkAccount)
671693
}

templates/user/auth/link_account.tmpl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
{{template "base/head" .}}
2+
23
<div class="user link-account">
34
<div class="ui middle very relaxed page grid">
45
<div class="column">
5-
<p class="large center">
6-
{{.i18n.Tr "link_account_signin_or_signup"}}
7-
</p>
6+
7+
<div class="ui tabular menu">
8+
<!-- TODO handle .ShowRegistrationButton once other login bugs are fixed -->
9+
<div class="item {{if not .user_exists}}active{{end}}"
10+
data-tab="auth-link-signup-tab">
11+
{{.i18n.Tr "auth.oauth_signup_tab"}}
12+
</div>
13+
<div class="item {{if .user_exists}}active{{end}}"
14+
data-tab="auth-link-signin-tab">
15+
{{.i18n.Tr "auth.oauth_signin_tab"}}
16+
</div>
17+
</div>
18+
19+
<div class="ui tab {{if not .user_exists}}active{{end}}"
20+
data-tab="auth-link-signup-tab">
21+
{{template "user/auth/signup_inner" .}}
22+
</div>
23+
<div class="ui tab {{if .user_exists}}active{{end}}"
24+
data-tab="auth-link-signin-tab">
25+
<div class="ui user signin container icon">
26+
{{template "user/auth/signin_inner" .}}
27+
</div>
28+
</div>
829
</div>
930
</div>
1031
</div>
11-
<div class="ui user signin container icon">
12-
{{template "user/auth/signin_inner" .}}
13-
</div>
14-
{{template "user/auth/signup_inner" .}}
32+
1533
{{template "base/footer" .}}

templates/user/auth/signin_inner.tmpl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
{{template "base/alert" .}}
33
{{end}}
44
<h4 class="ui top attached header center">
5-
{{.i18n.Tr "auth.login_userpass"}}
5+
{{if .LinkAccountMode}}
6+
{{.i18n.Tr "auth.oauth_signin_title"}}
7+
{{else}}
8+
{{.i18n.Tr "auth.login_userpass"}}
9+
{{end}}
610
</h4>
711
<div class="ui attached segment">
812
<form class="ui form" action="{{.SignInLink}}" method="post">
@@ -27,7 +31,13 @@
2731

2832
<div class="inline field">
2933
<label></label>
30-
<button class="ui green button">{{.i18n.Tr "sign_in"}}</button>
34+
<button class="ui green button">
35+
{{if .LinkAccountMode}}
36+
{{.i18n.Tr "auth.oauth_signin_submit"}}
37+
{{else}}
38+
{{.i18n.Tr "sign_in"}}
39+
{{end}}
40+
</button>
3141
<a href="{{AppSubUrl}}/user/forgot_password">{{.i18n.Tr "auth.forgot_password"}}</a>
3242
</div>
3343

templates/user/auth/signup_inner.tmpl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
<form class="ui form" action="{{.SignUpLink}}" method="post">
55
{{.CsrfTokenHtml}}
66
<h3 class="ui top attached header">
7-
{{.i18n.Tr "sign_up"}}
7+
{{if .LinkAccountMode}}
8+
{{.i18n.Tr "auth.oauth_signup_title"}}
9+
{{else}}
10+
{{.i18n.Tr "sign_up"}}
11+
{{end}}
812
</h3>
913
<div class="ui attached segment">
1014
{{if or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeRegister)}}
@@ -47,7 +51,13 @@
4751

4852
<div class="inline field">
4953
<label></label>
50-
<button class="ui green button">{{.i18n.Tr "auth.create_new_account"}}</button>
54+
<button class="ui green button">
55+
{{if .LinkAccountMode}}
56+
{{.i18n.Tr "auth.oauth_signup_submit"}}
57+
{{else}}
58+
{{.i18n.Tr "auth.create_new_account"}}
59+
{{end}}
60+
</button>
5161
</div>
5262

5363
{{if not .LinkAccountMode}}

0 commit comments

Comments
 (0)