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

Function Deactivate

clientapi/routing/deactivate.go:15–55  ·  view source on GitHub ↗

Deactivate handles POST requests to /account/deactivate

(
	req *http.Request,
	userInteractiveAuth *auth.UserInteractive,
	accountAPI api.ClientUserAPI,
	deviceAPI *api.Device,
)

Source from the content-addressed store, hash-verified

13
14// Deactivate handles POST requests to /account/deactivate
15func 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}

Callers 1

SetupFunction · 0.85

Calls 6

ContextMethod · 0.80
UsernameMethod · 0.80
CloseMethod · 0.65
VerifyMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected