Added activation page

This commit is contained in:
keannu125 2023-02-27 00:07:46 +08:00
parent 4caf7479fd
commit 115b8b207f
3 changed files with 58 additions and 0 deletions

View file

@ -65,3 +65,21 @@ export function UserInfo() {
console.log(error); console.log(error);
}); });
} }
export interface activation {
uid: string;
token: string;
}
export function UserActivate(activation: activation) {
return axios
.post("http://localhost:8000/api/v1/accounts/users/activation/", activation)
.then(async (response) => {
console.log("Activation Success");
return true;
})
.catch((error) => {
console.log("Activation failed: " + error);
return false;
});
}

View file

@ -0,0 +1,35 @@
import styles from "../../styles";
import Header from "../../Components/Header/Header";
import { useParams } from "react-router-dom";
import { useState } from "react";
import { UserActivate } from "../../Components/Api/Api";
export interface activation {
uid: string;
token: string;
}
export default function Activation() {
let { uid, token } = useParams();
const [activationStatus, setStatus] = useState("Activating...");
async function verify(activation: activation) {
let status = await UserActivate(activation);
if (status) {
setStatus("Success!");
} else {
setStatus("Invalid Activation Link");
}
}
if (uid && token) {
verify({ uid, token });
}
return (
<div style={styles.background}>
<Header />
<div style={styles.note}>
<p style={styles.text_medium}>User ID: {uid}</p>
<p style={styles.text_medium}>Activation Token: {token}</p>
<p style={styles.text_medium}>{activationStatus}</p>
</div>
</div>
);
}

View file

@ -7,6 +7,7 @@ import { createBrowserRouter, RouterProvider } from "react-router-dom";
import Home from "./Routes/Home/Home"; import Home from "./Routes/Home/Home";
import NewNote from "./Routes/NewNote/NewNote"; import NewNote from "./Routes/NewNote/NewNote";
import Login from "./Routes/Login/Login"; import Login from "./Routes/Login/Login";
import Activation from "./Routes/Activation/Activation";
import { QueryClient, QueryClientProvider } from "react-query"; import { QueryClient, QueryClientProvider } from "react-query";
@ -28,6 +29,10 @@ const router = createBrowserRouter([
path: "/Login", path: "/Login",
element: <Login />, element: <Login />,
}, },
{
path: "/Activation/:uid/:token",
element: <Activation />,
},
]); ]);
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(