katoikia-app/mobile-ui/components/LogIn.js

175 lines
4.0 KiB
JavaScript
Raw Permalink Normal View History

import React from "react";
2022-08-18 22:02:50 +00:00
import Cookies from 'universal-cookie';
import {
Text,
Link,
Center,
Heading,
VStack,
Box,
FormControl,
Button,
2022-08-17 16:36:33 +00:00
Image
} from "native-base";
import logo from "../assets/logo-katoikia.png";
2022-08-13 03:56:58 +00:00
import { Entypo } from '@expo/vector-icons';
import { MaterialCommunityIcons } from '@expo/vector-icons';
2022-08-16 05:16:44 +00:00
import { View, TextInput, StyleSheet } from "react-native";
2022-08-18 22:02:50 +00:00
const baseURL = "http://localhost:4000/user/loginUser";
const cookies = new Cookies();
2022-08-16 05:16:44 +00:00
const styles = StyleSheet.create({
input: {
height: 40,
margin: 10,
borderWidth: 0.5,
padding: 5,
flex: 1,
paddingTop: 10,
paddingRight: 10,
paddingBottom: 10,
paddingLeft: 0,
marginTop: 50,
marginBottom: 10
},
iconStyle: {
padding: 10,
},
viewSection: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
2022-08-16 20:27:34 +00:00
margin: 10
},
container: {
2022-08-16 05:16:44 +00:00
}
})
2022-08-18 22:02:50 +00:00
const iniciarSesion = async() => {
try {
await fetch(baseURL, {
cache: 'no-cache',
method: 'POST',
body: JSON.stringify(),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => {
if (response.status != 201){
console.log('ocurrio un error ');
}else{
return response.json();
}
})
.then( response => {
const user = response.message
if(user.user_type == '3'){
cookies.set('id',user._id, {path: "/"} )
cookies.set('name',user.name, {path: "/"} )
cookies.set('email',user.email, {path: "/"} )
cookies.set('type',user.user_type, {path: "/"} )
}
})
} catch (error) {
}
}
export default function LogIn({navigation}) {
return (
<Center w="100%">
<Box safeArea p="2" py="8" w="90%" maxW="290">
2022-08-18 22:02:50 +00:00
<Center>
<Image source={
logo
2022-08-18 22:02:50 +00:00
} width={500} height={550} m='2'
alt="Katoikia logo" size="xl" justifyContent="center" />
2022-08-18 22:02:50 +00:00
</Center>
<Heading
size="lg"
fontWeight="600"
color="coolGray.800"
_dark={{
color: "warmGray.50",
}}
>
Bienvenido a Katoikia
</Heading>
<Heading
mt="1"
_dark={{
color: "warmGray.200",
}}
color="coolGray.600"
fontWeight="medium"
size="xs"
>
Su app de comunidad de confianza
</Heading>
2022-08-16 20:27:34 +00:00
<View style={styles.container}>
<VStack space={3} mt="5">
<FormControl>
2022-08-13 03:56:58 +00:00
<FormControl.Label> Correo Electrónico </FormControl.Label>
2022-08-16 05:16:44 +00:00
<View style={styles.viewSection}>
<Entypo name="email" size={20} color="grey" style={styles.iconStyle} />
<TextInput type="text" style={styles.input} />
2022-08-13 03:56:58 +00:00
</View>
</FormControl>
<FormControl>
2022-08-13 03:56:58 +00:00
<FormControl.Label> Contraseña </FormControl.Label>
2022-08-16 05:16:44 +00:00
<View style={styles.viewSection}>
<MaterialCommunityIcons name="form-textbox-password" size={20} color="grey" style={styles.iconStyle}/>
<TextInput type="password" style={styles.input} />
2022-08-13 03:56:58 +00:00
</View>
<Link
_text={{
fontSize: "xs",
fontWeight: "500",
color: "indigo.500",
2022-08-18 22:02:50 +00:00
marginTop: "10"
}}
alignSelf="flex-end"
mt="1"
onPress={() => navigation.navigate('Password')}
2022-08-13 03:56:58 +00:00
>
2022-08-13 03:56:58 +00:00
Recuperar contraseña
</Link>
</FormControl>
2022-08-17 21:08:38 +00:00
<Button mt="2" backgroundColor="#D7A86E" onPress={() => navigation.navigate('Comunicados')}
>
<Text>Continuar</Text>
</Button>
2022-08-16 20:27:34 +00:00
</VStack></View>
</Box>
</Center>
);
2022-08-16 05:16:44 +00:00
}