Deactivate handles POST requests to /account/deactivate
( req *http.Request, userInteractiveAuth *auth.UserInteractive, accountAPI api.ClientUserAPI, deviceAPI *api.Device, )
| 13 | |
| 14 | // Deactivate handles POST requests to /account/deactivate |
| 15 | func Deactivate( |
| 16 | req *http.Request, |
| 17 | userInteractiveAuth *auth.UserInteractive, |
| 18 | accountAPI api.ClientUserAPI, |
| 19 | deviceAPI *api.Device, |
| 20 | ) util.JSONResponse { |
| 21 | ctx := req.Context() |
| 22 | defer req.Body.Close() // nolint:errcheck |
| 23 | bodyBytes, err := io.ReadAll(req.Body) |
| 24 | if err != nil { |
| 25 | return util.JSONResponse{ |
| 26 | Code: http.StatusBadRequest, |
| 27 | JSON: jsonerror.BadJSON("The request body could not be read: " + err.Error()), |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | login, errRes := userInteractiveAuth.Verify(ctx, bodyBytes, deviceAPI) |
| 32 | if errRes != nil { |
| 33 | return *errRes |
| 34 | } |
| 35 | |
| 36 | localpart, _, err := gomatrixserverlib.SplitID('@', login.Username()) |
| 37 | if err != nil { |
| 38 | util.GetLogger(req.Context()).WithError(err).Error("gomatrixserverlib.SplitID failed") |
| 39 | return jsonerror.InternalServerError() |
| 40 | } |
| 41 | |
| 42 | var res api.PerformAccountDeactivationResponse |
| 43 | err = accountAPI.PerformAccountDeactivation(ctx, &api.PerformAccountDeactivationRequest{ |
| 44 | Localpart: localpart, |
| 45 | }, &res) |
| 46 | if err != nil { |
| 47 | util.GetLogger(ctx).WithError(err).Error("userAPI.PerformAccountDeactivation failed") |
| 48 | return jsonerror.InternalServerError() |
| 49 | } |
| 50 | |
| 51 | return util.JSONResponse{ |
| 52 | Code: http.StatusOK, |
| 53 | JSON: struct{}{}, |
| 54 | } |
| 55 | } |