accounts-frontend/src/services/api/accounts.js

101 lines
2.3 KiB
JavaScript
Raw Normal View History

// @flow
import request from 'services/request';
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,
};
export default {
/**
* @param {object} options
* @param {object} [options.token] - an optional token to overwrite headers
* in middleware and disable token auto-refresh
*
* @return {Promise<UserResponse>}
*/
current(options: { token?: ?string } = {}): Promise<UserResponse> {
return request.get('/api/accounts/current', {}, {
token: options.token
});
},
2016-10-10 00:20:34 +05:30
changePassword({
password = '',
newPassword = '',
newRePassword = '',
logoutAll = true
}: {
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 = ''
}: {
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
},
changeLang(lang: string) {
2016-05-20 01:11:43 +05:30
return request.post(
'/api/accounts/change-lang',
{lang}
);
},
requestEmailChange({password = ''}: { password?: string }) {
return request.post(
'/api/accounts/change-email/initialize',
{password}
);
},
setNewEmail({
email = '',
key = ''
}: {
email?: string,
key?: string,
}) {
return request.post(
'/api/accounts/change-email/submit-new-email',
{email, key}
);
},
confirmNewEmail({key}: { key: string }) {
return request.post(
'/api/accounts/change-email/confirm-new-email',
{key}
);
}
};