|
|
@@ -1,4 +1,5 @@
|
|
|
import { Actions } from 'react-native-router-flux';
|
|
|
+import { post } from '../api/'
|
|
|
import {
|
|
|
EMAIL_CHANGED,
|
|
|
PASSWORD_CHANGED,
|
|
|
@@ -23,33 +24,23 @@ export const passwordChanged = (text) => {
|
|
|
|
|
|
export const loginUser = ({ email, password }) => {
|
|
|
return (dispatch) => {
|
|
|
- dispatch({ type: LOGIN_USER })
|
|
|
- fetch('https://plataforma.especificosba.com.ar/back/login.php', {
|
|
|
- method: 'POST',
|
|
|
- headers: {
|
|
|
- 'Accept': 'application/json',
|
|
|
- 'Content-Type': 'application/json',
|
|
|
- },
|
|
|
- body: JSON.stringify({
|
|
|
- user: email,
|
|
|
- pass: password,
|
|
|
- })
|
|
|
- })
|
|
|
- .then( (response) => response.json() )
|
|
|
- .then( (responseJson) => {
|
|
|
- loginUserSuccess(dispatch, responseJson);
|
|
|
- });
|
|
|
- //FIXME: Catch
|
|
|
+ dispatch({ type: LOGIN_USER });
|
|
|
+ post( "login.php", { user: email, pass: password } )
|
|
|
+ .then(
|
|
|
+ (response) => loginUserSuccess(dispatch, response)
|
|
|
+ ).catch(
|
|
|
+ (error) => loginUserFail(dispatch, error)
|
|
|
+ );
|
|
|
};
|
|
|
-
|
|
|
-
|
|
|
};
|
|
|
|
|
|
-const loginUserFail = (dispatch) => {
|
|
|
- dispatch({ type: LOGIN_USER_FAIL });
|
|
|
+const loginUserFail = (dispatch, error) => {
|
|
|
+ console.log("login failed", error);
|
|
|
+ dispatch({ type: LOGIN_USER_FAIL, payload: error });
|
|
|
};
|
|
|
|
|
|
const loginUserSuccess = (dispatch, user) => {
|
|
|
+ console.log("success", user);
|
|
|
dispatch({
|
|
|
type: LOGIN_USER_SUCCESS,
|
|
|
payload: user
|