From 77b0755a8e23f5325d391bebeccc327ee03044a9 Mon Sep 17 00:00:00 2001 From: Maria Sanchez Date: Thu, 18 Aug 2022 16:02:50 -0600 Subject: [PATCH] mobile log in --- mobile-ui/App.js | 4 ++- mobile-ui/components/LogIn.js | 50 +++++++++++++++++++++++++++++++++-- mobile-ui/package-lock.json | 44 +++++++++++++++++++++++++++++- mobile-ui/package.json | 3 ++- 4 files changed, 96 insertions(+), 5 deletions(-) diff --git a/mobile-ui/App.js b/mobile-ui/App.js index 8d44c4c4..fd210975 100644 --- a/mobile-ui/App.js +++ b/mobile-ui/App.js @@ -48,7 +48,9 @@ export default function App() { }}} /> - + diff --git a/mobile-ui/components/LogIn.js b/mobile-ui/components/LogIn.js index 77b203bb..eeb75cb9 100644 --- a/mobile-ui/components/LogIn.js +++ b/mobile-ui/components/LogIn.js @@ -1,4 +1,5 @@ import React from "react"; +import Cookies from 'universal-cookie'; import { Text, Link, @@ -15,6 +16,9 @@ import { Entypo } from '@expo/vector-icons'; import { MaterialCommunityIcons } from '@expo/vector-icons'; import { View, TextInput, StyleSheet } from "react-native"; +const baseURL = "http://localhost:4000/user/loginUser"; +const cookies = new Cookies(); + const styles = StyleSheet.create({ input: { height: 40, @@ -47,17 +51,58 @@ const styles = StyleSheet.create({ } }) +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 (
- + Katoikia logo +
+ = 0.6" + } + }, "node_modules/copy-descriptor": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz", @@ -10824,6 +10838,15 @@ "node": ">=0.10.0" } }, + "node_modules/universal-cookie": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/universal-cookie/-/universal-cookie-4.0.4.tgz", + "integrity": "sha512-lbRVHoOMtItjWbM7TwDLdl8wug7izB0tq3/YVKhT/ahB4VDvWMyvnADfnJI8y6fSvsjh51Ix7lTGC6Tn4rMPhw==", + "dependencies": { + "@types/cookie": "^0.3.3", + "cookie": "^0.4.0" + } + }, "node_modules/universalify": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz", @@ -14293,6 +14316,11 @@ "resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz", "integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==" }, + "@types/cookie": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.3.3.tgz", + "integrity": "sha512-LKVP3cgXBT9RYj+t+9FDKwS5tdI+rPBXaNSkma7hvqy35lc7mAokC2zsqWJH0LaqIt3B962nuYI77hsJoT1gow==" + }, "@types/graceful-fs": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.5.tgz", @@ -15173,6 +15201,11 @@ "safe-buffer": "~5.1.1" } }, + "cookie": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", + "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==" + }, "copy-descriptor": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz", @@ -19605,6 +19638,15 @@ } } }, + "universal-cookie": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/universal-cookie/-/universal-cookie-4.0.4.tgz", + "integrity": "sha512-lbRVHoOMtItjWbM7TwDLdl8wug7izB0tq3/YVKhT/ahB4VDvWMyvnADfnJI8y6fSvsjh51Ix7lTGC6Tn4rMPhw==", + "requires": { + "@types/cookie": "^0.3.3", + "cookie": "^0.4.0" + } + }, "universalify": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz", diff --git a/mobile-ui/package.json b/mobile-ui/package.json index 43ee388e..9fa4b879 100644 --- a/mobile-ui/package.json +++ b/mobile-ui/package.json @@ -33,7 +33,8 @@ "react-native-safe-area-context": "3.3.2", "react-native-screens": "~3.10.1", "react-native-svg": "12.1.1", - "react-native-web": "0.17.1" + "react-native-web": "0.17.1", + "universal-cookie": "^4.0.4" }, "devDependencies": { "@babel/core": "^7.12.9"