mirror of
https://github.com/lemeow125/StudE-Frontend.git
synced 2025-06-28 16:25:46 +08:00
Added functional registration
This commit is contained in:
parent
dfc20753b3
commit
26b3db25f0
23 changed files with 679 additions and 57 deletions
73
src/components/Api/Api.tsx
Normal file
73
src/components/Api/Api.tsx
Normal file
|
@ -0,0 +1,73 @@
|
|||
import axios from "axios";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import {
|
||||
ActivationParams,
|
||||
LoginParams,
|
||||
RegistrationParams,
|
||||
} from "../../interfaces/Interfaces";
|
||||
|
||||
let debug = true;
|
||||
export let backendURL = "";
|
||||
if (debug) {
|
||||
backendURL = "http://10.0.10.8:8000";
|
||||
} else {
|
||||
backendURL = "https://keannu125.pythonanywhere.com";
|
||||
}
|
||||
|
||||
const instance = axios.create({
|
||||
baseURL: backendURL,
|
||||
timeout: 1000,
|
||||
});
|
||||
|
||||
// App APIs
|
||||
|
||||
// User APIs
|
||||
|
||||
export function UserRegister(register: RegistrationParams) {
|
||||
console.log(JSON.stringify(register));
|
||||
return instance
|
||||
.post("/api/v1/accounts/users/", register)
|
||||
.then(async (response) => {
|
||||
return [response.status];
|
||||
})
|
||||
.catch((error) => {
|
||||
return [error.response.status, error.response.data];
|
||||
});
|
||||
}
|
||||
|
||||
export function UserLogin(user: LoginParams) {
|
||||
return instance
|
||||
.post("/api/v1/accounts/token/login/", user)
|
||||
.then(async (response) => {
|
||||
AsyncStorage.setItem("token", JSON.stringify(response.data.auth_token));
|
||||
return true;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Login Failed: " + error);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
export async function UserInfo() {
|
||||
const token = JSON.parse((await AsyncStorage.getItem("token")) || "{}");
|
||||
return instance
|
||||
.get("/api/v1/accounts/users/me/", {
|
||||
headers: {
|
||||
Authorization: "Token " + token,
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
|
||||
export function UserActivate(activation: ActivationParams) {
|
||||
return instance
|
||||
.post("/api/v1/accounts/users/activation/", activation)
|
||||
.then(async (response) => {
|
||||
return true;
|
||||
})
|
||||
.catch((error) => {
|
||||
return false;
|
||||
});
|
||||
}
|
23
src/components/Button/Button.tsx
Normal file
23
src/components/Button/Button.tsx
Normal file
|
@ -0,0 +1,23 @@
|
|||
import * as React from "react";
|
||||
import { Text, Pressable, GestureResponderEvent } from "react-native";
|
||||
import styles from "../../styles";
|
||||
|
||||
export interface props {
|
||||
children: React.ReactNode;
|
||||
onPress: (event: GestureResponderEvent) => void;
|
||||
color: string;
|
||||
}
|
||||
|
||||
export default function Button(props: props) {
|
||||
return (
|
||||
<Pressable
|
||||
onPress={props.onPress}
|
||||
style={{
|
||||
...styles.button_template,
|
||||
...{ backgroundColor: props.color, width: "50%" },
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</Pressable>
|
||||
);
|
||||
}
|
|
@ -14,7 +14,11 @@ export default function DrawerButton(props: props) {
|
|||
onPress={props.onPress}
|
||||
style={{
|
||||
...styles.button_template,
|
||||
...{ backgroundColor: props.color, width: "95%" },
|
||||
...{
|
||||
backgroundColor: props.color,
|
||||
width: "95%",
|
||||
justifyContent: "flex-start",
|
||||
},
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
|
|
|
@ -22,7 +22,7 @@ export default function CustomDrawerContent(props: {}) {
|
|||
...{ justifyContent: "center" },
|
||||
}}
|
||||
>
|
||||
<AppIcon size={32} color={colors.icon_color} />
|
||||
<AppIcon size={32} />
|
||||
<Text style={styles.text_white_medium}>Stud-E</Text>
|
||||
</View>
|
||||
<DrawerButton
|
||||
|
@ -31,7 +31,7 @@ export default function CustomDrawerContent(props: {}) {
|
|||
navigation.navigate("Home");
|
||||
}}
|
||||
>
|
||||
<HomeIcon size={32} color={colors.icon_color} />
|
||||
<HomeIcon size={32} />
|
||||
<Text style={styles.text_white_medium}>Home</Text>
|
||||
</DrawerButton>
|
||||
<DrawerButton
|
||||
|
@ -40,7 +40,7 @@ export default function CustomDrawerContent(props: {}) {
|
|||
navigation.navigate("Login");
|
||||
}}
|
||||
>
|
||||
<LoginIcon size={32} color={colors.icon_color} />
|
||||
<LoginIcon size={32} />
|
||||
<Text style={styles.text_white_medium}>Login</Text>
|
||||
</DrawerButton>
|
||||
<DrawerButton
|
||||
|
@ -49,7 +49,7 @@ export default function CustomDrawerContent(props: {}) {
|
|||
navigation.navigate("Register");
|
||||
}}
|
||||
>
|
||||
<SignupIcon size={32} color={colors.icon_color} />
|
||||
<SignupIcon size={32} />
|
||||
<Text style={styles.text_white_medium}>Register</Text>
|
||||
</DrawerButton>
|
||||
</DrawerContentScrollView>
|
||||
|
|
|
@ -24,7 +24,7 @@ const DrawerScreenSettings: DrawerNavigationOptions = {
|
|||
<View
|
||||
style={{ flexDirection: "row", marginRight: 16, alignItems: "center" }}
|
||||
>
|
||||
<AppIcon size={32} color={colors.icon_color} />
|
||||
<AppIcon size={32} />
|
||||
</View>
|
||||
),
|
||||
};
|
||||
|
|
8
src/components/IsNumber/IsNumber.tsx
Normal file
8
src/components/IsNumber/IsNumber.tsx
Normal file
|
@ -0,0 +1,8 @@
|
|||
export default function IsNumber(number: string) {
|
||||
const re = /^[0-9\b]+$/;
|
||||
if (re.test(number)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
9
src/components/ParseError/ParseError.tsx
Normal file
9
src/components/ParseError/ParseError.tsx
Normal file
|
@ -0,0 +1,9 @@
|
|||
export default function ParseError(text: string) {
|
||||
return text
|
||||
.replaceAll(/[{}()"]/g, " ")
|
||||
.replaceAll(/,/g, "\n")
|
||||
.replaceAll(":", "")
|
||||
.replaceAll("[", "")
|
||||
.replaceAll("]", "")
|
||||
.replaceAll(".", "");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue