completeRegistration runs some rudimentary checks against the submitted input, then if successful creates an account and a newly associated device We pass in each individual part of the request here instead of just passing a registerRequest, as this function serves requests encoded as both registerR
( ctx context.Context, userAPI userapi.ClientUserAPI, username, password, appserviceID, ipAddr, userAgent, sessionID string, inhibitLogin eventutil.WeakBoolean, displayName, deviceID *string, accType userapi.AccountType, )
| 857 | // registerRequests and legacyRegisterRequests, which share some attributes but |
| 858 | // not all |
| 859 | func completeRegistration( |
| 860 | ctx context.Context, |
| 861 | userAPI userapi.ClientUserAPI, |
| 862 | username, password, appserviceID, ipAddr, userAgent, sessionID string, |
| 863 | inhibitLogin eventutil.WeakBoolean, |
| 864 | displayName, deviceID *string, |
| 865 | accType userapi.AccountType, |
| 866 | ) util.JSONResponse { |
| 867 | if username == "" { |
| 868 | return util.JSONResponse{ |
| 869 | Code: http.StatusBadRequest, |
| 870 | JSON: jsonerror.MissingArgument("Missing username"), |
| 871 | } |
| 872 | } |
| 873 | // Blank passwords are only allowed by registered application services |
| 874 | if password == "" && appserviceID == "" { |
| 875 | return util.JSONResponse{ |
| 876 | Code: http.StatusBadRequest, |
| 877 | JSON: jsonerror.MissingArgument("Missing password"), |
| 878 | } |
| 879 | } |
| 880 | var accRes userapi.PerformAccountCreationResponse |
| 881 | err := userAPI.PerformAccountCreation(ctx, &userapi.PerformAccountCreationRequest{ |
| 882 | AppServiceID: appserviceID, |
| 883 | Localpart: username, |
| 884 | Password: password, |
| 885 | AccountType: accType, |
| 886 | OnConflict: userapi.ConflictAbort, |
| 887 | }, &accRes) |
| 888 | if err != nil { |
| 889 | if _, ok := err.(*userapi.ErrorConflict); ok { // user already exists |
| 890 | return util.JSONResponse{ |
| 891 | Code: http.StatusBadRequest, |
| 892 | JSON: jsonerror.UserInUse("Desired user ID is already taken."), |
| 893 | } |
| 894 | } |
| 895 | return util.JSONResponse{ |
| 896 | Code: http.StatusInternalServerError, |
| 897 | JSON: jsonerror.Unknown("failed to create account: " + err.Error()), |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | // Increment prometheus counter for created users |
| 902 | amtRegUsers.Inc() |
| 903 | |
| 904 | // Check whether inhibit_login option is set. If so, don't create an access |
| 905 | // token or a device for this user |
| 906 | if inhibitLogin { |
| 907 | return util.JSONResponse{ |
| 908 | Code: http.StatusOK, |
| 909 | JSON: registerResponse{ |
| 910 | UserID: userutil.MakeUserID(username, accRes.Account.ServerName), |
| 911 | HomeServer: accRes.Account.ServerName, |
| 912 | }, |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | token, err := auth.GenerateAccessToken() |
no test coverage detected