mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-28 07:50:32 +05:30
Decouple the rest of an api calls
This commit is contained in:
parent
5fdb662934
commit
3804c1c143
@ -1,9 +1,9 @@
|
|||||||
import { routeActions } from 'react-router-redux';
|
import { routeActions } from 'react-router-redux';
|
||||||
|
|
||||||
import { updateUser, logout as logoutUser, changePassword as changeUserPassword, authenticate } from 'components/user/actions';
|
import { updateUser, logout as logoutUser, changePassword as changeUserPassword, authenticate } from 'components/user/actions';
|
||||||
import request from 'services/request';
|
|
||||||
import authentication from 'services/api/authentication';
|
import authentication from 'services/api/authentication';
|
||||||
import oauth from 'services/api/oauth';
|
import oauth from 'services/api/oauth';
|
||||||
|
import signup from 'services/api/signup';
|
||||||
|
|
||||||
export function login({login = '', password = '', rememberMe = false}) {
|
export function login({login = '', password = '', rememberMe = false}) {
|
||||||
const PASSWORD_REQUIRED = 'error.password_required';
|
const PASSWORD_REQUIRED = 'error.password_required';
|
||||||
@ -50,14 +50,11 @@ export function forgotPassword({
|
|||||||
login = ''
|
login = ''
|
||||||
}) {
|
}) {
|
||||||
return wrapInLoader((dispatch, getState) =>
|
return wrapInLoader((dispatch, getState) =>
|
||||||
request.post(
|
authentication.forgotPassword({login})
|
||||||
'/api/authentication/forgot-password',
|
.then(({data = {}}) => dispatch(updateUser({
|
||||||
{login}
|
maskedEmail: data.emailMask || getState().user.email
|
||||||
)
|
})))
|
||||||
.then(({data = {}}) => dispatch(updateUser({
|
.catch(validationErrorsHandler(dispatch))
|
||||||
maskedEmail: data.emailMask || getState().user.email
|
|
||||||
})))
|
|
||||||
.catch(validationErrorsHandler(dispatch))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,12 +64,9 @@ export function recoverPassword({
|
|||||||
newRePassword = ''
|
newRePassword = ''
|
||||||
}) {
|
}) {
|
||||||
return wrapInLoader((dispatch) =>
|
return wrapInLoader((dispatch) =>
|
||||||
request.post(
|
authentication.recoverPassword({key, newPassword, newRePassword})
|
||||||
'/api/authentication/recover-password',
|
.then(authHandler(dispatch))
|
||||||
{key, newPassword, newRePassword}
|
.catch(validationErrorsHandler(dispatch, '/forgot-password'))
|
||||||
)
|
|
||||||
.then(authHandler(dispatch))
|
|
||||||
.catch(validationErrorsHandler(dispatch, '/forgot-password'))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,10 +78,11 @@ export function register({
|
|||||||
rulesAgreement = false
|
rulesAgreement = false
|
||||||
}) {
|
}) {
|
||||||
return wrapInLoader((dispatch, getState) =>
|
return wrapInLoader((dispatch, getState) =>
|
||||||
request.post(
|
signup.register({
|
||||||
'/api/signup',
|
email, username,
|
||||||
{email, username, password, rePassword, rulesAgreement, lang: getState().user.lang}
|
password, rePassword,
|
||||||
)
|
rulesAgreement, lang: getState().user.lang
|
||||||
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
dispatch(updateUser({
|
dispatch(updateUser({
|
||||||
username,
|
username,
|
||||||
@ -102,29 +97,23 @@ export function register({
|
|||||||
|
|
||||||
export function activate({key = ''}) {
|
export function activate({key = ''}) {
|
||||||
return wrapInLoader((dispatch) =>
|
return wrapInLoader((dispatch) =>
|
||||||
request.post(
|
signup.activate({key})
|
||||||
'/api/signup/confirm',
|
.then(authHandler(dispatch))
|
||||||
{key}
|
.catch(validationErrorsHandler(dispatch, '/resend-activation'))
|
||||||
)
|
|
||||||
.then(authHandler(dispatch))
|
|
||||||
.catch(validationErrorsHandler(dispatch, '/resend-activation'))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resendActivation({email = ''}) {
|
export function resendActivation({email = ''}) {
|
||||||
return wrapInLoader((dispatch) =>
|
return wrapInLoader((dispatch) =>
|
||||||
request.post(
|
signup.resendActivation({email})
|
||||||
'/api/signup/repeat-message',
|
.then((resp) => {
|
||||||
{email}
|
dispatch(updateUser({
|
||||||
)
|
email
|
||||||
.then((resp) => {
|
}));
|
||||||
dispatch(updateUser({
|
|
||||||
email
|
|
||||||
}));
|
|
||||||
|
|
||||||
return resp;
|
return resp;
|
||||||
})
|
})
|
||||||
.catch(validationErrorsHandler(dispatch))
|
.catch(validationErrorsHandler(dispatch))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,26 @@ export default {
|
|||||||
return request.post('/api/authentication/logout');
|
return request.post('/api/authentication/logout');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
forgotPassword({
|
||||||
|
login = ''
|
||||||
|
}) {
|
||||||
|
return request.post(
|
||||||
|
'/api/authentication/forgot-password',
|
||||||
|
{login}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
recoverPassword({
|
||||||
|
key = '',
|
||||||
|
newPassword = '',
|
||||||
|
newRePassword = ''
|
||||||
|
}) {
|
||||||
|
return request.post(
|
||||||
|
'/api/authentication/recover-password',
|
||||||
|
{key, newPassword, newRePassword}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
refreshToken(refresh_token) {
|
refreshToken(refresh_token) {
|
||||||
return request.post(
|
return request.post(
|
||||||
'/api/authentication/refresh-token',
|
'/api/authentication/refresh-token',
|
||||||
|
31
src/services/api/signup.js
Normal file
31
src/services/api/signup.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import request from 'services/request';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
register({
|
||||||
|
email = '',
|
||||||
|
username = '',
|
||||||
|
password = '',
|
||||||
|
rePassword = '',
|
||||||
|
rulesAgreement = false,
|
||||||
|
lang = ''
|
||||||
|
}) {
|
||||||
|
return request.post(
|
||||||
|
'/api/signup',
|
||||||
|
{email, username, password, rePassword, rulesAgreement, lang}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
activate({key = ''}) {
|
||||||
|
return request.post(
|
||||||
|
'/api/signup/confirm',
|
||||||
|
{key}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
resendActivation({email = ''}) {
|
||||||
|
return request.post(
|
||||||
|
'/api/signup/repeat-message',
|
||||||
|
{email}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user