From ad6e331860f8861e305d004342f6eba2424af2a7 Mon Sep 17 00:00:00 2001 From: Eric Chiang Date: Tue, 22 Dec 2015 13:20:40 -0800 Subject: [PATCH] server: fix flow when user logs in through wrong connector This cleans up the code that deals with a user attempting to login through a different connector than they registered with. The only functional change is that `newLoginURLFromSession` is now called with register = false when a user has an existing account. --- server/server.go | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/server/server.go b/server/server.go index e4d7e328..abc598d5 100644 --- a/server/server.go +++ b/server/server.go @@ -322,26 +322,22 @@ func (s *Server) Login(ident oidc.Identity, key string) (string, error) { ConnectorID: ses.ConnectorID, ID: ses.Identity.ID, }) - if err != nil { - if err == user.ErrorNotFound { - // If has authenticated via a connector, but no local identity there - // are a couple of possibilities: - - // * Maybe they are using the wrong connector: - if ses.Identity.Email != "" { - if connID, err := getConnectorForUserByEmail(s.UserRepo, - ses.Identity.Email); err == nil { - - return newLoginURLFromSession(s.IssuerURL, - ses, true, []string{connID}, - "wrong-connector").String(), nil - } + if err == user.ErrorNotFound { + // Does the user have an existing account with a different connector? + if ses.Identity.Email != "" { + connID, err := getConnectorForUserByEmail(s.UserRepo, ses.Identity.Email) + if err == nil { + // Ask user to sign in through existing account. + u := newLoginURLFromSession(s.IssuerURL, ses, false, []string{connID}, "wrong-connector") + return u.String(), nil } - - // * User needs to register - return newLoginURLFromSession(s.IssuerURL, - ses, true, []string{ses.ConnectorID}, "register-maybe").String(), nil } + + // User doesn't have an existing account. Ask them to register. + u := newLoginURLFromSession(s.IssuerURL, ses, true, []string{ses.ConnectorID}, "register-maybe") + return u.String(), nil + } + if err != nil { return "", err }