import React,{useState} from ‘react’;
import {View, Text, Button, TextInput, TouchableOpacity } from ‘react-native’;
export function Login({props, navigation }) {
const UserLoginFunction = () =>{
const [id, setId] = useState('');
const [password, setPw] = useState('');
fetch(‘https://localhost/User_Login.php’, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: id,
password: password
})
}).then((response) => response.json())
.then((responseJson) => {
// If server response message same as Data Matched
if(responseJson === 'Data Matched')
{
//Then open Profile activity and send user email to profile activity.
this.props.navigation.navigate('Detail');
}
else{
Alert.alert(responseJson);
}
}).catch((error) => {
console.error(error);
});
}
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>메인 페이지</Text>
<Text>{` 아이디는 : ${id}`}</Text>
<Text>{` 비밀번호는 : ${password} `}</Text>
<TextInput
style={{height:40, borderColor:'gray',borderWidth:1}}
value={id}
onChange={e=> setId(e.target.value)}
>
</TextInput>
<TextInput
style={{height:40, borderColor:'gray',borderWidth:1}}
value={password}
onChange={e=> setPw(e.target.value)}
>
</TextInput>
<Button
title="Go to Details"
onPress={() => {
navigation.navigate('Mypage', {
itemID : 86,
otherParam : 'Hello world'
});
}}
/>
<Button
title="로그인"
onPress={() => {
navigation.navigate('Member',{
name: '로그인 완료',
id: id,
password: password
});
}}
/>
<View style={{marginTop: 10}}>
<TouchableOpacity
style={{ alignSelf: 'stretch',
backgroundColor: '#01c853',
padding: 20,
alignItems: 'center'}}
onPress={UserLoginFunction}>
<Text>Login</Text>
</TouchableOpacity>
</View>
)}
export default Login;