accounts-frontend/packages/app/services/api/accounts.ts

94 lines
2.5 KiB
TypeScript
Raw Normal View History

import request from 'app/services/request';
2019-12-07 16:58:52 +05:30
export interface UserResponse {
2020-05-24 04:38:24 +05:30
elyProfileLink: string;
email: string;
hasMojangUsernameCollision: boolean;
id: number;
isActive: boolean;
isOtpEnabled: boolean;
isDeleted: boolean;
2020-05-24 04:38:24 +05:30
lang: string;
passwordChangedAt: number; // timestamp
registeredAt: number; // timestamp
shouldAcceptRules: boolean;
username: string;
uuid: string;
2019-12-07 16:58:52 +05:30
}
export function getInfo(id: number, token?: string): Promise<UserResponse> {
return request.get(`/api/v1/accounts/${id}`, {}, { token });
}
export function changePassword(
2020-05-24 04:38:24 +05:30
id: number,
{
password = '',
newPassword = '',
newRePassword = '',
logoutAll = true,
}: {
password?: string;
newPassword?: string;
newRePassword?: string;
logoutAll?: boolean;
},
): Promise<{ success: boolean }> {
2020-05-24 04:38:24 +05:30
return request.post(`/api/v1/accounts/${id}/password`, {
password,
newPassword,
newRePassword,
logoutAll,
});
}
export function acceptRules(id: number): Promise<{ success: boolean }> {
2020-05-24 04:38:24 +05:30
return request.post(`/api/v1/accounts/${id}/rules`);
}
export function changeUsername(
2020-05-24 04:38:24 +05:30
id: number,
username: string | void,
password: string | void,
): Promise<{ success: boolean }> {
2020-05-24 04:38:24 +05:30
return request.post(`/api/v1/accounts/${id}/username`, {
username,
password,
});
}
2020-05-24 04:38:24 +05:30
export function changeLang(id: number, lang: string): Promise<{ success: boolean }> {
return request.post(`/api/v1/accounts/${id}/language`, {
lang,
});
}
2020-05-24 04:38:24 +05:30
export function requestEmailChange(id: number, password: string): Promise<{ success: boolean }> {
return request.post(`/api/v1/accounts/${id}/email-verification`, {
password,
});
}
2020-05-24 04:38:24 +05:30
export function setNewEmail(id: number, email: string, key: string): Promise<{ success: boolean }> {
return request.post(`/api/v1/accounts/${id}/new-email-verification`, {
email,
key,
});
}
2020-05-24 04:38:24 +05:30
export function confirmNewEmail(id: number, key: string): Promise<{ success: boolean }> {
return request.post(`/api/v1/accounts/${id}/email`, {
key,
});
}
export function deleteAccount(id: number, { password }: { password?: string }): Promise<{ success: boolean }> {
return request.delete(`/api/v1/accounts/${id}`, {
password,
});
}
export function restoreAccount(id: number): Promise<{ success: boolean }> {
return request.post(`/api/v1/accounts/${id}/restore`);
}