This commit is contained in:
parent
f048c87810
commit
1e09446709
|
@ -58,6 +58,7 @@ class App extends Component {
|
||||||
console.log(this.props.UI_loginScannerActive);
|
console.log(this.props.UI_loginScannerActive);
|
||||||
};
|
};
|
||||||
_tryLogin = () => {
|
_tryLogin = () => {
|
||||||
|
this.props.waitLogin();
|
||||||
//console.log(this.state.text)
|
//console.log(this.state.text)
|
||||||
//this.scanner.reactivate();
|
//this.scanner.reactivate();
|
||||||
this.props.login(this.state.username, this.state.text);
|
this.props.login(this.state.username, this.state.text);
|
||||||
|
@ -98,6 +99,7 @@ class App extends Component {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
//this.props.hold();
|
//this.props.hold();
|
||||||
|
this.props.loginInternal();
|
||||||
NetInfo.isConnected.addEventListener(
|
NetInfo.isConnected.addEventListener(
|
||||||
"connectionChange",
|
"connectionChange",
|
||||||
this.handleConnectivityChange
|
this.handleConnectivityChange
|
||||||
|
@ -140,13 +142,7 @@ class App extends Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (!this.state.isConnected) {
|
|
||||||
return (
|
|
||||||
<View>
|
|
||||||
<Text>cenas da vida</Text>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!this.props.logged && this.props.onHold) {
|
if (!this.props.logged && this.props.onHold) {
|
||||||
return (
|
return (
|
||||||
<View style={UtilStyles.containerLoading}>
|
<View style={UtilStyles.containerLoading}>
|
||||||
|
@ -228,7 +224,7 @@ class App extends Component {
|
||||||
onSubmitEditing={Keyboard.dismiss}
|
onSubmitEditing={Keyboard.dismiss}
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
/>
|
/>
|
||||||
|
{ !this.props.loadingLogin &&
|
||||||
<RkButton
|
<RkButton
|
||||||
rkType="dark"
|
rkType="dark"
|
||||||
style={styles.loginBtn}
|
style={styles.loginBtn}
|
||||||
|
@ -236,6 +232,10 @@ class App extends Component {
|
||||||
>
|
>
|
||||||
Entrar
|
Entrar
|
||||||
</RkButton>
|
</RkButton>
|
||||||
|
}
|
||||||
|
{this.props.alignItems &&
|
||||||
|
<ActivityIndicator size="large" color="#0000ff" />
|
||||||
|
}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View style={styles.buttons}>
|
<View style={styles.buttons}>
|
||||||
|
@ -490,7 +490,8 @@ mapStateToProps = (state, props) => {
|
||||||
userDetails: state.apiReducer.userDetails,
|
userDetails: state.apiReducer.userDetails,
|
||||||
modalOpen: state.apiReducer.modalOpen,
|
modalOpen: state.apiReducer.modalOpen,
|
||||||
modalInfo: state.apiReducer.modalInfo,
|
modalInfo: state.apiReducer.modalInfo,
|
||||||
type: state.apiReducer.type
|
type: state.apiReducer.type,
|
||||||
|
loadingLogin:state.apiReducer.loadingLogin
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ export const UI_LOGIN_PASSWORD_INPUT_LOADING='UI_LOGIN_PASSWORD_INPUT_LOADING'
|
||||||
export const UI_LOGIN_PASSWORD_INPUT_INVALID='UI_LOGIN_PASSWORD_INPUT_INVALID'
|
export const UI_LOGIN_PASSWORD_INPUT_INVALID='UI_LOGIN_PASSWORD_INPUT_INVALID'
|
||||||
export const UI_LOGIN_NOINTERNET='UI_LOGIN_NOINTERNET'
|
export const UI_LOGIN_NOINTERNET='UI_LOGIN_NOINTERNET'
|
||||||
export const UI_LOGIN_OPEN_SCANNER='UI_LOIN_OPEN_SCANNER'
|
export const UI_LOGIN_OPEN_SCANNER='UI_LOIN_OPEN_SCANNER'
|
||||||
|
export const LOADINGLOGIN = 'LOADINGLOGIN'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { AsyncStorage } from "react-native";
|
import { AsyncStorage } from "react-native";
|
||||||
|
|
||||||
import { NetInfo } from "react-native";
|
import { NetInfo , Alert} from "react-native";
|
||||||
|
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@ import {
|
||||||
CHANGE_GUEST,
|
CHANGE_GUEST,
|
||||||
WAIT_CHANGE,
|
WAIT_CHANGE,
|
||||||
SIGN_SESSION,
|
SIGN_SESSION,
|
||||||
OPEN_MODAL
|
OPEN_MODAL,
|
||||||
|
LOADINGLOGIN
|
||||||
} from "./actionTypes"; //Import the actions types constant we defined in our actions
|
} from "./actionTypes"; //Import the actions types constant we defined in our actions
|
||||||
|
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
|
@ -38,6 +39,44 @@ axios.defaults.baseURL = "http://enei2019.uingress.com/internal/api";
|
||||||
|
|
||||||
const map = require("lodash/fp/map").convert({ cap: false });
|
const map = require("lodash/fp/map").convert({ cap: false });
|
||||||
|
|
||||||
|
|
||||||
|
export function waitLogin(){
|
||||||
|
return dispatch=>{
|
||||||
|
dispatch({
|
||||||
|
type: LOADINGLOGIN,
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//faz autenticação com API interna
|
||||||
|
export function loginInternal(userDetails){
|
||||||
|
axios.defaults.baseURL = "http://127.0.0.1:5000";
|
||||||
|
return dispatch => {
|
||||||
|
|
||||||
|
axios.post('/api/login',{
|
||||||
|
"username": "cena",
|
||||||
|
"password": "password"
|
||||||
|
|
||||||
|
}).then(a=>{
|
||||||
|
console.log("sucesso!")
|
||||||
|
console.log(a)
|
||||||
|
}).catch(p=>{
|
||||||
|
console.log(p)
|
||||||
|
})
|
||||||
|
|
||||||
|
dispatch({
|
||||||
|
type: OPEN_MODAL,
|
||||||
|
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function openModal(info, t) {
|
export function openModal(info, t) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -613,23 +652,36 @@ export function login(user, pass) {
|
||||||
type: API_LOGIN,
|
type: API_LOGIN,
|
||||||
logged: false,
|
logged: false,
|
||||||
failedAttempt: true,
|
failedAttempt: true,
|
||||||
tokenData: "error"
|
tokenData: "error",
|
||||||
|
user: { Name: "" },
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
.catch(err=>{
|
||||||
|
console.log("error")
|
||||||
|
})
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(parsed => {
|
.then(parsed => {
|
||||||
|
console.log(parsed)
|
||||||
if (
|
if (
|
||||||
parsed.error_description ==
|
parsed.error_description ==
|
||||||
"Provided username and password is incorrect"
|
"Provided username and password is incorrect"
|
||||||
) {
|
) {
|
||||||
|
Alert.alert("Dados Inválidos","Podes sempre fazer reset da password para o email.")
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: API_LOGIN,
|
type: API_LOGIN,
|
||||||
logged: false,
|
logged: false,
|
||||||
failedAttempt: true,
|
failedAttempt: true,
|
||||||
token: obj,
|
token: obj,
|
||||||
user: { Name: "Henrique" }
|
user: { Name: "Henrique" },
|
||||||
|
userDetails:{},
|
||||||
|
waitLogin:false,
|
||||||
|
onHold:false
|
||||||
|
|
||||||
});
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
var obj = {
|
var obj = {
|
||||||
access_token: parsed.access_token,
|
access_token: parsed.access_token,
|
||||||
expirationDateToken: Math.round(new Date().getTime() / 1000) + 3598,
|
expirationDateToken: Math.round(new Date().getTime() / 1000) + 3598,
|
||||||
|
@ -648,7 +700,7 @@ export function login(user, pass) {
|
||||||
token: obj,
|
token: obj,
|
||||||
user: { Name: "Henrique" },
|
user: { Name: "Henrique" },
|
||||||
userDetails: details
|
userDetails: details
|
||||||
});
|
});}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,9 @@ export {checkUser,
|
||||||
getSessions,
|
getSessions,
|
||||||
signSession,
|
signSession,
|
||||||
openModal,
|
openModal,
|
||||||
closeModal
|
closeModal,
|
||||||
|
loginInternal,
|
||||||
|
waitLogin
|
||||||
} from "./api"
|
} from "./api"
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
|
@ -14,8 +14,11 @@ import {
|
||||||
TIMERWAIT_CHANGE,
|
TIMERWAIT_CHANGE,
|
||||||
SIGN_SESSION,
|
SIGN_SESSION,
|
||||||
OPEN_MODAL,
|
OPEN_MODAL,
|
||||||
CLOSE_MODAL
|
CLOSE_MODAL,
|
||||||
|
LOADINGLOGIN
|
||||||
|
|
||||||
} from "../actions/actionTypes"; //Import the actions types constant we defined in our actions
|
} from "../actions/actionTypes"; //Import the actions types constant we defined in our actions
|
||||||
|
|
||||||
import { REHYDRATE } from "redux-persist";
|
import { REHYDRATE } from "redux-persist";
|
||||||
|
|
||||||
let apiState = {
|
let apiState = {
|
||||||
|
@ -43,7 +46,8 @@ let apiState = {
|
||||||
a:{},
|
a:{},
|
||||||
b:{},
|
b:{},
|
||||||
c:{},
|
c:{},
|
||||||
d:{}
|
d:{},
|
||||||
|
loadingLogin:false,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -96,6 +100,9 @@ const apiReducer = (state = apiState, action) => {
|
||||||
isConnected: action.isConnected
|
isConnected: action.isConnected
|
||||||
});
|
});
|
||||||
|
|
||||||
|
case LOADINGLOGIN:
|
||||||
|
state= Object.assign({}, state, {loadingLogin:true});
|
||||||
|
|
||||||
case HOLD:
|
case HOLD:
|
||||||
state = Object.assign({}, state, { onHold: true });
|
state = Object.assign({}, state, { onHold: true });
|
||||||
return state;
|
return state;
|
||||||
|
@ -110,7 +117,9 @@ const apiReducer = (state = apiState, action) => {
|
||||||
token: action.token,
|
token: action.token,
|
||||||
username: action.userDetails.username,
|
username: action.userDetails.username,
|
||||||
password: action.userDetails.password
|
password: action.userDetails.password
|
||||||
}
|
},
|
||||||
|
loadingLogin:false,
|
||||||
|
onHold: action.onHold
|
||||||
});
|
});
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|
Loading…
Reference in New Issue