// Delete handles user's data removal from the data store.
// On successful deletion, an email will be sent.
Delete handles user's data removal from the data store.
On successful deletion, an email will be sent.
// Delete handles user ' s data removal from the data store . // On successful deletion an email will be sent .
func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()
	_, id, err := httpflow.ExtractSession(ctx)
	if err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	var cInp CoreInput
	if err = httpflow.DecodeJSON(r, &cInp); err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	usr, err := h.db.FetchUserByID(ctx, id)
	if err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	if err = h.ext.deleteCheck(ctx, usr); err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	usrC := usr.ExposeCore()
	if !usrC.IsPasswordCorrect(cInp.Password) {
		httpflow.RespondError(h.log, w, r, ErrInvalidCredentials)
		return
	}
	if err = h.session.manager.RevokeAll(ctx, w); err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	if err = h.db.DeleteUserByID(ctx, id); err != nil {
		httpflow.RespondError(h.log, w, r, err)
		return
	}
	go h.email.SendAccountDeleted(ctx, usrC.Email)
	httpflow.Respond(h.log, w, r, nil, http.StatusNoContent)
}
func ( h * Handler ) Delete ( w http . ResponseWriter , r * http . Request ) { ctx := r . Context ( ) _ , id , err := httpflow . ExtractSession ( ctx ) if err != nil { httpflow . RespondError ( h . log , w , r , err ) return } var cInp CoreInput if err = httpflow . DecodeJSON ( r , & cInp ) ; err != nil { httpflow . RespondError ( h . log , w , r , err ) return } usr , err := h . db . FetchUserByID ( ctx , id ) if err != nil { httpflow . RespondError ( h . log , w , r , err ) return } if err = h . ext . deleteCheck ( ctx , usr ) ; err != nil { httpflow . RespondError ( h . log , w , r , err ) return } usrC := usr . ExposeCore ( ) if ! usrC . IsPasswordCorrect ( cInp . Password ) { httpflow . RespondError ( h . log , w , r , ErrInvalidCredentials ) return } if err = h . session . manager . RevokeAll ( ctx , w ) ; err != nil { httpflow . RespondError ( h . log , w , r , err ) return } if err = h . db . DeleteUserByID ( ctx , id ) ; err != nil { httpflow . RespondError ( h . log , w , r , err ) return } go h . email . SendAccountDeleted ( ctx , usrC . Email ) httpflow . Respond ( h . log , w , r , nil , http . StatusNoContent ) }
Delete handles user's data removal from the data store.
Delete handles user ' s data removal from the data store .