|
1 | | -import {getAuthLogin, postUsers, activateUser} from '../../services/authService'; |
| 1 | +import {getAuthLogin, activateUser} from '../../services/authService'; |
2 | 2 | import {Cookies} from 'react-cookie'; |
3 | 3 | import * as authActionTypes from './authActionTypes'; |
4 | 4 |
|
5 | | -export const registerIfNeeded = () => { |
6 | | - return (dispatch, getState) => { |
7 | | - if (shouldRegister(getState())) { |
8 | | - return dispatch(registration()); |
9 | | - } |
10 | | - return Promise.resolve(); |
11 | | - }; |
12 | | -}; |
13 | | -const shouldRegister = ({auth: {isLoggingIn, isLoggedIn}}) => !isLoggingIn && !isLoggedIn; |
14 | | -const registration = () => { |
15 | | - return (dispatch, getState) => { |
16 | | - dispatch(registrationRequest()); |
17 | | - |
18 | | - const {auth, app} = getState(); |
19 | | - const {registration, activationUrl, activationFromEmail} = auth; |
20 | | - const {appBarTitle} = app; |
21 | | - |
22 | | - return postUsers({registration, activationUrl, activationFromEmail, appName: appBarTitle}) |
23 | | - .then((response) => { |
24 | | - if (response.status === 201) { |
25 | | - dispatch(registrationSuccess('Account created. We have sent you an email with activation instructions.')); |
26 | | - |
27 | | - return {success: true}; |
28 | | - } else { |
29 | | - return response.json(); |
30 | | - } |
31 | | - }) |
32 | | - .then((json) => { |
33 | | - if (json.error && json.errors) { |
34 | | - dispatch(registrationFailure({error: json.error, errors: json.errors})); |
35 | | - } |
36 | | - }) |
37 | | - .catch(error => dispatch(registrationFailure({error: error.message, errors: {}}))); |
38 | | - }; |
39 | | -}; |
40 | | -const registrationRequest = () => ({type: authActionTypes.REGISTRATION_REQUEST}); |
41 | | -const registrationSuccess = payload => ({type: authActionTypes.REGISTRATION_SUCCESS, payload}); |
42 | | -const registrationFailure = payload => ({type: authActionTypes.REGISTRATION_FAILURE, payload}); |
43 | | - |
44 | 5 | export const loginIfNeeded = () => { |
45 | 6 | return (dispatch, getState) => { |
46 | 7 | const {auth: {isLoggingIn, isLoggedIn, login}} = getState(); |
@@ -128,11 +89,7 @@ export const setActivationData = () => { |
128 | 89 | return {type: authActionTypes.SET_ACTIVATION_DATA, payload: {host, hostname, protocol}}; |
129 | 90 | }; |
130 | 91 |
|
131 | | -export const setRegistrationErrorMessage = payload => ({type: authActionTypes.SET_REGISTRATION_ERROR_MESSAGE, payload}); |
132 | | -export const setRegistrationSuccessMessage = payload => ({type: authActionTypes.SET_REGISTRATION_SUCCESS_MESSAGE, payload}); |
133 | 92 | export const setLoginErrorMessage = payload => ({type: authActionTypes.SET_LOGIN_ERROR_MESSAGE, payload}); |
134 | 93 | export const setActivationErrorMessage = payload => ({type: authActionTypes.SET_ACTIVATION_ERROR_MESSAGE, payload}); |
135 | 94 | export const setActivationSuccessMessage = payload => ({type: authActionTypes.SET_ACTIVATION_SUCCESS_MESSAGE, payload}); |
136 | 95 | export const toggleLoginPasswordVisibility = () => ({type: authActionTypes.TOGGLE_LOGIN_PASSWORD_VISIBILITY}); |
137 | | -export const toggleRegistrationPasswordVisibility = () => ({type: authActionTypes.TOGGLE_REGISTRATION_PASSWORD_VISIBILITY}); |
138 | | -export const toggleRegistrationRepeatPasswordVisibility = () => ({type: authActionTypes.TOGGLE_REGISTRATION_REPEAT_PASSWORD_VISIBILITY}); |
0 commit comments