This commit is contained in:
henrydays 2019-03-11 16:15:51 +00:00
parent f048c87810
commit 1e09446709
5 changed files with 83 additions and 19 deletions

View File

@ -58,6 +58,7 @@ class App extends Component {
console.log(this.props.UI_loginScannerActive);
};
_tryLogin = () => {
this.props.waitLogin();
//console.log(this.state.text)
//this.scanner.reactivate();
this.props.login(this.state.username, this.state.text);
@ -98,6 +99,7 @@ class App extends Component {
componentDidMount() {
//this.props.hold();
this.props.loginInternal();
NetInfo.isConnected.addEventListener(
"connectionChange",
this.handleConnectivityChange
@ -140,13 +142,7 @@ class App extends Component {
};
render() {
if (!this.state.isConnected) {
return (
<View>
<Text>cenas da vida</Text>
</View>
);
}
if (!this.props.logged && this.props.onHold) {
return (
<View style={UtilStyles.containerLoading}>
@ -228,7 +224,7 @@ class App extends Component {
onSubmitEditing={Keyboard.dismiss}
placeholder="Password"
/>
{ !this.props.loadingLogin &&
<RkButton
rkType="dark"
style={styles.loginBtn}
@ -236,6 +232,10 @@ class App extends Component {
>
Entrar
</RkButton>
}
{this.props.alignItems &&
<ActivityIndicator size="large" color="#0000ff" />
}
</View>
<View style={styles.buttons}>
@ -490,7 +490,8 @@ mapStateToProps = (state, props) => {
userDetails: state.apiReducer.userDetails,
modalOpen: state.apiReducer.modalOpen,
modalInfo: state.apiReducer.modalInfo,
type: state.apiReducer.type
type: state.apiReducer.type,
loadingLogin:state.apiReducer.loadingLogin
};
};

View File

@ -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_NOINTERNET='UI_LOGIN_NOINTERNET'
export const UI_LOGIN_OPEN_SCANNER='UI_LOIN_OPEN_SCANNER'
export const LOADINGLOGIN = 'LOADINGLOGIN'

View File

@ -1,6 +1,6 @@
import { AsyncStorage } from "react-native";
import { NetInfo } from "react-native";
import { NetInfo , Alert} from "react-native";
var _ = require("lodash");
@ -19,7 +19,8 @@ import {
CHANGE_GUEST,
WAIT_CHANGE,
SIGN_SESSION,
OPEN_MODAL
OPEN_MODAL,
LOADINGLOGIN
} from "./actionTypes"; //Import the actions types constant we defined in our actions
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 });
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) {
return dispatch => {
dispatch({
@ -613,23 +652,36 @@ export function login(user, pass) {
type: API_LOGIN,
logged: false,
failedAttempt: true,
tokenData: "error"
tokenData: "error",
user: { Name: "" },
});
})
.catch(err=>{
console.log("error")
})
.then(res => res.json())
.then(parsed => {
console.log(parsed)
if (
parsed.error_description ==
"Provided username and password is incorrect"
) {
Alert.alert("Dados Inválidos","Podes sempre fazer reset da password para o email.")
dispatch({
type: API_LOGIN,
logged: false,
failedAttempt: true,
token: obj,
user: { Name: "Henrique" }
user: { Name: "Henrique" },
userDetails:{},
waitLogin:false,
onHold:false
});
return;
}
else{
var obj = {
access_token: parsed.access_token,
expirationDateToken: Math.round(new Date().getTime() / 1000) + 3598,
@ -648,7 +700,7 @@ export function login(user, pass) {
token: obj,
user: { Name: "Henrique" },
userDetails: details
});
});}
});
};
}

View File

@ -14,7 +14,9 @@ export {checkUser,
getSessions,
signSession,
openModal,
closeModal
closeModal,
loginInternal,
waitLogin
} from "./api"
export {

View File

@ -14,8 +14,11 @@ import {
TIMERWAIT_CHANGE,
SIGN_SESSION,
OPEN_MODAL,
CLOSE_MODAL
CLOSE_MODAL,
LOADINGLOGIN
} from "../actions/actionTypes"; //Import the actions types constant we defined in our actions
import { REHYDRATE } from "redux-persist";
let apiState = {
@ -43,7 +46,8 @@ let apiState = {
a:{},
b:{},
c:{},
d:{}
d:{},
loadingLogin:false,
};
@ -96,6 +100,9 @@ const apiReducer = (state = apiState, action) => {
isConnected: action.isConnected
});
case LOADINGLOGIN:
state= Object.assign({}, state, {loadingLogin:true});
case HOLD:
state = Object.assign({}, state, { onHold: true });
return state;
@ -110,7 +117,9 @@ const apiReducer = (state = apiState, action) => {
token: action.token,
username: action.userDetails.username,
password: action.userDetails.password
}
},
loadingLogin:false,
onHold: action.onHold
});
return state;