Reduce cyclo complexity

This commit is contained in:
Andrew Morgan 2018-07-27 18:22:51 +01:00
parent c594bbddb4
commit 28e98d99fc

View file

@ -497,8 +497,7 @@ func Register(
// Application services can register users with no auth type, but require
// access token. Differentiate from users who are initially hitting register
// without an auth type
if r.Auth.Type == "" && req.URL.Query().Get("access_token") == "" &&
req.Header.Get("Authorization") == "" {
if initialUserInteractiveRequest(req, r) {
return util.JSONResponse{
Code: http.StatusUnauthorized,
JSON: newUserInteractiveResponse(sessionID,
@ -782,6 +781,17 @@ func completeRegistration(
}
}
// initialUserInteractiveRequest returns true or false based on whether the
// request should have User Interactive Authentication Flows returned. This is
// the case if a user is requesting registration first without specifying a
// registration type. This method also differentiates between application
// services and users, as application services can register with no type and an
// access token, either included as part of the query parameters or an
// Authorization header
func initialUserInteractiveRequest(req *http.Request, r registerRequest) bool {
return r.Auth.Type == "" && req.URL.Query().Get("access_token") == "" && req.Header.Get("Authorization") == ""
}
// Used for shared secret registration.
// Checks if the username, password and isAdmin flag matches the given mac.
func isValidMacLogin(