Create and delete tokens from web ui
This commit is contained in:
@ -6,7 +6,11 @@ export interface ServerConfig {
|
||||
constraints: ServerConstraints;
|
||||
}
|
||||
|
||||
export interface ServerConstraints {}
|
||||
export interface ServerConstraints {
|
||||
token_name: LenConstraint;
|
||||
token_ip_net: LenConstraint;
|
||||
token_max_inactivity: LenConstraint;
|
||||
}
|
||||
|
||||
export interface LenConstraint {
|
||||
min: number;
|
||||
|
70
moneymgr_web/src/api/TokensApi.ts
Normal file
70
moneymgr_web/src/api/TokensApi.ts
Normal file
@ -0,0 +1,70 @@
|
||||
import { APIClient } from "./ApiClient";
|
||||
|
||||
export interface Token {
|
||||
id: number;
|
||||
name: string;
|
||||
time_create: number;
|
||||
user_id: number;
|
||||
time_used: number;
|
||||
max_inactivity: number;
|
||||
ip_net?: string;
|
||||
read_only: boolean;
|
||||
right_account: boolean;
|
||||
right_movement: boolean;
|
||||
right_inbox: boolean;
|
||||
right_attachment: boolean;
|
||||
right_auth: boolean;
|
||||
}
|
||||
|
||||
export interface TokenWithSecret extends Token {
|
||||
token: string;
|
||||
}
|
||||
|
||||
export interface NewToken {
|
||||
name: string;
|
||||
ip_net?: string;
|
||||
max_inactivity: number;
|
||||
read_only: boolean;
|
||||
right_account: boolean;
|
||||
right_movement: boolean;
|
||||
right_inbox: boolean;
|
||||
right_attachment: boolean;
|
||||
right_auth: boolean;
|
||||
}
|
||||
|
||||
export class TokensApi {
|
||||
/**
|
||||
* Get the list of tokens of the current user
|
||||
*/
|
||||
static async GetList(): Promise<Token[]> {
|
||||
return (
|
||||
await APIClient.exec({
|
||||
uri: "/tokens/list",
|
||||
method: "GET",
|
||||
})
|
||||
).data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new token
|
||||
*/
|
||||
static async Create(t: NewToken): Promise<TokenWithSecret> {
|
||||
return (
|
||||
await APIClient.exec({
|
||||
uri: "/tokens",
|
||||
method: "POST",
|
||||
jsonData: t,
|
||||
})
|
||||
).data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a token
|
||||
*/
|
||||
static async Delete(t: Token): Promise<void> {
|
||||
await APIClient.exec({
|
||||
uri: `/tokens/${t.id}`,
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user