Commit 3e8054fe by Mathias Gatti Elbern

Merge branch 'TelaCadastro' into 'dev-sprint4'

Tela cadastro

See merge request !47
2 parents fd817beb 8a5eea75
{
"expoServerPort": null,
"expoServerNgrokUrl": null,
"packagerNgrokUrl": null,
"ngrokPid": null,
"packagerPort": null,
"packagerPid": null,
"devToolsPort": 19002
}
\ No newline at end of file
{
"hostType": "lan",
"lanType": "ip",
"dev": true,
"minify": false,
"urlRandomness": "xz-g8k"
}
\ No newline at end of file
......@@ -14,6 +14,9 @@ import AndamentoVotos from './src/screens/AndamentoVotos';
import Votacao from './src/screens/Votacao';
import Votar from './src/screens/Votar';
import Login from './src/screens/Login';
import TelaCadastro from './src/screens/TelaCadastro';
import { app } from 'firebase';
import moment from 'moment';
const AppNavigator = createStackNavigator(
......@@ -31,7 +34,8 @@ const AppNavigator = createStackNavigator(
AndamentoVotos,
Votacao,
VisualizarQuestao,
Votar
Votar,
TelaCadastro
},
{
initialRouteName: 'Login',
......
......@@ -8,9 +8,10 @@ const BotaoAnterior = ({ endereco, navigation, disabled, onPress}) => (
(<TouchableOpacity
disabled={disabled}
onPress={onPress}
width={3}
>
<Icon style={styles.icon}
name="md-arrow-back" size={50}
name="md-arrow-back" size={28}
color={ disabled ? 'gray' : "#8400C5"}
/>
</TouchableOpacity>)
......@@ -18,9 +19,10 @@ const BotaoAnterior = ({ endereco, navigation, disabled, onPress}) => (
(<TouchableOpacity
disabled={disabled}
onPress={() => navigation.navigate(endereco)}
width={3}
>
<Icon style={styles.icon}
name="md-arrow-back" size={50}
name="md-arrow-back" size={28}
color={ disabled ? 'gray' : "#8400C5"}
/>
</TouchableOpacity>)
......@@ -30,7 +32,7 @@ const BotaoAnterior = ({ endereco, navigation, disabled, onPress}) => (
const styles = StyleSheet.create({
icon: {
flexDirection: 'column',
alignSelf: 'flex-end',
alignSelf: 'flex-start',
paddingLeft: 10,
paddingRight: 10,
paddingBottom: 10
......
......@@ -71,11 +71,17 @@ export default class Login extends Component {
{this.state.errorMessage}
</Text>
</View>
<View style={{flex: 3, backgroundColor: 'white'}}>
<TouchableOpacity style={styles.loginButtonContainer}
onPress={() => {this.setState({ errorMessage: 'Por favor, aguarde.' }), this.handleLogin()}}>
<Text style={styles.loginButtonText}>Entrar</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.loginButtonContainer}
onPress={() => this.props.navigation.navigate('TelaCadastro')}>
<Text style={styles.loginButtonText}>Cadastrar</Text>
</TouchableOpacity>
</View>
......
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
KeyboardAvoidingView,
AsyncStorage,
ActivityIndicator } from 'react-native';
import InputTexto from '../components/InputTexto';
import styles from '../styles/estilos';
import DateInput from '../components/DateInput';
import InputEmail from '../components/InputEmail';
import InputSenha from '../components/InputSenha';
import BotaoAnterior from '../components/BotaoAnterior';
import BotaoGrande from '../components/BotaoGrande';
import { auth, db } from '../config';
export default class TelaCadastro extends Component{
constructor(props) {
super(props)
this.state = {
salas: {},
email: '',
senha: '',
cpf: '',
nome: '',
errorMessage: '',
errorEmail: '',
errorSenha: '',
errorCPF: '',
errorNome: '',
loading: false
}
}
validate = () => {
let error = '';
if(this.isNomeValido()==false){
error = 'nome'
}else if(this.isEmailValido()==false){
error = 'email'
}else if(this.isCPFValido()==false){
error = 'cpf'
}else if(this.isSenhaValido()==false){
error = 'senha'
}
switch(error) {
case 'nome':
return this.setState({errorMessage: this.state.errorNome})
case 'email':
return this.setState({errorMessage: this.state.errorEmail})
case 'cpf':
return this.setState({errorMessage: this.state.errorCPF})
case 'senha':
return this.setState({errorMessage: this.state.errorSenha})
default:
this.handleSignUp();
}
this.setState({
errorCPF : '',
errorEmail : '',
errorNome : '',
errorSenha : ''
})
}
handleSignUp = async () => {
const { email, senha, nome, cpf } = this.state;
this.setState({loading: true});
const retornoCriacao = await auth.createUserWithEmailAndPassword(email,senha)
.catch(error => this.setState({ errorMessage: error.message, loading: false }));
const uid = retornoCriacao.user.uid;
await Promise.all(
db.ref('usuarios/').push({email, uid, nome, cpf}),
AsyncStorage.setItem('@UID', uid))
this.props.navigation.navigate('Inicio')
}
static navigationOptions = {
title: 'Registrar',
};
render(){
const { loading } = this.state;
return(
loading?
<ActivityIndicator
style={stylesLoading.iconStatusLoading}
animating={loading}
size="large"
color="#00DC7B"
/> :
<KeyboardAvoidingView behavior={"padding"} style={styles.container} enabled number="2" >
<View style={{flex: 1} [styles.flowButtonsContainer, { marginTop: 5 }]}>
<InputTexto
label="Nome"
max={100}
value={this.state.nome}
onChangeText={nome => this.setState({ nome })}/>
<InputEmail
autoCorrect={false}
keyboardType='email-address'
returnKeyType="next"
onChangeText={email => this.setState({ email })}
value={this.state.email}
placeholder='E-mail' />
<InputTexto
label= "CPF"
max={11}
value={this.state.cpf}
onChangeText={cpf => this.setState({ cpf })}/>
</View>
<View style={{flex: 2, backgroundColor: 'white'} }>
<DateInput
titulo="Data de nascimento"
/>
<InputSenha
autoCorrect={false}
returnKeyType="go"
ref={(input)=> this.passwordInput = input}
placeholder='Senha'
onChangeText={senha => this.setState({ senha })}
value={this.state.senha}
/>
<InputSenha
autoCorrect={false}
returnKeyType="go"
ref={(input)=> this.passwordInput = input}
placeholder='Confirmar senha'
onChangeText={email => this.setState({ email })}
value={this.state.senha}
/>
<BotaoGrande
texto="Confirmar"
onPress={() => this.validate()}
endereco='Login'
navigation={this.props.navigation}
/>
<Text>
{this.state.errorMessage}
</Text>
</View>
</KeyboardAvoidingView>
)
}
// utilizada classe '../shared/validationUtil.js'
isEmailValido = () => {
const {email} = this.state;
if(email.includes('@'))return true
this.setState({errorEmail : 'Email inválido'});
return false
}
isNomeValido = () => {
const {nome} = this.state;
if(nome.length > 0) return true
this.setState({errorNome : 'Nome deve ter pelo menos um caracter'});
return false
}
isCPFValido = () => {
let Soma;
let Resto;
let validated = true;
Soma = 0;
if (this.state.cpf == "00000000000") validated = false;
for (i=1; i<=9; i++) Soma = Soma + parseInt(this.state.cpf.substring(i-1, i)) * (11 - i);
Resto = (Soma * 10) % 11;
if ((Resto == 10) || (Resto == 11)) Resto = 0;
if (Resto != parseInt(this.state.cpf.substring(9, 10)) ) validated = false;
Soma = 0;
for (i = 1; i <= 10; i++) Soma = Soma + parseInt(this.state.cpf.substring(i-1, i)) * (12 - i);
Resto = (Soma * 10) % 11;
if ((Resto == 10) || (Resto == 11)) Resto = 0;
if (Resto != parseInt(this.state.cpf.substring(10, 11) ) ) validated = false;
if(validated==false)this.setState({errorCPF : 'CPF inválido'});
return validated;
}
//Fazer validação para senha e confirmação de senha
isSenhaValido = () => {
const {senha} = this.state;
if(senha.length >= 6)return true;
this.setState({errorSenha : 'Senha deve ter pelo menos 6 caracteres'});
return false
}
}
const stylesLoading = StyleSheet.create({
iconStatusLoaded: {
justifyContent: 'flex-end',
paddingLeft: 5,
marginTop: 45
},
iconStatusLoading: {
justifyContent: 'center',
paddingLeft: 5,
marginTop: 22
}
})
const isEmailValido = entrada => {
if(entrada.includes('@')) return true
return false
}
const isNomeValido = entrada => {
if(entrada.length > 0) return true
return false
}
const isCPFValido = entrada => {
let Soma;
let Resto;
Soma = 0;
if (entrada == "00000000000") return false;
for (i=1; i<=9; i++) Soma = Soma + parseInt(entrada.substring(i-1, i)) * (11 - i);
Resto = (Soma * 10) % 11;
if ((Resto == 10) || (Resto == 11)) Resto = 0;
if (Resto != parseInt(entrada.substring(9, 10)) ) return false;
Soma = 0;
for (i = 1; i <= 10; i++) Soma = Soma + parseInt(entrada.substring(i-1, i)) * (12 - i);
Resto = (Soma * 10) % 11;
if ((Resto == 10) || (Resto == 11)) Resto = 0;
if (Resto != parseInt(entrada.substring(10, 11) ) ) return false;
return true;
}
const isSenhaValido = entrada => {
if(entrada.length > 8) return true
return false
}
const isValido = () => {
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!