MCPcopy Create free account
hub / github.com/daodst/chat / handleSharedSecretRegistration

Function handleSharedSecretRegistration

clientapi/routing/register.go:1062–1096  ·  view source on GitHub ↗
(userAPI userapi.ClientUserAPI, sr *SharedSecretRegistration, req *http.Request)

Source from the content-addressed store, hash-verified

1060}
1061
1062func handleSharedSecretRegistration(userAPI userapi.ClientUserAPI, sr *SharedSecretRegistration, req *http.Request) util.JSONResponse {
1063 ssrr, err := NewSharedSecretRegistrationRequest(req.Body)
1064 if err != nil {
1065 return util.JSONResponse{
1066 Code: 400,
1067 JSON: jsonerror.BadJSON(fmt.Sprintf("malformed json: %s", err)),
1068 }
1069 }
1070 valid, err := sr.IsValidMacLogin(ssrr.Nonce, ssrr.User, ssrr.Password, ssrr.Admin, ssrr.MacBytes)
1071 if err != nil {
1072 return util.ErrorResponse(err)
1073 }
1074 if !valid {
1075 return util.JSONResponse{
1076 Code: 403,
1077 JSON: jsonerror.Forbidden("bad mac"),
1078 }
1079 }
1080 // downcase capitals
1081 ssrr.User = strings.ToLower(ssrr.User)
1082
1083 if resErr := validateUsername(ssrr.User); resErr != nil {
1084 return *resErr
1085 }
1086 if resErr := validatePassword(ssrr.Password); resErr != nil {
1087 return *resErr
1088 }
1089 deviceID := "shared_secret_registration"
1090
1091 accType := userapi.AccountTypeUser
1092 if ssrr.Admin {
1093 accType = userapi.AccountTypeAdmin
1094 }
1095 return completeRegistration(req.Context(), userAPI, ssrr.User, ssrr.Password, "", req.RemoteAddr, req.UserAgent(), "", false, &ssrr.User, &deviceID, accType)
1096}

Callers 1

SetupFunction · 0.85

Calls 6

validateUsernameFunction · 0.85
validatePasswordFunction · 0.85
completeRegistrationFunction · 0.85
IsValidMacLoginMethod · 0.80
ContextMethod · 0.80

Tested by

no test coverage detected