diff --git a/net/server/internal/api_addAccount.go b/net/server/internal/api_addAccount.go index d86aefd9..21e20bcc 100644 --- a/net/server/internal/api_addAccount.go +++ b/net/server/internal/api_addAccount.go @@ -12,8 +12,15 @@ import ( func AddAccount(w http.ResponseWriter, r *http.Request) { var token *store.AccountToken + var res error - if r.Header.Get("Authorization") == "" { + if r.FormValue("token") != "" { + token, _, res = AccessToken(r) + if res != nil || token.TokenType != APP_TOKENCREATE { + ErrResponse(w, http.StatusUnauthorized, res) + return + } + } else { if available, err := getAvailableAccounts(); err != nil { ErrResponse(w, http.StatusInternalServerError, err) return @@ -21,13 +28,6 @@ func AddAccount(w http.ResponseWriter, r *http.Request) { ErrResponse(w, http.StatusForbidden, errors.New("no open accounts available")) return } - } else { - var err error - token, err = BearerAccountToken(r); - if err != nil || token.TokenType != APP_TOKENCREATE { - ErrResponse(w, http.StatusUnauthorized, err) - return - } } username, password, ret := BasicCredentials(r); diff --git a/net/server/internal/api_getAccountUsername.go b/net/server/internal/api_getAccountUsername.go index c0855630..ed1d968c 100644 --- a/net/server/internal/api_getAccountUsername.go +++ b/net/server/internal/api_getAccountUsername.go @@ -11,21 +11,19 @@ type accountUsername struct { } func GetAccountUsername(w http.ResponseWriter, r *http.Request) { - var token *store.AccountToken - if r.Header.Get("Authorization") == "" { + if r.FormValue("token") != "" { + token, _, res := AccessToken(r) + if res != nil || token.TokenType != APP_TOKENCREATE { + ErrResponse(w, http.StatusUnauthorized, res) + return + } + } else { if available, err := getAvailableAccounts(); err != nil { ErrResponse(w, http.StatusInternalServerError, err) return } else if available == 0 { - ErrResponse(w, http.StatusUnauthorized, errors.New("no open accounts available")) - return - } - } else { - var err error - token, err = BearerAccountToken(r); - if err != nil || token.TokenType != APP_TOKENCREATE { - ErrResponse(w, http.StatusUnauthorized, err) + ErrResponse(w, http.StatusForbidden, errors.New("no open accounts available")) return } } diff --git a/net/server/internal/routers.go b/net/server/internal/routers.go index cd8261dd..daa9e899 100644 --- a/net/server/internal/routers.go +++ b/net/server/internal/routers.go @@ -34,7 +34,7 @@ func NewRouter() *mux.Router { Handler(handler) } - fs := http.FileServer(http.Dir("/data/databag/net/web/build/")) + fs := http.FileServer(http.Dir("/app/databag/net/web/build/")) router.PathPrefix("/").Handler(http.StripPrefix("/", fs)) return router diff --git a/net/web/src/Admin/Dashboard/AccountItem/AccountItem.jsx b/net/web/src/Admin/Dashboard/AccountItem/AccountItem.jsx index 38ef868a..7f15079c 100644 --- a/net/web/src/Admin/Dashboard/AccountItem/AccountItem.jsx +++ b/net/web/src/Admin/Dashboard/AccountItem/AccountItem.jsx @@ -45,7 +45,7 @@ export function AccountItem({ token, item, remove }) {
} - onClick={() => actions.setAccessLink()}> + loading={state.accessBusy} onClick={() => actions.setAccessLink()}> @@ -53,7 +53,7 @@ export function AccountItem({ token, item, remove }) { loading={state.removeBusy} onClick={() => actions.remove()}>
- actions.setShowAccess(false)}>OK ]} onCancel={() => actions.setShowAccess(false)}> diff --git a/net/web/src/Admin/Dashboard/AccountItem/useAccountItem.hook.js b/net/web/src/Admin/Dashboard/AccountItem/useAccountItem.hook.js index 81700fa2..59c44759 100644 --- a/net/web/src/Admin/Dashboard/AccountItem/useAccountItem.hook.js +++ b/net/web/src/Admin/Dashboard/AccountItem/useAccountItem.hook.js @@ -8,6 +8,7 @@ export function useAccountItem(token, item, remove) { const [state, setState] = useState({ statusBusy: false, removeBusy: false, + accessBusy: false, showAccess: false, }); @@ -29,8 +30,17 @@ export function useAccountItem(token, item, remove) { const actions = { setAccessLink: async () => { - let access = await addAccountAccess(token, item.accountId); - updateState({ accessToken: access, showAccess: true }); + if (!state.accessBusy) { + updateState({ accessBusy: true }); + try { + let access = await addAccountAccess(token, item.accountId); + updateState({ accessToken: access, showAccess: true }); + } + catch (err) { + window.alert(err); + } + updateState({ accessBusy: false }); + } }, setShowAccess: (showAccess) => { updateState({ showAccess }); diff --git a/net/web/src/Admin/Dashboard/Dashboard.jsx b/net/web/src/Admin/Dashboard/Dashboard.jsx index a200d73f..1a9fa496 100644 --- a/net/web/src/Admin/Dashboard/Dashboard.jsx +++ b/net/web/src/Admin/Dashboard/Dashboard.jsx @@ -1,6 +1,6 @@ -import { DashboardWrapper, SettingsButton, AddButton, SettingsLayout } from './Dashboard.styled'; +import { DashboardWrapper, SettingsButton, AddButton, SettingsLayout, CreateLayout } from './Dashboard.styled'; import { Tooltip, Button, Modal, Input, InputNumber, Space, List } from 'antd'; -import { SettingOutlined, UserAddOutlined, LogoutOutlined, ReloadOutlined } from '@ant-design/icons'; +import { SettingOutlined, CopyOutlined, UserAddOutlined, LogoutOutlined, ReloadOutlined } from '@ant-design/icons'; import { useDashboard } from './useDashboard.hook'; import { AccountItem } from './AccountItem/AccountItem'; @@ -8,6 +8,14 @@ export function Dashboard({ token, config, logout }) { const { state, actions } = useDashboard(token, config); + const onClipboard = (value) => { + navigator.clipboard.writeText(value); + }; + + const createLink = () => { + return window.location.origin + '/#/create?add=' + state.createToken; + }; + return ( @@ -34,7 +42,8 @@ export function Dashboard({ token, config, logout }) {
- }> + } + loading={state.createBusy} onClick={() => actions.setCreateLink()}>
@@ -60,13 +69,22 @@ export function Dashboard({ token, config, logout }) { value={state.host} />
-
Account Storage (GB): 
+
Storage Limit (GB) / Account: 
actions.setStorage(e)} placeholder="0 for unrestricted" value={state.storage} />
- + actions.setShowCreate(false)}>OK ]} + onCancel={() => actions.setShowCreate(false)}> + +
{createLink()}
+