login update v4
This commit is contained in:
parent
d22b3d692c
commit
f669273ba5
|
@ -1,5 +1,5 @@
|
|||
import React, {Component} from 'react';
|
||||
import {Platform, StyleSheet, Text, View, StatusBar, Dimensions, Image, ActivityIndicator} from 'react-native';
|
||||
import {Platform, StyleSheet, Text, View, StatusBar, Dimensions, Image, ActivityIndicator, Button, TouchableHighlight} from 'react-native';
|
||||
|
||||
import {bindActionCreators} from 'redux';
|
||||
import {connect} from 'react-redux';
|
||||
|
@ -7,15 +7,37 @@ import {connect} from 'react-redux';
|
|||
import QRCodeScanner from 'react-native-qrcode-scanner';
|
||||
import {UtilStyles} from './assets/styles'
|
||||
import * as Actions from './actions'; //Import your actions
|
||||
import {RkButton, RkTheme, RkText} from 'react-native-ui-kitten';
|
||||
import {RkButton, RkTheme, RkText, RkTextInput} from 'react-native-ui-kitten';
|
||||
|
||||
import Modal from "react-native-modal";
|
||||
|
||||
import Router from './Router'
|
||||
|
||||
import Icon from "react-native-vector-icons/Ionicons"
|
||||
|
||||
const SCREEN_HEIGHT = Dimensions.get("window").height;
|
||||
const SCREEN_WIDTH = Dimensions.get("window").width;
|
||||
|
||||
|
||||
class App extends Component {
|
||||
|
||||
_activate=()=>{
|
||||
|
||||
this.setState({ isModalVisible: !this.state.isModalVisible});
|
||||
this.scanner.reactivate();
|
||||
|
||||
}
|
||||
_tryLogin=()=>{
|
||||
|
||||
console.log(this.state.text)
|
||||
this.scanner.reactivate();
|
||||
this.props.login(this.state.username, this.state.text);
|
||||
this.scanner.reactivate();
|
||||
console.log(this.props.failedAttempt);
|
||||
}
|
||||
|
||||
_toggleModal = () =>
|
||||
this.setState({ isModalVisible: !this.state.isModalVisible });
|
||||
|
||||
constructor(props) {
|
||||
|
||||
|
@ -26,7 +48,11 @@ class App extends Component {
|
|||
token: {valid: false},
|
||||
tokenData: '',
|
||||
onHold: true,
|
||||
logged: false
|
||||
logged: false,
|
||||
isModalVisible: false,
|
||||
state : {text: ''},
|
||||
username:'',
|
||||
failedAttempt: false
|
||||
|
||||
};
|
||||
|
||||
|
@ -41,8 +67,10 @@ class App extends Component {
|
|||
|
||||
onSuccess = (e) => {
|
||||
|
||||
this.setState({ isModalVisible: !this.state.isModalVisible });
|
||||
// this.props.login(e.data, 'f8908cc0');
|
||||
this.setState({username:e.data})
|
||||
|
||||
this.props.login(e.data, 'f8908cc0');
|
||||
console.log("tentativa de login");
|
||||
|
||||
|
||||
|
@ -61,14 +89,12 @@ class App extends Component {
|
|||
)
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
//console.log('token... '+ this.props.logged)
|
||||
|
||||
//se existir token
|
||||
|
||||
|
||||
if (this.props.logged) {
|
||||
|
||||
return (
|
||||
|
@ -82,15 +108,38 @@ class App extends Component {
|
|||
return (
|
||||
|
||||
<QRCodeScanner
|
||||
|
||||
ref={(node) => { this.scanner = node }}
|
||||
showMarker
|
||||
reactivate={true}
|
||||
|
||||
onRead={this.onSuccess.bind(this)}
|
||||
cameraStyle={{height: SCREEN_HEIGHT}}
|
||||
|
||||
customMarker={
|
||||
|
||||
|
||||
|
||||
<View style={styles.rectangleContainer}>
|
||||
|
||||
<Modal isVisible={this.state.isModalVisible} style={{backgroundColor:'#E8E8E8', borderRadius:30, height:100}}>
|
||||
<View style={{ flex: 1 }}>
|
||||
<Text></Text>
|
||||
<Text> Introduza a password</Text>
|
||||
<RkTextInput secureTextEntry={true} rkType='rounded' onChangeText={(text) => this.setState({text})} />
|
||||
<Button onPress={this._tryLogin} title="Login" color="#841584" accessibilityLabel="Learn more about this purple button"/>
|
||||
|
||||
{ this.props.failedAttempt &&
|
||||
<Text> Password ou QR incorrecto</Text>
|
||||
}
|
||||
|
||||
|
||||
<Text></Text>
|
||||
<Button onPress={this._activate} title="Scan again!" color="green" accessibilityLabel="Learn more about this purple button"/>
|
||||
|
||||
|
||||
|
||||
|
||||
</View>
|
||||
|
||||
</Modal>
|
||||
<View style={styles.logo}>
|
||||
<Image style={UtilStyles.loginImage}
|
||||
source={require('./assets/img/logo.png')}
|
||||
|
@ -114,7 +163,6 @@ class App extends Component {
|
|||
<View style={styles.bottomOverlay}>
|
||||
|
||||
<View style={{flex: 1, alignItems: 'center', alignContent: 'center'}}>
|
||||
|
||||
<RkText rkType='primary' style={styles.recover}>Recuperar pin de acesso</RkText>
|
||||
<RkButton rkType='dark' style={styles.manual}>lols</RkButton>
|
||||
</View>
|
||||
|
@ -199,14 +247,29 @@ const styles = {
|
|||
backgroundColor: overlayColor
|
||||
},
|
||||
};
|
||||
|
||||
RkTheme.setType('RkTextInput', 'frame', {
|
||||
input: {
|
||||
backgroundColor: 'white',
|
||||
marginLeft: 0,
|
||||
marginHorizontal: 0,
|
||||
borderRadius: 5
|
||||
},
|
||||
color: 'gray',
|
||||
backgroundColor: 'gray',
|
||||
borderRadius: 10,
|
||||
container: {
|
||||
paddingHorizontal: 20
|
||||
}
|
||||
});
|
||||
|
||||
mapStateToProps = (state, props) => {
|
||||
|
||||
return {
|
||||
token: state.apiReducer.token,
|
||||
loggedIn: state.apiReducer.loggedIn,
|
||||
onHold: state.apiReducer.onHold,
|
||||
logged: state.apiReducer.logged
|
||||
logged: state.apiReducer.logged,
|
||||
failedAttempt:state.apiReducer.failedAttempt,
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -210,10 +210,11 @@ export function login(user, pass){
|
|||
console.log(err);
|
||||
|
||||
alert("error");
|
||||
|
||||
co
|
||||
dispatch({
|
||||
type: API_LOGIN,
|
||||
logged:false,
|
||||
logged:false,
|
||||
failedAttempt:true,
|
||||
tokenData:'error'
|
||||
});
|
||||
|
||||
|
@ -221,6 +222,15 @@ export function login(user, pass){
|
|||
|
||||
}).then(res=>res.json()).then(parsed=>{
|
||||
|
||||
if(parsed.error_description=="Provided username and password is incorrect"){
|
||||
dispatch({
|
||||
type: API_LOGIN,
|
||||
logged:false,
|
||||
failedAttempt:true,
|
||||
token: obj
|
||||
|
||||
});
|
||||
}
|
||||
var obj={
|
||||
access_token:parsed.access_token,
|
||||
expirationDateToken:Math.round(new Date().getTime()/1000) + parsed.expires_in,
|
||||
|
@ -235,10 +245,12 @@ export function login(user, pass){
|
|||
saveToken(obj).then(a=>{
|
||||
|
||||
obj.valid=true;
|
||||
|
||||
|
||||
|
||||
dispatch({
|
||||
type: API_LOGIN,
|
||||
logged:true,
|
||||
failedAttempt:false,
|
||||
token: obj
|
||||
|
||||
});
|
||||
|
@ -251,7 +263,8 @@ export function login(user, pass){
|
|||
|
||||
dispatch({
|
||||
type: API_LOGIN,
|
||||
logged:true,
|
||||
logged:false,
|
||||
failedAttempt:true,
|
||||
token: obj
|
||||
|
||||
|
||||
|
@ -261,14 +274,7 @@ export function login(user, pass){
|
|||
|
||||
}
|
||||
|
||||
).then(a=>{
|
||||
dispatch({
|
||||
type: API_LOGIN,
|
||||
logged:true,
|
||||
token: obj
|
||||
|
||||
});
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { combineReducers } from 'redux';
|
|||
import { DATA_AVAILABLE, API_LOGIN, CHECK_USER, LOGOUT_USER, USER_INFO, HOLD, GET_EVENTS } from "../actions/" //Import the actions types constant we defined in our actions
|
||||
|
||||
|
||||
let dataState = { data: [], loading:true ,token:true};
|
||||
let dataState = { data: [], loading:true ,token:true, failAttempt:false};
|
||||
|
||||
const dataReducer = (state = dataState, action) => {
|
||||
switch (action.type) {
|
||||
|
@ -15,7 +15,7 @@ const dataReducer = (state = dataState, action) => {
|
|||
}
|
||||
};
|
||||
|
||||
let apiState= { token:{valid:false}, tokenData:'error', logged:false, onHold:true, user:{}, events:[]}
|
||||
let apiState= { token:{valid:false}, tokenData:'error', logged:false, onHold:true, user:{}, events:[], failedAttempt:false}
|
||||
|
||||
const apiReducer = (state = apiState, action) => {
|
||||
|
||||
|
@ -28,7 +28,7 @@ const apiReducer = (state = apiState, action) => {
|
|||
|
||||
case API_LOGIN:
|
||||
|
||||
state=Object.assign({},state, { logged:action.logged, token:action.token});
|
||||
state=Object.assign({},state, { logged:action.logged, token:action.token, failedAttempt: action.failedAttempt});
|
||||
|
||||
return state;
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ class Home extends Component {
|
|||
|
||||
//console.log(th2is.props)
|
||||
|
||||
console.log(this.props.user)
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue