mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
adding admin account reset
This commit is contained in:
parent
e25b95277c
commit
9af758a82b
@ -33,8 +33,4 @@ func RemoveNodeAccount(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func SetNodeAccount(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
|
@ -8,12 +8,17 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"databag/internal/store"
|
||||
"encoding/base64"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func GetAccountListingImage(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// get referenced account guid
|
||||
params := mux.Vars(r)
|
||||
guid := params["guid"]
|
||||
|
||||
var account store.Account
|
||||
if err := store.DB.Preload("AccountDetail").Where("searchable = ? AND disabled = ?", true, false).First(&account).Error; err != nil {
|
||||
if err := store.DB.Preload("AccountDetail").Where("guid = ? AND searchable = ? AND disabled = ?", guid, true, false).First(&account).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
ErrResponse(w, http.StatusNotFound, err)
|
||||
} else {
|
||||
|
49
net/server/internal/api_setNodeAccount.go
Normal file
49
net/server/internal/api_setNodeAccount.go
Normal file
@ -0,0 +1,49 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"encoding/hex"
|
||||
"time"
|
||||
"strconv"
|
||||
"github.com/gorilla/mux"
|
||||
"databag/internal/store"
|
||||
"github.com/theckman/go-securerandom"
|
||||
)
|
||||
|
||||
func SetNodeAccount(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// get referenced account id
|
||||
params := mux.Vars(r)
|
||||
accountId, res := strconv.ParseUint(params["accountId"], 10, 32)
|
||||
if res != nil {
|
||||
ErrResponse(w, http.StatusBadRequest, res)
|
||||
return
|
||||
}
|
||||
|
||||
if res = AdminLogin(r); res != nil {
|
||||
ErrResponse(w, http.StatusUnauthorized, res)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := securerandom.Bytes(APP_RESETSIZE)
|
||||
if err != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
token := hex.EncodeToString(data)
|
||||
|
||||
accountToken := store.AccountToken{
|
||||
TokenType: APP_TOKENRESET,
|
||||
Token: token,
|
||||
AccountID: uint(accountId),
|
||||
Expires: time.Now().Unix() + APP_CREATEEXPIRE,
|
||||
};
|
||||
|
||||
if err := store.DB.Create(&accountToken).Error; err != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
WriteResponse(w, token);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user