( dispatch, login, password, setIsLoading, setError, social = '', )
| 101 | // ########################################################### |
| 102 | |
| 103 | function loginUser( |
| 104 | dispatch, |
| 105 | login, |
| 106 | password, |
| 107 | setIsLoading, |
| 108 | setError, |
| 109 | social = '', |
| 110 | ) { |
| 111 | setError(false); |
| 112 | setIsLoading(true); |
| 113 | // We check if app runs with backend mode |
| 114 | if (!config.isBackend) { |
| 115 | setError(null); |
| 116 | doInit()(dispatch); |
| 117 | setIsLoading(false); |
| 118 | receiveToken('token', dispatch); |
| 119 | } else { |
| 120 | if (social) { |
| 121 | window.location.href = |
| 122 | config.baseURLApi + |
| 123 | '/auth/signin/' + |
| 124 | social + |
| 125 | '?app=' + |
| 126 | config.redirectUrl; |
| 127 | } else if (login.length > 0 && password.length > 0) { |
| 128 | axios |
| 129 | .post('/auth/signin/local', { email: login, password }) |
| 130 | .then((res) => { |
| 131 | const token = res.data; |
| 132 | setError(null); |
| 133 | setIsLoading(false); |
| 134 | receiveToken(token, dispatch); |
| 135 | doInit()(dispatch); |
| 136 | }) |
| 137 | .catch(() => { |
| 138 | setError(true); |
| 139 | setIsLoading(false); |
| 140 | }); |
| 141 | } else { |
| 142 | dispatch({ type: 'LOGIN_FAILURE' }); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | export function sendPasswordResetEmail(email) { |
| 148 | return (dispatch) => { |
no test coverage detected