Skip to content

Commit

Permalink
show "back" link for password connectors
Browse files Browse the repository at this point in the history
This way, the user who has selected, say, "Log in with Email" can make up
their mind, and select a different connector instead.

However, if there's only one connector set up, none of this makes sense -- and
the link will thus not be displayed.

Signed-off-by: Stephan Renatus <[email protected]>
  • Loading branch information
srenatus committed Nov 13, 2017
1 parent 1fe7d53 commit d3f3d25
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
5 changes: 3 additions & 2 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
return
}
scopes := parseScopes(authReq.Scopes)
showBacklink := len(s.connectors) > 1

switch r.Method {
case "GET":
Expand Down Expand Up @@ -250,7 +251,7 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
}
http.Redirect(w, r, callbackURL, http.StatusFound)
case connector.PasswordConnector:
if err := s.templates.password(w, r.URL.String(), "", usernamePrompt(conn), false); err != nil {
if err := s.templates.password(w, r.URL.String(), "", usernamePrompt(conn), false, showBacklink); err != nil {
s.logger.Errorf("Server template error: %v", err)
}
case connector.SAMLConnector:
Expand Down Expand Up @@ -298,7 +299,7 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
return
}
if !ok {
if err := s.templates.password(w, r.URL.String(), username, usernamePrompt(passwordConnector), true); err != nil {
if err := s.templates.password(w, r.URL.String(), username, usernamePrompt(passwordConnector), true, showBacklink); err != nil {
s.logger.Errorf("Server template error: %v", err)
}
return
Expand Down
5 changes: 3 additions & 2 deletions server/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ func (t *templates) login(w http.ResponseWriter, connectors []connectorInfo) err
return renderTemplate(w, t.loginTmpl, data)
}

func (t *templates) password(w http.ResponseWriter, postURL, lastUsername, usernamePrompt string, lastWasInvalid bool) error {
func (t *templates) password(w http.ResponseWriter, postURL, lastUsername, usernamePrompt string, lastWasInvalid, showBacklink bool) error {
data := struct {
PostURL string
BackLink bool
Username string
UsernamePrompt string
Invalid bool
}{postURL, lastUsername, usernamePrompt, lastWasInvalid}
}{postURL, showBacklink, lastUsername, usernamePrompt, lastWasInvalid}
return renderTemplate(w, t.passwordTmpl, data)
}

Expand Down
5 changes: 5 additions & 0 deletions web/templates/password.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ <h2 class="theme-heading">Log in to Your Account</h2>
<button tabindex="3" id="submit-login" type="submit" class="dex-btn theme-btn--primary">Login</button>

</form>
{{ if .BackLink }}
<div class="theme-link-back">
<a class="dex-subtle-text" href="javascript:history.back()">Select another login method.</a>
</div>
{{ end }}
</div>

{{ template "footer.html" . }}
4 changes: 4 additions & 0 deletions web/themes/coreos/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@
text-align: left;
width: 250px;
}

.theme-link-back {
margin-top: 4px;
}

0 comments on commit d3f3d25

Please sign in to comment.