mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-20 20:07:51 +01:00
New function to delete account. Create deletion functions for blockchain and warehouse. Add function /account/delete to webapi. Close #42
This commit is contained in:
@@ -9,6 +9,7 @@ package webapi
|
||||
import (
|
||||
"encoding/hex"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/PeernetOfficial/core"
|
||||
)
|
||||
@@ -50,11 +51,11 @@ type apiResponsePeerSelf struct {
|
||||
}
|
||||
|
||||
/*
|
||||
apiPeerSelf provides information about the self peer details
|
||||
Request: GET /peer/self
|
||||
apiAccountInfo provides information about the current account.
|
||||
Request: GET /account/info
|
||||
Result: 200 with JSON structure apiResponsePeerSelf
|
||||
*/
|
||||
func apiPeerSelf(w http.ResponseWriter, r *http.Request) {
|
||||
func apiAccountInfo(w http.ResponseWriter, r *http.Request) {
|
||||
response := apiResponsePeerSelf{}
|
||||
response.NodeID = hex.EncodeToString(core.SelfNodeID())
|
||||
|
||||
@@ -63,3 +64,21 @@ func apiPeerSelf(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
EncodeJSON(w, r, response)
|
||||
}
|
||||
|
||||
/*
|
||||
apiAccountDelete deletes the current account. The confirm parameter must include the user's choice.
|
||||
Request: GET /account/delete?confirm=[0 or 1]
|
||||
Result: 204 if the user choses not to delete the account
|
||||
200 if successfully deleted
|
||||
*/
|
||||
func apiAccountDelete(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
if confirm, _ := strconv.ParseBool(r.Form.Get("confirm")); !confirm {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
core.DeleteAccount()
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user