Commit e24fa411 by bianca-camargo-machado

salvando votantes

2 parents b654ed5c 3e8054fe
{
"expoServerPort": 19000,
"expoServerNgrokUrl": "https://xz-g8k.evote.rn-evote.exp.direct",
"packagerNgrokUrl": "https://packager.xz-g8k.evote.rn-evote.exp.direct",
"ngrokPid": 7194,
"packagerPort": 19001,
"packagerPid": 7094,
"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
......
......@@ -54,7 +54,7 @@ export default class Andamento extends Component {
sala.horaFinal,
sala.horaInicial,
true
): null
): "Votação ainda não encerrou."
}/>
</View>
<BotaoGrande texto="Andamento" onPress={() => this.andamentoVotos()}/>
......
import React, { Component } from 'react';
import { View, ScrollView, Dimensions } from 'react-native';
import { db } from '../config';
let salasRef = db.ref('salas/');
import styles from '../styles/estilos';
import SemSalas from '../containers/SemSalas';
import CardSalaVotacao from '../components/CardSalaVotacao';
......@@ -10,10 +8,7 @@ import moment from 'moment';
class Historico extends Component {
constructor(props) {
super(props)
this.state = {
salas: {}
}
super(props)
}
static navigationOptions = {
title: 'Histórico de Votações',
......@@ -26,19 +21,6 @@ class Historico extends Component {
this.props.navigation.navigate('Andamento', { 'sala': 'Não disponível' });
}
componentWillMount() {
salasRef.orderByChild("uid").on('value', snapshot => {
let salas = snapshot.val();
if (salas != null) {
salas = Object.values(salas);
this.setState(() => ({
salas
}))
}
});
}
getStatus = (dataFinal, dataInicial, horaFinal, horaInicial, informacaoExtra) => {
let firstMoment = moment(`${dataInicial} ${horaInicial}`, 'DD/MM/YYYY HH:mm');
let finalMoment = moment(`${dataFinal} ${horaFinal}`, 'DD/MM/YYYY HH:mm');
......@@ -50,7 +32,7 @@ class Historico extends Component {
}
render() {
const { salas } = this.state;
const salas = this.props.navigation.getParam('salas', []);
const { height } = Dimensions.get('screen');
return (
<View style={[styles.container, { height: height }]}>
......
import React, { Component } from 'react';
import { View, ScrollView, Dimensions } from 'react-native';
import { View, ScrollView, Dimensions, AsyncStorage } from 'react-native';
import { db } from '../config';
let salasRef = db.ref('salas/');
import BotaoNovaSala from '../components/BotaoNovaSala';
......@@ -13,38 +13,65 @@ export default class Inicio extends Component {
constructor(props) {
super(props);
this.state = {
salas: []
salas: [],
souAdm: false
}
}
static navigationOptions = {
title: 'Votações disponíveis',
};
componentWillMount() {
salasRef.orderByChild("uid").on('value', snapshot => {
let salas = snapshot.val();
if (salas != null) {
salas = Object.values(salas);
this.setState(() => ({
salas
}))
}
AsyncStorage.getItem('@UID').then(uid => {
if (salas != null) {
salas = Object.values(salas);
salas = salas.filter(sala => {
if(sala.adm_uid === uid){
return true;
}
if(sala.votantes){
return [...sala.votantes].filter(v => v.uid === uid).length;
}
});
this.setState(() => ({
salas, uid
}))
}
},
error => console.log('Erro ao carregar as salas.', error));
});
}
handleVisualizar = (item, index) => {
const { salas } = this.state;
if (item)
const { uid, salas } = this.state
if (item){
if(uid && item.adm_uid === uid){
return this.props.navigation.navigate('Andamento', { 'sala': item });
}
this.props.navigation.navigate('Votacao', { 'sala': item, 'salas': salas, 'indiceSala': index });
} else {
this.props.navigation.navigate('Votacao', { 'sala': item, 'salas': salas, 'indiceSala': index });
else
this.props.navigation.navigate('Votacao', { 'sala': 'Não disponível' });
}
}
handleSelect = selected => {
this.setState({ selected });
}
getHistorico = salas => salas.filter(item => {
const {dataFinal, dataInicial, horaFinal, horaInicial } = item;
return this.getStatus(dataFinal, dataInicial, horaFinal, horaInicial, false) == 'encerrada';
})
render() {
const { salas } = this.state;
const { height } = Dimensions.get('screen');
const salasmock = [{
dataFinal: '28/06/2019', dataInicial:'28/06/2019', horaFinal:'28/06/2019', horaInicial:'28/06/2019', descricao:'a',titulo:'a'
}]
return (
<View style={[styles.container, { height: height }]}>
<ScrollView style={{ maxHeight: height - 240, marginBottom: 5 }}>
......@@ -84,7 +111,7 @@ export default class Inicio extends Component {
/>
<Barra
index={false}
onPress={() => this.props.navigation.navigate('Historico')}
onPress={() => this.props.navigation.navigate('Historico', {'salas': this.getHistorico(salas)})}
/>
</View>
);
......
import React, { Component } from 'react';
import { View, Image, TouchableOpacity,Text, StyleSheet, KeyboardAvoidingView } from 'react-native';
import { View, Image, TouchableOpacity,Text, StyleSheet, KeyboardAvoidingView, AsyncStorage } from 'react-native';
import { auth } from '../config';
import InputEmail from '../components/InputEmail';
import InputSenha from '../components/InputSenha';
import styles from '../styles/estilos';
import AuthService from '../shared/AuthService';
export default class Login extends Component {
constructor(props) {
super(props)
this.state = {
salas: {},
email: 'dev@evote.com',
senha: '123456',
email: '',
senha: '',
errorMessage:''
}
}
......@@ -20,14 +21,28 @@ export default class Login extends Component {
const { email, senha } = this.state;
auth
.signInWithEmailAndPassword(email, senha)
.then((data) => this.props.navigation.navigate('Inicio'))
.catch(error => this.setState({ errorMessage: 'E-mail ou senha incorretos.' }));
.then((data) => {
console.log(JSON.stringify(data));
// AuthService.setUID(data.user.uid).then(
AsyncStorage.setItem('@UID', data.user.uid).then(
() => this.props.navigation.navigate('Inicio')
)
//)
})
.catch(error => {
console.log(error);
this.setState({ errorMessage: 'E-mail ou senha incorretos.' })
})
}
static navigationOptions = {
title: 'Bem-vind@ ao eVote!'
};
static getUID = () => {
return AsyncStorage.getItem()
}
render(){
return(
<KeyboardAvoidingView style={styles.container} behavior="padding" enabled number="2">
......@@ -36,33 +51,37 @@ export default class Login extends Component {
</View>
<View style={{flex: 3}}>
<InputEmail
autoCorrect={false}
label=" "
keyboardType='email-address'
returnKeyType="next"
onChangeText={email => this.setState({ email })}
value={this.state.email}
placeholder='E-mail'
/>
autoCorrect={false}
keyboardType='email-address'
returnKeyType="next"
label={'login'}
onChangeText={email => this.setState({ email })}
value={this.state.email}
placeholder='E-mail' />
<InputSenha
label=" "
autoCorrect={false}
returnKeyType="go"
placeholder='Senha'
onChangeText={senha => this.setState({ senha })}
value={this.state.senha}
/>
<InputSenha
autoCorrect={false}
returnKeyType="go"
placeholder='Senha'
label={'senha'}
onChangeText={senha => this.setState({ senha })}
value={this.state.senha}/>
<Text style={custom.notice}>
{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>
......
......@@ -158,7 +158,7 @@ export default class Questao extends Component {
let { questao } = this.state;
this.setState({erroPergunta: ""});
// [ text, 0, []] = texto da alternativa : contador de votos : array de votantes dessa alternativa
questao[questao.length-1].alternativas[index] = [ text, 0, []];
questao[questao.length-1].alternativas[index] = [text, 0, votantes = []];
this.setState({questao: questao});
}
......
import React, { Component } from 'react';
import { View, Text, ScrollView, KeyboardAvoidingView } from 'react-native';
import { View, Text, ScrollView, KeyboardAvoidingView, AsyncStorage } from 'react-native';
import Aviso from '../components/Aviso';
import BotaoAnterior from '../components/BotaoAnterior';
import BotaoProximo from '../components/BotaoProximo';
......@@ -38,7 +38,14 @@ export default class Sala extends Component {
headerLeft: null
};
horaInvalida = (hF, hI) => {
componentWillMount(){
AsyncStorage.getItem('@UID').then(uid => {
this.setState({sala: {...this.state.sala, adm_uid: uid}});
},
error => console.log('EEERROOOOU', error));
}
horaInvalida = (hF,hI) => {
const { dataFinal, dataInicial } = this.state.sala;
if (dataFinal == dataInicial) {
const horaFinal = hF.split(":");
......
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
}
})
import React, { Component } from 'react';
import { View, Text, FlatList, ActivityIndicator, ScrollView } from 'react-native';
import { View, Text, FlatList, ActivityIndicator, ScrollView, AsyncStorage } from 'react-native';
import BotaoProximo from '../components/BotaoProximo';
import NotificacaoHeader from '../components/NotificacaoHeader';
import BotaoAlternativa from '../components/BotaoAlternativa';
......@@ -9,6 +9,7 @@ import votarStyles from '../styles/votarStyles';
import BotaoMedio from '../components/BotaoMedio';
import BotaoAnterior from '../components/BotaoAnterior';
import { db } from '../config';
let salasRef = db.ref('salas/');
export default class Votar extends Component {
......@@ -27,10 +28,14 @@ export default class Votar extends Component {
componentDidMount() {
const { salas, indiceSala } = this.props;
const { alternativas, } = this.props.questao;
const { alternativas } = this.props.questao;
this.setState({ alternativas, indiceSala, salas });
}
getUID = async () => {
return await AsyncStorage.getItem('@UID');
}
handleSubmit = async () => {
const sent = await this.sendData();
if (sent) {
......@@ -64,6 +69,11 @@ export default class Votar extends Component {
let contadorVotos = questoes[x].alternativas[posicaoAlternativa][1];
contadorVotos = contadorVotos + 1;
questoes[x].alternativas[posicaoAlternativa][1] = contadorVotos;
if(questoes[x].alternativas[posicaoAlternativa][2])
questoes[x].alternativas[posicaoAlternativa][2].push(await this.getUID());
else {
questoes[x].alternativas[posicaoAlternativa][2] = new Array(await this.getUID());
}
}
}
}
......
import { AsyncStorage } from "react-native";
export class AuthService {
static setUID(uid) {
return AsyncStorage.setItem('@UID', uid);
}
static getUID() {
return AsyncStorage.getItem('@UID');
}
}
// export { AuthService }
\ No newline at end of file
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!