Skip to content

Commit 4152596

Browse files
committed
UltraCheese
1 parent f1ff81d commit 4152596

File tree

214 files changed

+11518
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+11518
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import http from '@/api/http';
2+
import { ApiKey, rawDataToApiKey } from '@/api/account/getApiKeys';
3+
4+
export default (description: string, allowedIps: string): Promise<ApiKey & { secretToken: string }> => {
5+
return new Promise((resolve, reject) => {
6+
http.post('/api/client/account/api-keys', {
7+
description,
8+
allowed_ips: allowedIps.length > 0 ? allowedIps.split('\n') : [],
9+
})
10+
.then(({ data }) => resolve({
11+
...rawDataToApiKey(data.attributes),
12+
// eslint-disable-next-line camelcase
13+
secretToken: data.meta?.secret_token ?? '',
14+
}))
15+
.catch(reject);
16+
});
17+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import http from '@/api/http';
2+
3+
export default (identifier: string): Promise<void> => {
4+
return new Promise((resolve, reject) => {
5+
http.delete(`/api/client/account/api-keys/${identifier}`)
6+
.then(() => resolve())
7+
.catch(reject);
8+
});
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import http from '@/api/http';
2+
3+
export default (password: string): Promise<void> => {
4+
return new Promise((resolve, reject) => {
5+
http.delete('/api/client/account/two-factor', { params: { password } })
6+
.then(() => resolve())
7+
.catch(reject);
8+
});
9+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import http from '@/api/http';
2+
3+
export default async (code: string): Promise<string[]> => {
4+
const { data } = await http.post('/api/client/account/two-factor', { code });
5+
6+
return data.attributes.tokens;
7+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import http from '@/api/http';
2+
3+
export interface ApiKey {
4+
identifier: string;
5+
description: string;
6+
allowedIps: string[];
7+
createdAt: Date | null;
8+
lastUsedAt: Date | null;
9+
}
10+
11+
export const rawDataToApiKey = (data: any): ApiKey => ({
12+
identifier: data.identifier,
13+
description: data.description,
14+
allowedIps: data.allowed_ips,
15+
createdAt: data.created_at ? new Date(data.created_at) : null,
16+
lastUsedAt: data.last_used_at ? new Date(data.last_used_at) : null,
17+
});
18+
19+
export default (): Promise<ApiKey[]> => {
20+
return new Promise((resolve, reject) => {
21+
http.get('/api/client/account/api-keys')
22+
.then(({ data }) => resolve((data.data || []).map((d: any) => rawDataToApiKey(d.attributes))))
23+
.catch(reject);
24+
});
25+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import http from '@/api/http';
2+
3+
export default (): Promise<string> => {
4+
return new Promise((resolve, reject) => {
5+
http.get('/api/client/account/two-factor')
6+
.then(({ data }) => resolve(data.data.image_url_data))
7+
.catch(reject);
8+
});
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import http from '@/api/http';
2+
3+
export default (email: string, password: string): Promise<void> => {
4+
return new Promise((resolve, reject) => {
5+
http.put('/api/client/account/email', { email, password })
6+
.then(() => resolve())
7+
.catch(reject);
8+
});
9+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import http from '@/api/http';
2+
3+
interface Data {
4+
current: string;
5+
password: string;
6+
confirmPassword: string;
7+
}
8+
9+
export default ({ current, password, confirmPassword }: Data): Promise<void> => {
10+
return new Promise((resolve, reject) => {
11+
http.put('/api/client/account/password', {
12+
current_password: current,
13+
password: password,
14+
password_confirmation: confirmPassword,
15+
})
16+
.then(() => resolve())
17+
.catch(reject);
18+
});
19+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import http from '@/api/http';
2+
3+
export interface LoginResponse {
4+
complete: boolean;
5+
intended?: string;
6+
confirmationToken?: string;
7+
}
8+
9+
export interface LoginData {
10+
username: string;
11+
password: string;
12+
recaptchaData?: string | null;
13+
}
14+
15+
export default ({ username, password, recaptchaData }: LoginData): Promise<LoginResponse> => {
16+
return new Promise((resolve, reject) => {
17+
http.post('/auth/login', {
18+
user: username,
19+
password,
20+
'g-recaptcha-response': recaptchaData,
21+
})
22+
.then(response => {
23+
if (!(response.data instanceof Object)) {
24+
return reject(new Error('An error occurred while processing the login request.'));
25+
}
26+
27+
return resolve({
28+
complete: response.data.data.complete,
29+
intended: response.data.data.intended || undefined,
30+
confirmationToken: response.data.data.confirmation_token || undefined,
31+
});
32+
})
33+
.catch(reject);
34+
});
35+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import http from '@/api/http';
2+
import { LoginResponse } from '@/api/auth/login';
3+
4+
export default (token: string, code: string, recoveryToken?: string): Promise<LoginResponse> => {
5+
return new Promise((resolve, reject) => {
6+
http.post('/auth/login/checkpoint', {
7+
confirmation_token: token,
8+
authentication_code: code,
9+
recovery_token: (recoveryToken && recoveryToken.length > 0) ? recoveryToken : undefined,
10+
})
11+
.then(response => resolve({
12+
complete: response.data.data.complete,
13+
intended: response.data.data.intended || undefined,
14+
}))
15+
.catch(reject);
16+
});
17+
};

0 commit comments

Comments
 (0)