mirror of
https://github.com/balzack/databag.git
synced 2025-02-11 19:19:16 +00:00
adding admin listing of accounts
This commit is contained in:
parent
9af758a82b
commit
3a0409c002
48
doc/api.oa3
48
doc/api.oa3
@ -130,7 +130,7 @@ paths:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Account'
|
||||
$ref: '#/components/schemas/AccountProfile'
|
||||
'401':
|
||||
description: invalid password
|
||||
'404':
|
||||
@ -156,6 +156,36 @@ paths:
|
||||
'500':
|
||||
description: internal server error
|
||||
|
||||
/admin/accounts/{accountId}/image:
|
||||
get:
|
||||
tags:
|
||||
- admin
|
||||
description: Get profile image of node account.
|
||||
operationId: get-node-account-image
|
||||
security:
|
||||
- basicAuth: []
|
||||
parameters:
|
||||
- name: accountId
|
||||
in: path
|
||||
description: id of account to delete
|
||||
required: true
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
content:
|
||||
application/octet-stream: # content specific
|
||||
schema:
|
||||
type: string
|
||||
format: binary
|
||||
'401':
|
||||
description: invalid authentication
|
||||
'404':
|
||||
description: account not found
|
||||
'500':
|
||||
description: internal server error
|
||||
|
||||
/admin/accounts/{accountId}/reset:
|
||||
put:
|
||||
tags:
|
||||
@ -3006,13 +3036,23 @@ components:
|
||||
type: object
|
||||
required:
|
||||
- accountId
|
||||
- profile
|
||||
- disabled
|
||||
properties:
|
||||
accountId:
|
||||
type: integer
|
||||
format: uint32
|
||||
guid:
|
||||
type: string
|
||||
profile:
|
||||
$ref: '#/components/schemas/Profile'
|
||||
handle:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
location:
|
||||
type: string
|
||||
imageSet:
|
||||
type: boolean
|
||||
disabled:
|
||||
type: boolean
|
||||
|
||||
|
@ -13,16 +13,6 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetNodeAccountImage(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func GetNodeAccounts(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func ImportAccount(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
54
net/server/internal/api_getNodeAccountImage.go
Normal file
54
net/server/internal/api_getNodeAccountImage.go
Normal file
@ -0,0 +1,54 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"time"
|
||||
"strconv"
|
||||
"gorm.io/gorm"
|
||||
"bytes"
|
||||
"errors"
|
||||
"encoding/base64"
|
||||
"net/http"
|
||||
"databag/internal/store"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func GetNodeAccountImage(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 err := AdminLogin(r); err != nil {
|
||||
ErrResponse(w, http.StatusUnauthorized, err)
|
||||
return
|
||||
}
|
||||
|
||||
var account store.Account
|
||||
if err := store.DB.Preload("AccountDetail").First(&account, uint(accountId)).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
ErrResponse(w, http.StatusNotFound, err)
|
||||
} else {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if account.AccountDetail.Image == "" {
|
||||
ErrResponse(w, http.StatusNotFound, errors.New("iamge not set"))
|
||||
return
|
||||
}
|
||||
|
||||
data, err := base64.StdEncoding.DecodeString(account.AccountDetail.Image)
|
||||
if err != nil {
|
||||
ErrResponse(w, http.StatusNotFound, errors.New("image not valid"))
|
||||
return
|
||||
}
|
||||
|
||||
// response with content
|
||||
http.ServeContent(w, r, "image", time.Unix(account.Updated, 0), bytes.NewReader(data))
|
||||
}
|
||||
|
37
net/server/internal/api_getNodeAccounts.go
Normal file
37
net/server/internal/api_getNodeAccounts.go
Normal file
@ -0,0 +1,37 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"databag/internal/store"
|
||||
)
|
||||
|
||||
func GetNodeAccounts(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if err := AdminLogin(r); err != nil {
|
||||
ErrResponse(w, http.StatusUnauthorized, err)
|
||||
return
|
||||
}
|
||||
|
||||
var accounts []store.Account
|
||||
if err := store.DB.Preload("AccountDetail").Find(&accounts).Error; err != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
profiles := []AccountProfile{}
|
||||
for _, account := range accounts {
|
||||
profiles = append(profiles, AccountProfile{
|
||||
AccountId: uint32(account.ID),
|
||||
Guid: account.Guid,
|
||||
Handle: account.Username,
|
||||
Name: account.AccountDetail.Name,
|
||||
Description: account.AccountDetail.Description,
|
||||
Location: account.AccountDetail.Location,
|
||||
ImageSet: account.AccountDetail.Image != "",
|
||||
Disabled: account.Disabled,
|
||||
})
|
||||
}
|
||||
|
||||
WriteResponse(w, &profiles);
|
||||
}
|
||||
|
@ -1,14 +1,20 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
//"os"
|
||||
)
|
||||
type AccountProfile struct {
|
||||
|
||||
type Account struct {
|
||||
AccountId uint32 `json:"accountId"`
|
||||
|
||||
AccountId string `json:"accountId"`
|
||||
Guid string `json:"guid"`
|
||||
|
||||
Profile *Profile `json:"profile"`
|
||||
Handle string `json:"handle,omitempty"`
|
||||
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
Location string `json:"location,omitempty"`
|
||||
|
||||
ImageSet bool `json:"imageSet,omitempty"`
|
||||
|
||||
Disabled bool `json:"disabled"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user