Add m.login.recaptcha to completed stages after success

This commit is contained in:
Andrew Morgan 2019-07-19 14:09:29 +01:00
parent e704cc7ee0
commit 03b3bc208e
2 changed files with 11 additions and 8 deletions

View file

@ -149,6 +149,9 @@ func AuthFallback(
return nil return nil
} }
// Success. Add recaptcha as a completed login flow
AddCompletedSessionStage(sessionID, authtypes.LoginTypeRecaptcha)
ServeSuccess() ServeSuccess()
return nil return nil
} }

View file

@ -83,17 +83,17 @@ func (d sessionsDict) GetCompletedStages(sessionID string) []authtypes.LoginType
return make([]authtypes.LoginType, 0) return make([]authtypes.LoginType, 0)
} }
// AddCompletedStage records that a session has completed an auth stage.
func (d *sessionsDict) AddCompletedStage(sessionID string, stage authtypes.LoginType) {
d.sessions[sessionID] = append(d.GetCompletedStages(sessionID), stage)
}
func newSessionsDict() *sessionsDict { func newSessionsDict() *sessionsDict {
return &sessionsDict{ return &sessionsDict{
sessions: make(map[string][]authtypes.LoginType), sessions: make(map[string][]authtypes.LoginType),
} }
} }
// AddCompletedSessionStage records that a session has completed an auth stage.
func AddCompletedSessionStage(sessionID string, stage authtypes.LoginType) {
sessions.sessions[sessionID] = append(sessions.GetCompletedStages(sessionID), stage)
}
var ( var (
// TODO: Remove old sessions. Need to do so on a session-specific timeout. // TODO: Remove old sessions. Need to do so on a session-specific timeout.
// sessions stores the completed flow stages for all sessions. Referenced using their sessionID. // sessions stores the completed flow stages for all sessions. Referenced using their sessionID.
@ -521,7 +521,7 @@ func handleRegistrationFlow(
} }
// Add Recaptcha to the list of completed registration stages // Add Recaptcha to the list of completed registration stages
sessions.AddCompletedStage(sessionID, authtypes.LoginTypeRecaptcha) AddCompletedSessionStage(sessionID, authtypes.LoginTypeRecaptcha)
case authtypes.LoginTypeSharedSecret: case authtypes.LoginTypeSharedSecret:
// Check shared secret against config // Check shared secret against config
@ -534,7 +534,7 @@ func handleRegistrationFlow(
} }
// Add SharedSecret to the list of completed registration stages // Add SharedSecret to the list of completed registration stages
sessions.AddCompletedStage(sessionID, authtypes.LoginTypeSharedSecret) AddCompletedSessionStage(sessionID, authtypes.LoginTypeSharedSecret)
case "": case "":
// Extract the access token from the request, if there's one to extract // Extract the access token from the request, if there's one to extract
@ -564,7 +564,7 @@ func handleRegistrationFlow(
case authtypes.LoginTypeDummy: case authtypes.LoginTypeDummy:
// there is nothing to do // there is nothing to do
// Add Dummy to the list of completed registration stages // Add Dummy to the list of completed registration stages
sessions.AddCompletedStage(sessionID, authtypes.LoginTypeDummy) AddCompletedSessionStage(sessionID, authtypes.LoginTypeDummy)
default: default:
return util.JSONResponse{ return util.JSONResponse{