mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
chaning code layout
This commit is contained in:
parent
c3b142fcba
commit
660d83e3bd
41
net/server/internal/addNodeAccount.endpoint.go
Normal file
41
net/server/internal/addNodeAccount.endpoint.go
Normal file
@ -0,0 +1,41 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"log"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"databag/internal/store"
|
||||
"github.com/theckman/go-securerandom"
|
||||
)
|
||||
|
||||
func AddNodeAccount(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// validate login
|
||||
if !adminLogin(r) {
|
||||
log.Printf("AddNodeAccount - invalid admin credentials");
|
||||
w.WriteHeader(http.StatusUnauthorized);
|
||||
return
|
||||
}
|
||||
|
||||
data, err := securerandom.Base64OfBytes(32)
|
||||
if err != nil {
|
||||
log.Println("AddNodeAccount - failed to generate token");
|
||||
w.WriteHeader(http.StatusInternalServerError);
|
||||
return
|
||||
}
|
||||
|
||||
token := store.AccountToken{TokenType: "create", Token: data };
|
||||
if res := store.DB.Create(&token).Error; res != nil {
|
||||
log.Println("AddNodeAccount - failed to store token");
|
||||
return
|
||||
}
|
||||
|
||||
body, err := json.Marshal(data);
|
||||
if err != nil {
|
||||
log.Println("GetNodeConfig - failed to marshal response");
|
||||
}
|
||||
w.Write(body)
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"databag/internal/store"
|
||||
"github.com/theckman/go-securerandom"
|
||||
)
|
||||
|
||||
func adminLogin(r *http.Request) bool {
|
||||
@ -46,37 +45,6 @@ func adminLogin(r *http.Request) bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
func AddNodeAccount(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// validate login
|
||||
if !adminLogin(r) {
|
||||
log.Printf("AddNodeAccount - invalid admin credentials");
|
||||
w.WriteHeader(http.StatusUnauthorized);
|
||||
return
|
||||
}
|
||||
|
||||
data, err := securerandom.Base64OfBytes(32)
|
||||
if err != nil {
|
||||
log.Println("AddNodeAccount - failed to generate token");
|
||||
w.WriteHeader(http.StatusInternalServerError);
|
||||
return
|
||||
}
|
||||
|
||||
token := store.AccountToken{TokenType: "create", Token: data };
|
||||
if res := store.DB.Create(&token).Error; res != nil {
|
||||
log.Println("AddNodeAccount - failed to store token");
|
||||
return
|
||||
}
|
||||
|
||||
body, err := json.Marshal(data);
|
||||
if err != nil {
|
||||
log.Println("GetNodeConfig - failed to marshal response");
|
||||
}
|
||||
w.Write(body)
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func GetNodeAccountImage(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* DataBag
|
||||
*
|
||||
* DataBag provides storage for decentralized identity based self-hosting apps. It is intended to support sharing of personal data and hosting group conversations.
|
||||
*
|
||||
* API version: 0.0.1
|
||||
* Contact: roland.osborne@gmail.com
|
||||
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||
*/
|
||||
package databag
|
||||
|
||||
type Account struct {
|
||||
|
||||
AccountId string `json:"accountId"`
|
||||
|
||||
Profile *Profile `json:"profile"`
|
||||
|
||||
Disabled bool `json:"disabled"`
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* DataBag
|
||||
*
|
||||
* DataBag provides storage for decentralized identity based self-hosting apps. It is intended to support sharing of personal data and hosting group conversations.
|
||||
*
|
||||
* API version: 0.0.1
|
||||
* Contact: roland.osborne@gmail.com
|
||||
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||
*/
|
||||
package databag
|
||||
|
||||
type AccountStatus struct {
|
||||
|
||||
Disabled bool `json:"disabled"`
|
||||
|
||||
StorageUsed float64 `json:"storageUsed"`
|
||||
|
||||
StorageAvailable float64 `json:"storageAvailable"`
|
||||
|
||||
ForwardingAddress string `json:"forwardingAddress"`
|
||||
}
|
||||
|
15
net/server/internal/models.go
Normal file
15
net/server/internal/models.go
Normal file
@ -0,0 +1,15 @@
|
||||
package databag
|
||||
|
||||
type Account struct {
|
||||
AccountId string `json:"accountId"`
|
||||
Profile *Profile `json:"profile"`
|
||||
Disabled bool `json:"disabled"`
|
||||
}
|
||||
|
||||
type AccountStatus struct {
|
||||
Disabled bool `json:"disabled"`
|
||||
StorageUsed float64 `json:"storageUsed"`
|
||||
StorageAvailable float64 `json:"storageAvailable"`
|
||||
ForwardingAddress string `json:"forwardingAddress"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user