Commit 9bb04a20 by JM Fantin

Merge branch 'TelaCadastro' into 'dev-sprint4'

Tela cadastro

See merge request !50
2 parents 9fd795ff 79d36936
{
"devToolsPort": 19002,
"expoServerPort": 19000,
"packagerPort": 19001,
"packagerPid": 7236,
"expoServerNgrokUrl": "https://b3-sgx.evote.rn-evote.exp.direct",
"packagerNgrokUrl": "https://packager.b3-sgx.evote.rn-evote.exp.direct",
"ngrokPid": 7290
}
\ No newline at end of file
{}
\ No newline at end of file
......@@ -62,7 +62,7 @@ export default class Andamento extends Component {
{sala.descricao}
</Text>
<View>
<StatusVotacao tipo = 'usuario' texto={`${this.getVotosRealizados() || 0}% dos usuários votaram`} />
<StatusVotacao tipo = 'usuario' texto={`${this.getVotosRealizados() || 0}% dos usuários votaram`} />
<StatusVotacao tipo = 'hora' texto = {
encerrou ? 'Votação encerrou em: ' +
getStatus(
......
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
KeyboardAvoidingView,
View,
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 Aviso from '../components/Aviso';
import { auth, db } from '../config';
export default class TelaCadastro extends Component{
constructor(props) {
super(props)
......@@ -23,6 +20,7 @@ export default class TelaCadastro extends Component{
salas: {},
email: '',
senha: '',
senhaConfirma: '',
cpf: '',
nome: '',
errorMessage: '',
......@@ -34,38 +32,29 @@ export default class TelaCadastro extends Component{
}
}
validate = () => {
validate = async () => {
let error = '';
if(this.isNomeValido()==false){
error = 'nome'
}else if(this.isEmailValido()==false){
await this.isNomeValido();
await this.isEmailValido();
await this.isCPFValido();
await this.isSenhaValido();
if(this.state.errorNome){
error = 'nome';
this.setState({errorMessage: this.state.errorNome});
}else if(this.state.errorEmail){
this.setState({errorMessage: this.state.errorEmail});
error = 'email'
}else if(this.isCPFValido()==false){
}else if(this.state.errorCPF){
error = 'cpf'
}else if(this.isSenhaValido()==false){
this.setState({errorMessage: this.state.errorCPF});
}else if(this.state.errorSenha){
error = 'senha'
this.setState({errorMessage: this.state.errorSenha});
} else {
await this.handleSignUp();
}
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 : ''
})
return error;
}
......@@ -83,7 +72,7 @@ export default class TelaCadastro extends Component{
}
static navigationOptions = {
title: 'Registrar',
title: 'Registrar ',
};
......@@ -97,56 +86,48 @@ export default class TelaCadastro extends Component{
size="large"
color="#00DC7B"
/> :
<KeyboardAvoidingView behavior={"padding"} style={styles.container} enabled number="2" >
<KeyboardAvoidingView behavior={"padding"} style={styles.container} enabled number="2">
<View style={{flex: 1} [styles.flowButtonsContainer, { marginTop: 5 }]}>
<Aviso texto={this.state.errorMessage} />
<InputTexto
label="Nome"
max={100}
value={this.state.nome}
onChangeText={nome => this.setState({ nome })}/>
onChangeText={nome => this.setState({ nome, errorNome: '', errorMessage: '' })}/>
<InputEmail
autoCorrect={false}
keyboardType='email-address'
returnKeyType="next"
onChangeText={email => this.setState({ email })}
onChangeText={email => this.setState({ email, errorEmail: '', errorMessage: '' })}
value={this.state.email}
placeholder='E-mail' />
label='E-mail' />
<InputTexto
label= "CPF"
max={11}
value={this.state.cpf}
onChangeText={cpf => this.setState({ cpf })}/>
onChangeText={cpf => this.setState({ cpf, errorCPF: '', errorMessage: '' })}/>
</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 })}
label='Senha'
onChangeText={senha => this.setState({ senha, errorSenha: '', errorMessage: '' })}
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}
label='Confirmar senha'
onChangeText={senhaConfirma => this.setState({ senhaConfirma, errorSenha: '', errorMessage: '' })}
value={this.state.senhaConfirma}
/>
<BotaoGrande
texto="Confirmar"
onPress={() => this.validate()}
onPress={ () => this.validate()}
endereco='Login'
navigation={this.props.navigation}
/>
<Text>
{this.state.errorMessage}
</Text>
</View>
</KeyboardAvoidingView>
)
......@@ -154,16 +135,14 @@ export default class TelaCadastro extends Component{
// utilizada classe '../shared/validationUtil.js'
isEmailValido = () => {
const {email} = this.state;
if(email.includes('@'))return true
this.setState({errorEmail : 'Email inválido'});
return false
const { email } = this.state;
if(email.includes('@')) return true
return this.setState({errorEmail : 'Email inválido'});
}
isNomeValido = () => {
const {nome} = this.state;
if(nome.length > 0) return true
this.setState({errorNome : 'Nome deve ter pelo menos um caracter'});
return false
const { nome } = this.state;
if(nome.length > 0 && nome.length < 100) return true
return this.setState({errorNome : 'Nome deve ter de 1 a 100 caracteres'});
}
isCPFValido = () => {
......@@ -171,6 +150,10 @@ export default class TelaCadastro extends Component{
let Resto;
let validated = true;
Soma = 0;
if(this.state.cpf.length != 11){
return this.setState({errorCPF : 'CPF deve ter 11 numeros'});
}
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);
......@@ -187,16 +170,22 @@ export default class TelaCadastro extends Component{
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 {senha, senhaConfirma} = this.state;
if(senha.length >= 6 && senhaConfirma.length >= 6){
if(senha === senhaConfirma){
return true;
} else {
return this.setState({errorSenha : 'As senhas não batem.'})
}
} else {
return this.setState({errorSenha : 'Senha deve ter pelo menos 6 caracteres'});
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!