mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-14 18:33:09 -06:00
Lint
Reduce cyclomatic complexity of the handleRegistration function. Signed-off-by: Andrew Morgan (https://amorgan.xyz) <andrew@amorgan.xyz>
This commit is contained in:
parent
4f78a32c82
commit
8549d4b096
|
|
@ -451,18 +451,36 @@ func handleRegistrationFlow(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the user's registration flow has been completed successfully
|
// Check if the user's registration flow has been completed successfully
|
||||||
if !checkFlowCompleted(sessions[sessionID], cfg.Derived.Registration.Flows) {
|
// A response with current registration flow and remaining available methods
|
||||||
// There are still more stages to complete.
|
// will be returned if a flow has not been successfully completed yet
|
||||||
// Return the flows and those that have been completed.
|
return checkAndCompleteFlow(sessions[sessionID], req, r, sessionID, cfg, accountDB, deviceDB)
|
||||||
return util.JSONResponse{
|
}
|
||||||
Code: 401,
|
|
||||||
JSON: newUserInteractiveResponse(sessionID,
|
// checkAndCompleteFlow checks if a given registration flow is completed given
|
||||||
cfg.Derived.Registration.Flows, cfg.Derived.Registration.Params),
|
// a set of allowed flows. If so, registration is completed, otherwise a
|
||||||
}
|
// response with
|
||||||
|
func checkAndCompleteFlow(
|
||||||
|
flow []authtypes.LoginType,
|
||||||
|
req *http.Request,
|
||||||
|
r registerRequest,
|
||||||
|
sessionID string,
|
||||||
|
cfg *config.Dendrite,
|
||||||
|
accountDB *accounts.Database,
|
||||||
|
deviceDB *devices.Database,
|
||||||
|
) util.JSONResponse {
|
||||||
|
if checkFlowCompleted(flow, cfg.Derived.Registration.Flows) {
|
||||||
|
// This flow was completed, registration can continue
|
||||||
|
return completeRegistration(req.Context(), accountDB, deviceDB,
|
||||||
|
r.Username, r.Password, "", r.InitialDisplayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return completeRegistration(req.Context(), accountDB, deviceDB,
|
// There are still more stages to complete.
|
||||||
r.Username, r.Password, "", r.InitialDisplayName)
|
// Return the flows and those that have been completed.
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: 401,
|
||||||
|
JSON: newUserInteractiveResponse(sessionID,
|
||||||
|
cfg.Derived.Registration.Flows, cfg.Derived.Registration.Params),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LegacyRegister process register requests from the legacy v1 API
|
// LegacyRegister process register requests from the legacy v1 API
|
||||||
|
|
@ -688,7 +706,10 @@ func checkFlows(
|
||||||
// checkFlowCompleted checks if a registration flow complies with any allowed flow
|
// checkFlowCompleted checks if a registration flow complies with any allowed flow
|
||||||
// dictated by the server. Order of stages does not matter. A user may complete
|
// dictated by the server. Order of stages does not matter. A user may complete
|
||||||
// extra stages as long as the required stages of at least one flow is met.
|
// extra stages as long as the required stages of at least one flow is met.
|
||||||
func checkFlowCompleted(flow []authtypes.LoginType, allowedFlows []authtypes.Flow) bool {
|
func checkFlowCompleted(
|
||||||
|
flow []authtypes.LoginType,
|
||||||
|
allowedFlows []authtypes.Flow,
|
||||||
|
) bool {
|
||||||
// Iterate through possible flows to check whether any have been fully completed.
|
// Iterate through possible flows to check whether any have been fully completed.
|
||||||
for _, allowedFlow := range allowedFlows {
|
for _, allowedFlow := range allowedFlows {
|
||||||
if checkFlows(flow, allowedFlow.Stages) {
|
if checkFlows(flow, allowedFlow.Stages) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue