2017-12-26 01:33:21 +05:30
|
|
|
// @flow
|
2016-05-01 15:58:54 +05:30
|
|
|
import request from 'services/request';
|
|
|
|
|
2017-12-26 01:33:21 +05:30
|
|
|
type UserResponse = {
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
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> {
|
2016-10-30 17:42:49 +05:30
|
|
|
return request.get('/api/accounts/current', {}, {
|
2016-11-08 12:00:53 +05:30
|
|
|
token: options.token
|
2016-10-30 17:42:49 +05:30
|
|
|
});
|
2016-05-01 15:58:54 +05:30
|
|
|
},
|
|
|
|
|
2016-10-10 00:20:34 +05:30
|
|
|
changePassword({
|
|
|
|
password = '',
|
|
|
|
newPassword = '',
|
|
|
|
newRePassword = '',
|
|
|
|
logoutAll = true
|
2017-12-26 01:33:21 +05:30
|
|
|
}: {
|
|
|
|
password?: string,
|
|
|
|
newPassword?: string,
|
|
|
|
newRePassword?: string,
|
|
|
|
logoutAll?: bool,
|
2016-10-10 00:20:34 +05:30
|
|
|
}) {
|
|
|
|
return request.post(
|
|
|
|
'/api/accounts/change-password',
|
|
|
|
{password, newPassword, newRePassword, logoutAll}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2016-08-03 00:29:29 +05:30
|
|
|
acceptRules() {
|
|
|
|
return request.post('/api/accounts/accept-rules');
|
|
|
|
},
|
|
|
|
|
2016-05-02 18:43:18 +05:30
|
|
|
changeUsername({
|
|
|
|
username = '',
|
|
|
|
password = ''
|
2017-12-26 01:33:21 +05:30
|
|
|
}: {
|
|
|
|
username?: string,
|
|
|
|
password?: string,
|
2016-05-02 18:43:18 +05:30
|
|
|
}) {
|
|
|
|
return request.post(
|
|
|
|
'/api/accounts/change-username',
|
|
|
|
{username, password}
|
|
|
|
);
|
2016-05-20 01:11:43 +05:30
|
|
|
},
|
|
|
|
|
2017-12-26 01:33:21 +05:30
|
|
|
changeLang(lang: string) {
|
2016-05-20 01:11:43 +05:30
|
|
|
return request.post(
|
|
|
|
'/api/accounts/change-lang',
|
|
|
|
{lang}
|
|
|
|
);
|
2016-05-22 13:23:40 +05:30
|
|
|
},
|
|
|
|
|
2017-12-26 01:33:21 +05:30
|
|
|
requestEmailChange({password = ''}: { password?: string }) {
|
2016-05-22 13:23:40 +05:30
|
|
|
return request.post(
|
2016-05-23 00:34:52 +05:30
|
|
|
'/api/accounts/change-email/initialize',
|
|
|
|
{password}
|
2016-05-22 13:23:40 +05:30
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
setNewEmail({
|
|
|
|
email = '',
|
|
|
|
key = ''
|
2017-12-26 01:33:21 +05:30
|
|
|
}: {
|
|
|
|
email?: string,
|
|
|
|
key?: string,
|
2016-05-22 13:23:40 +05:30
|
|
|
}) {
|
|
|
|
return request.post(
|
|
|
|
'/api/accounts/change-email/submit-new-email',
|
|
|
|
{email, key}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2017-12-26 01:33:21 +05:30
|
|
|
confirmNewEmail({key}: { key: string }) {
|
2016-05-22 13:23:40 +05:30
|
|
|
return request.post(
|
|
|
|
'/api/accounts/change-email/confirm-new-email',
|
|
|
|
{key}
|
|
|
|
);
|
2016-05-01 15:58:54 +05:30
|
|
|
}
|
|
|
|
};
|