From d8480f86f66f35350a1599727ff8832fc5e83005 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Thu, 12 Sep 2024 16:49:54 -0700 Subject: [PATCH] adding clear seal endpoint --- net/server/internal/api_clearAccountSeal.go | 44 +++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 net/server/internal/api_clearAccountSeal.go diff --git a/net/server/internal/api_clearAccountSeal.go b/net/server/internal/api_clearAccountSeal.go new file mode 100644 index 00000000..14b9cdb6 --- /dev/null +++ b/net/server/internal/api_clearAccountSeal.go @@ -0,0 +1,44 @@ +package databag + +import ( + "databag/internal/store" + "gorm.io/gorm" + "net/http" +) + +//ClearAccountSeal sets sealing key for channels +func ClearAccountSeal(w http.ResponseWriter, r *http.Request) { + + account, code, err := ParamAgentToken(r, true) + if err != nil { + ErrResponse(w, code, err) + return + } + + // update record + account.AccountDetail.SealSalt = "" + account.AccountDetail.SealIV = "" + account.AccountDetail.SealPrivate = "" + account.AccountDetail.SealPublic = "" + + err = store.DB.Transaction(func(tx *gorm.DB) error { + if res := tx.Save(&account.AccountDetail).Error; res != nil { + return res + } + if res := tx.Model(&account).Update("profile_revision", account.ProfileRevision+1).Error; res != nil { + return res + } + if res := tx.Model(&account).Update("account_revision", account.AccountRevision+1).Error; res != nil { + return res + } + return nil + }) + if err != nil { + ErrResponse(w, http.StatusInternalServerError, err) + return + } + + SetProfileNotification(account) + SetStatus(account) + WriteResponse(w, nil) +}