Merge pull request #1123 from srenatus/sr/back-button-for-password-template

show "back" link for password connectors
This commit is contained in:
Eric Chiang 2017-11-13 10:58:25 -08:00 committed by GitHub
commit f4b6bf2ac3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 4 deletions

View file

@ -223,6 +223,7 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
return return
} }
scopes := parseScopes(authReq.Scopes) scopes := parseScopes(authReq.Scopes)
showBacklink := len(s.connectors) > 1
switch r.Method { switch r.Method {
case "GET": case "GET":
@ -250,7 +251,7 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
} }
http.Redirect(w, r, callbackURL, http.StatusFound) http.Redirect(w, r, callbackURL, http.StatusFound)
case connector.PasswordConnector: 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) s.logger.Errorf("Server template error: %v", err)
} }
case connector.SAMLConnector: case connector.SAMLConnector:
@ -298,7 +299,7 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
return return
} }
if !ok { 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) s.logger.Errorf("Server template error: %v", err)
} }
return return

View file

@ -190,13 +190,14 @@ func (t *templates) login(w http.ResponseWriter, connectors []connectorInfo) err
return renderTemplate(w, t.loginTmpl, data) 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 { data := struct {
PostURL string PostURL string
BackLink bool
Username string Username string
UsernamePrompt string UsernamePrompt string
Invalid bool Invalid bool
}{postURL, lastUsername, usernamePrompt, lastWasInvalid} }{postURL, showBacklink, lastUsername, usernamePrompt, lastWasInvalid}
return renderTemplate(w, t.passwordTmpl, data) return renderTemplate(w, t.passwordTmpl, data)
} }

View file

@ -25,6 +25,11 @@
<button tabindex="3" id="submit-login" type="submit" class="dex-btn theme-btn--primary">Login</button> <button tabindex="3" id="submit-login" type="submit" class="dex-btn theme-btn--primary">Login</button>
</form> </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> </div>
{{ template "footer.html" . }} {{ template "footer.html" . }}

View file

@ -107,3 +107,7 @@
text-align: left; text-align: left;
width: 250px; width: 250px;
} }
.theme-link-back {
margin-top: 4px;
}