handleRegistrationFlow will direct and complete registration flow stages that the client has requested. nolint: gocyclo
( req *http.Request, r registerRequest, sessionID string, cfg *config.ClientAPI, userAPI userapi.ClientUserAPI, accessToken string, accessTokenErr error, )
| 700 | // that the client has requested. |
| 701 | // nolint: gocyclo |
| 702 | func handleRegistrationFlow( |
| 703 | req *http.Request, |
| 704 | r registerRequest, |
| 705 | sessionID string, |
| 706 | cfg *config.ClientAPI, |
| 707 | userAPI userapi.ClientUserAPI, |
| 708 | accessToken string, |
| 709 | accessTokenErr error, |
| 710 | ) util.JSONResponse { |
| 711 | // TODO: Enable registration config flag |
| 712 | // TODO: Guest account upgrading |
| 713 | |
| 714 | // TODO: Handle loading of previous session parameters from database. |
| 715 | // TODO: Handle mapping registrationRequest parameters into session parameters |
| 716 | |
| 717 | // TODO: email / msisdn auth types. |
| 718 | |
| 719 | // Appservices are special and are not affected by disabled |
| 720 | // registration or user exclusivity. We'll go onto the appservice |
| 721 | // registration flow if a valid access token was provided or if |
| 722 | // the login type specifically requests it. |
| 723 | if r.Type == authtypes.LoginTypeApplicationService && accessTokenErr == nil { |
| 724 | return handleApplicationServiceRegistration( |
| 725 | accessToken, accessTokenErr, req, r, cfg, userAPI, |
| 726 | ) |
| 727 | } |
| 728 | |
| 729 | if cfg.RegistrationDisabled && r.Auth.Type != authtypes.LoginTypeSharedSecret { |
| 730 | return util.JSONResponse{ |
| 731 | Code: http.StatusForbidden, |
| 732 | JSON: jsonerror.Forbidden("Registration is disabled"), |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | // Make sure normal user isn't registering under an exclusive application |
| 737 | // service namespace. Skip this check if no app services are registered. |
| 738 | // If an access token is provided, ignore this check this is an appservice |
| 739 | // request and we will validate in validateApplicationService |
| 740 | if len(cfg.Derived.ApplicationServices) != 0 && |
| 741 | UsernameMatchesExclusiveNamespaces(cfg, r.Username) { |
| 742 | return util.JSONResponse{ |
| 743 | Code: http.StatusBadRequest, |
| 744 | JSON: jsonerror.ASExclusive("This username is reserved by an application service."), |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | switch r.Auth.Type { |
| 749 | case authtypes.LoginTypeRecaptcha: |
| 750 | // Check given captcha response |
| 751 | resErr := validateRecaptcha(cfg, r.Auth.Response, req.RemoteAddr) |
| 752 | if resErr != nil { |
| 753 | return *resErr |
| 754 | } |
| 755 | |
| 756 | // Add Recaptcha to the list of completed registration stages |
| 757 | sessions.addCompletedSessionStage(sessionID, authtypes.LoginTypeRecaptcha) |
| 758 | |
| 759 | case authtypes.LoginTypeDummy: |
no test coverage detected