@@ -2,56 +2,15 @@ import * as React from 'react';
22import { useState , useRef } from 'react' ;
33import { StyleSheet , View , SafeAreaView , TextInput , Button , TouchableOpacity , Text , KeyboardAvoidingView , Platform } from 'react-native' ;
44import { useReducedMotion } from 'react-native-reanimated' ;
5+ import { handleLogin , handleSignup } from "./accountUtils" ;
6+
57
68export default function LoginScreen ( { navigation } ) {
79 const [ serverResponse , setServerResponse ] = useState ( "" ) ;
810 const [ username , setUsername ] = useState ( "" ) ;
911 const [ password , setPassword ] = useState ( "" ) ;
1012 const ref2 = React . useRef ( null ) ;
1113
12- const passphrase = "jr023uf1(£12g*" ;
13-
14- const handleLogin = async ( ) => {
15- if ( username == '' || password == '' ) {
16- alert ( "All fields have to be filled before logging in!" )
17- }
18- else {
19- console . log ( 'username: ' , username )
20- console . log ( 'password: ' , password )
21- // alert(`Username: ${username}\nPassword: ${password}`)
22- navigation . goBack ( )
23-
24- try {
25- const baseUrl = Platform . OS === 'web'
26- ? 'http://localhost:8000'
27- : process . env . EXPO_PUBLIC_API_URL ;
28- console . log ( `Sending request to ${ baseUrl } /login` ) ;
29-
30- const response = await fetch ( `${ baseUrl } /login` , {
31- method : 'POST' ,
32- headers : {
33- 'Content-Type' : 'application/json' ,
34- } ,
35- body : JSON . stringify ( { username : username , password : password } ) ,
36- } ) ;
37-
38- if ( ! response . ok ) {
39- throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
40- }
41-
42- // Await response and print message from server
43- const data = await response . json ( ) ;
44- alert ( data . message )
45-
46- console . log ( 'Server response:' , data ) ;
47- setServerResponse ( data . message ) ;
48- } catch ( error ) {
49- console . error ( 'Error details:' , error ) ;
50- setServerResponse ( `Error: ${ error . message } ` ) ;
51- }
52- }
53- } ;
54-
5514 return (
5615 < View style = { { flex : 1 , justifyContent : 'center' , alignItems : 'center' } } >
5716
@@ -73,7 +32,7 @@ export default function LoginScreen({ navigation }) {
7332 style = { styles . TextInput }
7433 />
7534
76- < TouchableOpacity style = { styles . TouchableOpacity } onPress = { handleLogin }
35+ < TouchableOpacity style = { styles . TouchableOpacity } onPress = { ( ) => handleLogin ( username , password , setServerResponse , navigation ) }
7736 color = "#841584" >
7837 < Text > Log In</ Text >
7938 </ TouchableOpacity >
@@ -90,6 +49,7 @@ const styles = StyleSheet.create({
9049 paddingVertical : 10 ,
9150 paddingHorizontal : 45 ,
9251 top : '-20%' ,
52+ //marginBottom: -150,
9353 } ,
9454 TextInput : {
9555 width : 100 ,
@@ -117,6 +77,20 @@ const styles = StyleSheet.create({
11777 shadowRadius : 5 ,
11878 elevation : 5 ,
11979 } ,
80+ TouchableOpacity1 : {
81+ alignItems : 'center' ,
82+ left : '0%' ,
83+ top : '5%' ,
84+ backgroundColor : '#007bff' ,
85+ paddingVertical : 10 ,
86+ paddingHorizontal : 40 ,
87+ borderRadius : 10 ,
88+ shadowColor : '#000' ,
89+ shadowOpacity : 0.2 ,
90+ shadowOffset : { width : 0 , height : 2 } ,
91+ shadowRadius : 5 ,
92+ elevation : 5 ,
93+ } ,
12094 TouchableOpacityText : {
12195 color : '#fff' ,
12296 fontWeight : 'bold' ,
0 commit comments