mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
adding open access account config
This commit is contained in:
parent
1f7c2e9eb2
commit
54b9737cd6
32
doc/api.oa3
32
doc/api.oa3
@ -268,6 +268,30 @@ paths:
|
|||||||
format: binary
|
format: binary
|
||||||
|
|
||||||
/account/available:
|
/account/available:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- account
|
||||||
|
description: Check if any public accounts are available
|
||||||
|
operationId: get-account-available
|
||||||
|
parameters:
|
||||||
|
- name: public
|
||||||
|
in: query
|
||||||
|
description: for open access accounts
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: boolean
|
||||||
|
responses:
|
||||||
|
'200':
|
||||||
|
description: available public accounts
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: integer
|
||||||
|
format: uint32
|
||||||
|
'500':
|
||||||
|
description: internal server error
|
||||||
|
|
||||||
|
/account/username:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
- account
|
- account
|
||||||
@ -2963,7 +2987,8 @@ components:
|
|||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
- domain
|
- domain
|
||||||
- publicLimit
|
- openAccess
|
||||||
|
- accountLimit
|
||||||
- accountStorage
|
- accountStorage
|
||||||
properties:
|
properties:
|
||||||
domain:
|
domain:
|
||||||
@ -2971,6 +2996,11 @@ components:
|
|||||||
accountStorage:
|
accountStorage:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
format: int64
|
||||||
|
openAccess
|
||||||
|
type: boolean
|
||||||
|
accountLimit
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
|
||||||
AccountStatus:
|
AccountStatus:
|
||||||
type: object
|
type: object
|
||||||
|
27
net/server/internal/api_getAccountAvailable.go
Normal file
27
net/server/internal/api_getAccountAvailable.go
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package databag
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"databag/internal/store"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetAccountAvailable(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
public := r.FormValue("public") == "true"
|
||||||
|
open := getBoolConfigValue(CONFIG_OPENACCESS, true)
|
||||||
|
limit := getNumConfigValue(CONFIG_ACCOUNTLIMIT, 16)
|
||||||
|
|
||||||
|
var count int64
|
||||||
|
if err := store.DB.Model(&store.Account{}).Count(&count).Error; err != nil {
|
||||||
|
ErrResponse(w, http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var available int64
|
||||||
|
if (!public || open) && limit > count {
|
||||||
|
available = limit - count
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteResponse(w, &available)
|
||||||
|
}
|
||||||
|
|
@ -15,7 +15,8 @@ func GetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
// get node config fields
|
// get node config fields
|
||||||
var config NodeConfig;
|
var config NodeConfig;
|
||||||
config.Domain = getStrConfigValue(CONFIG_DOMAIN, "");
|
config.Domain = getStrConfigValue(CONFIG_DOMAIN, "");
|
||||||
config.PublicLimit = getNumConfigValue(CONFIG_PUBLICLIMIT, 0);
|
config.AccountLimit = getNumConfigValue(CONFIG_ACCOUNTLIMIT, 16);
|
||||||
|
config.OpenAccess = getBoolConfigValue(CONFIG_OPENACCESS, true);
|
||||||
config.AccountStorage = getNumConfigValue(CONFIG_STORAGE, 0);
|
config.AccountStorage = getNumConfigValue(CONFIG_STORAGE, 0);
|
||||||
|
|
||||||
WriteResponse(w, config);
|
WriteResponse(w, config);
|
||||||
|
@ -33,11 +33,19 @@ func SetNodeConfig(w http.ResponseWriter, r *http.Request) {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// upsert public limit config
|
// upsert account limit config
|
||||||
if res := tx.Clauses(clause.OnConflict{
|
if res := tx.Clauses(clause.OnConflict{
|
||||||
Columns: []clause.Column{{Name: "config_id"}},
|
Columns: []clause.Column{{Name: "config_id"}},
|
||||||
DoUpdates: clause.AssignmentColumns([]string{"num_value"}),
|
DoUpdates: clause.AssignmentColumns([]string{"num_value"}),
|
||||||
}).Create(&store.Config{ConfigId: CONFIG_PUBLICLIMIT, NumValue: config.PublicLimit}).Error; res != nil {
|
}).Create(&store.Config{ConfigId: CONFIG_ACCOUNTLIMIT, NumValue: config.AccountLimit}).Error; res != nil {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
// upsert account open access
|
||||||
|
if res := tx.Clauses(clause.OnConflict{
|
||||||
|
Columns: []clause.Column{{Name: "config_id"}},
|
||||||
|
DoUpdates: clause.AssignmentColumns([]string{"bool_value"}),
|
||||||
|
}).Create(&store.Config{ConfigId: CONFIG_ACCOUNTLIMIT, BoolValue: config.OpenAccess}).Error; res != nil {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,11 +6,12 @@ import (
|
|||||||
"databag/internal/store"
|
"databag/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const CONFIG_OPENACCESS = "open_access"
|
||||||
|
const CONFIG_ACCOUNTLIMIT = "account_limit"
|
||||||
const CONFIG_CONFIGURED = "configured"
|
const CONFIG_CONFIGURED = "configured"
|
||||||
const CONFIG_USERNAME = "username"
|
const CONFIG_USERNAME = "username"
|
||||||
const CONFIG_PASSWORD = "password"
|
const CONFIG_PASSWORD = "password"
|
||||||
const CONFIG_DOMAIN = "domain"
|
const CONFIG_DOMAIN = "domain"
|
||||||
const CONFIG_PUBLICLIMIT = "public_limit"
|
|
||||||
const CONFIG_STORAGE = "storage"
|
const CONFIG_STORAGE = "storage"
|
||||||
const CONFIG_ASSETPATH = "asset_path"
|
const CONFIG_ASSETPATH = "asset_path"
|
||||||
const CONFIG_SCRIPTPATH = "script_path"
|
const CONFIG_SCRIPTPATH = "script_path"
|
||||||
|
@ -54,7 +54,7 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// config server
|
// config server
|
||||||
config := NodeConfig{Domain: "example.com", PublicLimit: 1024, AccountStorage: 4096}
|
config := NodeConfig{Domain: "example.com", AccountLimit: 1024, OpenAccess: true, AccountStorage: 4096}
|
||||||
r, w, _ = NewRequest("PUT", "/admin/config", &config)
|
r, w, _ = NewRequest("PUT", "/admin/config", &config)
|
||||||
SetBasicAuth(r, "admin:pass")
|
SetBasicAuth(r, "admin:pass")
|
||||||
SetNodeConfig(w, r)
|
SetNodeConfig(w, r)
|
||||||
@ -73,8 +73,11 @@ func TestMain(m *testing.M) {
|
|||||||
if check.Domain != "example.com" {
|
if check.Domain != "example.com" {
|
||||||
panic("failed to set config domain");
|
panic("failed to set config domain");
|
||||||
}
|
}
|
||||||
if check.PublicLimit != 1024 {
|
if check.AccountLimit != 1024 {
|
||||||
panic("failed to set public limit");
|
panic("failed to set account limit");
|
||||||
|
}
|
||||||
|
if check.OpenAccess != true {
|
||||||
|
panic("failed to set open access");
|
||||||
}
|
}
|
||||||
if check.AccountStorage != 4096 {
|
if check.AccountStorage != 4096 {
|
||||||
panic("failed to set account storage");
|
panic("failed to set account storage");
|
||||||
|
@ -322,7 +322,9 @@ type NodeConfig struct {
|
|||||||
|
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
|
|
||||||
PublicLimit int64 `json:"publicLimit"`
|
OpenAccess bool `json:"openAccess"`
|
||||||
|
|
||||||
|
AccountLimit int64 `json:"accountLimit"`
|
||||||
|
|
||||||
AccountStorage int64 `json:"accountStorage"`
|
AccountStorage int64 `json:"accountStorage"`
|
||||||
}
|
}
|
||||||
|
@ -119,9 +119,16 @@ var routes = Routes{
|
|||||||
},
|
},
|
||||||
|
|
||||||
Route{
|
Route{
|
||||||
"GetAccountUsername",
|
"GetAccountAvailable",
|
||||||
strings.ToUpper("Get"),
|
strings.ToUpper("Get"),
|
||||||
"/account/available",
|
"/account/available",
|
||||||
|
GetAccountAvailable,
|
||||||
|
},
|
||||||
|
|
||||||
|
Route{
|
||||||
|
"GetAccountUsername",
|
||||||
|
strings.ToUpper("Get"),
|
||||||
|
"/account/username",
|
||||||
GetAccountUsername,
|
GetAccountUsername,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -22,14 +22,14 @@ function App() {
|
|||||||
<div style={{ width: '100%', height: '100vh', backgroundColor: '#8fbea7' }}>
|
<div style={{ width: '100%', height: '100vh', backgroundColor: '#8fbea7' }}>
|
||||||
<img src={login} style={{ position: 'absolute', width: '33%', bottom: 0, right: 0 }}/>
|
<img src={login} style={{ position: 'absolute', width: '33%', bottom: 0, right: 0 }}/>
|
||||||
<div style={{ position: 'absolute', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', top: 0, left: 0, width: '100%', height: '67%' }}>
|
<div style={{ position: 'absolute', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', top: 0, left: 0, width: '100%', height: '67%' }}>
|
||||||
<div style={{ backgroundColor: '#ffffff', display: 'flex', flexDirection: 'column', padding: '16px', borderRadius: '8px' }}>
|
<div style={{ backgroundColor: '#ffffff', display: 'flex', flexDirection: 'column', padding: '16px', borderRadius: '8px', width: '500px' }}>
|
||||||
<div style={{ textAlign: 'center', fontSize: '24px', fontWeight: 'bold', color: '#555555' }}>indicom</div>
|
<div style={{ textAlign: 'center', fontSize: '24px', fontWeight: 'bold', color: '#555555' }}>indicom</div>
|
||||||
<div style={{ fontSize: '12px', borderBottom: '1px solid black', color: '#444444', paddingLeft: '16px', paddingRight: '16px' }}>
|
<div style={{ fontSize: '12px', display: 'flex', borderBottom: '1px solid black', color: '#444444', paddingLeft: '16px', paddingRight: '16px' }}>
|
||||||
<span>Communication for the Decentralized Web</span>
|
<span style={{ textAlign: 'center', width: '100%' }}>Communication for the Decentralized Web</span>
|
||||||
</div>
|
</div>
|
||||||
<Input size="large" onChange={(e) => setUsername(e.target.value)} placeholder="username" prefix={<UserOutlined />} style={{ marginTop: '16px' }} />
|
<Input size="large" onChange={(e) => setUsername(e.target.value)} placeholder="username" prefix={<UserOutlined />} style={{ marginTop: '16px' }} />
|
||||||
<Input.Password size="large" onChange={(e) => setPassword(e.target.value)} placeholder="password" prefix={<LockOutlined />} style={{ marginTop: '16px' }} />
|
<Input.Password size="large" onChange={(e) => setPassword(e.target.value)} placeholder="password" prefix={<LockOutlined />} style={{ marginTop: '16px' }} />
|
||||||
<Button type="primary" onClick={onLogin} style={{ marginTop: '16px' }}>Sign In</Button>
|
<Button type="primary" onClick={onLogin} style={{ alignSelf: 'center', marginTop: '16px', width: '33%' }}>Sign In</Button>
|
||||||
</div>
|
</div>
|
||||||
<Button type="link" onClick={onCreate} style={{ marginTop: '4px', color: '#000044' }}>Create Account</Button>
|
<Button type="link" onClick={onCreate} style={{ marginTop: '4px', color: '#000044' }}>Create Account</Button>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user