Merge pull request #18 from lemeow125/feature/register

Added registration functionality
This commit is contained in:
lemeow125 2023-04-16 13:55:08 +08:00 committed by GitHub
commit 9efcd6b08c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,56 +1,72 @@
import * as React from 'react';
import {View, Text, TextInput} from 'react-native';
import styles from '../../styles';
import Background from '../../Components/Background/Background';
import { SafeAreaView } from 'react-native-safe-area-context';
import * as React from "react";
import { View, Text, TextInput } from "react-native";
import styles from "../../styles";
import Background from "../../Components/Background/Background";
import { SafeAreaView } from "react-native-safe-area-context";
import { useState } from "react";
import {TouchableOpacity} from "react-native";
import { TouchableOpacity } from "react-native";
import { UserRegister } from "../../Components/Api/Api";
export default function Register() {
const [username, setUsername] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [feedback, setFeedback] = useState("");
return (
<Background>
<Text style={{...styles.text_white, ...{fontSize: 32}}}></Text>
<Text style={{ ...styles.text_white, ...{ fontSize: 32 } }}></Text>
<SafeAreaView>
<View style={styles.container}>
<Text style ={styles.loginlabel}>Create an Account</Text>
<View style={styles.inputView}>
<TextInput
style={styles.TextInput}
placeholder="Email"
placeholderTextColor="white"
onChangeText={setEmail}
value={email}
/>
</View>
<View style={styles.container}>
<Text style={styles.loginlabel}>Create an Account</Text>
<View style={styles.inputView}>
<TextInput
style={styles.TextInput}
placeholder="Username"
placeholderTextColor="white"
onChangeText={setUsername}
value={username}
/>
</View>
<View style={styles.inputView}>
<TextInput
style={styles.TextInput}
placeholder="Password"
placeholderTextColor="white"
secureTextEntry={true}
onChangeText={setPassword}
value={password}
/>
</View>
<TouchableOpacity style={styles.registerbtn}>
<Text style={styles.registertext}>REGISTER</Text>
</TouchableOpacity>
</View>
<TextInput
style={styles.TextInput}
placeholder="Email"
placeholderTextColor="white"
onChangeText={setEmail}
value={email}
/>
</View>
<View style={styles.inputView}>
<TextInput
style={styles.TextInput}
placeholder="Username"
placeholderTextColor="white"
onChangeText={setUsername}
value={username}
/>
</View>
<View style={styles.inputView}>
<TextInput
style={styles.TextInput}
placeholder="Password"
placeholderTextColor="white"
secureTextEntry={true}
onChangeText={setPassword}
value={password}
/>
</View>
<TouchableOpacity
onPress={async () => {
setUsername("");
setPassword("");
console.log("heh");
if (await UserRegister({ username, email, password })) {
setFeedback(
"Registration success. Please check your email address for activation"
);
} else {
setFeedback("Invalid credentials specified");
}
}}
style={styles.registerbtn}
>
<Text style={styles.registertext}>REGISTER</Text>
</TouchableOpacity>
<Text style={styles.registertext}>{feedback}</Text>
</View>
</SafeAreaView>
</Background>
);
}