2017-12-26 01:33:21 +05:30
|
|
|
// @flow
|
2016-05-01 15:58:54 +05:30
|
|
|
import request from 'services/request';
|
|
|
|
|
2019-01-25 22:59:32 +05:30
|
|
|
export type UserResponse = {
|
2017-12-26 01:33:21 +05:30
|
|
|
elyProfileLink: string,
|
|
|
|
email: string,
|
|
|
|
hasMojangUsernameCollision: bool,
|
|
|
|
id: number,
|
|
|
|
isActive: bool,
|
|
|
|
isOtpEnabled: bool,
|
|
|
|
lang: string,
|
|
|
|
passwordChangedAt: number, // timestamp
|
|
|
|
registeredAt: number, // timestamp
|
|
|
|
shouldAcceptRules: bool,
|
|
|
|
username: string,
|
|
|
|
uuid: string,
|
|
|
|
};
|
|
|
|
|
2019-01-25 22:59:32 +05:30
|
|
|
export function getInfo(id: number, options: { token?: ?string } = {}): Promise<UserResponse> {
|
|
|
|
return request.get(`/api/v1/accounts/${id}`, {}, {
|
|
|
|
token: options.token,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function changePassword({
|
|
|
|
password = '',
|
|
|
|
newPassword = '',
|
|
|
|
newRePassword = '',
|
|
|
|
logoutAll = true,
|
|
|
|
}: {
|
|
|
|
password?: string,
|
|
|
|
newPassword?: string,
|
|
|
|
newRePassword?: string,
|
|
|
|
logoutAll?: bool,
|
|
|
|
}) {
|
|
|
|
return request.post('/api/accounts/change-password', {
|
|
|
|
password,
|
|
|
|
newPassword,
|
|
|
|
newRePassword,
|
|
|
|
logoutAll,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function acceptRules() {
|
|
|
|
return request.post('/api/accounts/accept-rules');
|
|
|
|
}
|
|
|
|
|
|
|
|
export function changeUsername({
|
|
|
|
username = '',
|
|
|
|
password = '',
|
|
|
|
}: {
|
|
|
|
username?: string,
|
|
|
|
password?: string,
|
|
|
|
}) {
|
|
|
|
return request.post('/api/accounts/change-username', {
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function changeLang(lang: string) {
|
|
|
|
return request.post('/api/accounts/change-lang', {
|
|
|
|
lang,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function requestEmailChange({ password = '' }: { password?: string }) {
|
|
|
|
return request.post('/api/accounts/change-email/initialize', {
|
|
|
|
password,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setNewEmail({
|
|
|
|
email = '',
|
|
|
|
key = '',
|
|
|
|
}: {
|
|
|
|
email?: string,
|
|
|
|
key?: string,
|
|
|
|
}) {
|
|
|
|
return request.post('/api/accounts/change-email/submit-new-email', {
|
|
|
|
email,
|
|
|
|
key,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function confirmNewEmail({ key }: { key: string }) {
|
|
|
|
return request.post('/api/accounts/change-email/confirm-new-email', {
|
|
|
|
key,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-01 15:58:54 +05:30
|
|
|
export default {
|
2016-10-30 17:42:49 +05:30
|
|
|
/**
|
|
|
|
* @param {object} options
|
2016-11-08 12:00:53 +05:30
|
|
|
* @param {object} [options.token] - an optional token to overwrite headers
|
|
|
|
* in middleware and disable token auto-refresh
|
2016-10-30 17:42:49 +05:30
|
|
|
*
|
2017-12-26 01:33:21 +05:30
|
|
|
* @return {Promise<UserResponse>}
|
2016-10-30 17:42:49 +05:30
|
|
|
*/
|
2017-12-26 01:33:21 +05:30
|
|
|
current(options: { token?: ?string } = {}): Promise<UserResponse> {
|
2019-01-25 22:59:32 +05:30
|
|
|
return getInfo(0, options);
|
2016-10-10 00:20:34 +05:30
|
|
|
},
|
|
|
|
|
2016-05-22 13:23:40 +05:30
|
|
|
|
2016-05-01 15:58:54 +05:30
|
|
|
};
|