From d69b3a1b2cb0802d9c2878ee51c71b524d657c51 Mon Sep 17 00:00:00 2001 From: Felix Albrigtsen Date: Sat, 23 Apr 2022 10:20:24 +0200 Subject: [PATCH] Start LoginManager --- src/client/src/FrontPage.js | 36 +++++++++++++++++++++++++++++++++++ src/client/src/ProfilePage.js | 27 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/client/src/ProfilePage.js diff --git a/src/client/src/FrontPage.js b/src/client/src/FrontPage.js index 74025ae..f27f039 100644 --- a/src/client/src/FrontPage.js +++ b/src/client/src/FrontPage.js @@ -6,6 +6,7 @@ import TournamentManager from "./TournamentManager.js"; import TournamentHistory from "./TournamentHistory"; import TournamentTeams from "./TournamentTeams"; import LoginPage from "./LoginPage"; +import ProfilePage from "./ProfilePage"; import AppBar from './components/AsuraBar'; import { Button, Container, Typography, Box, Stack, Card, CardContent, CardMedia, Paper, Grid, Icon, TextField } from "@mui/material"; import AddCircleIcon from '@mui/icons-material/AddCircle'; @@ -194,6 +195,40 @@ function Home() { ); } +class LoginManager { + user = { + name: "", + email: "", + googleId: "", + asuraId: -1, + isManager: false + }; + + checkLogin() { + fetch(process.env.REACT_APP_API_URL + `/users/getSavedUser`) + .then(res => res.json()) + .then(data => { + if (data.status !== "OK") { + console.error(data); + return; + } + console.log(data); + this.user = data.data; + }) + .catch((err) => console.log(err.message)); + } + + isLoggedIn() { + return this.user.googleId !== undefined && this.user.googleId !== "" && this.user.asuraId !== undefined && this.user.asuraId !== -1; + } + isManager() { + return this.isLoggedIn() && this.user.isManager; + } +} + +let login = new LoginManager(); +login.checkLogin(); + export default function App() { return ( @@ -206,6 +241,7 @@ export default function App() { } /> } /> } /> + } /> diff --git a/src/client/src/ProfilePage.js b/src/client/src/ProfilePage.js new file mode 100644 index 0000000..2738e96 --- /dev/null +++ b/src/client/src/ProfilePage.js @@ -0,0 +1,27 @@ +import * as React from "react"; +import { BrowserRouter as Router, Link, Route, Routes } from "react-router-dom"; +import AppBar from "./components/AsuraBar"; +import ErrorSnackbar from "./components/ErrorSnackbar"; +import { Button, TextField, Stack, InputLabel, Select, Container, Slider, Paper, Box, Grid, Typography } from '@mui/material'; + +export default function ProfilePage(props) { + if (!props.login) { + return

Something went very wrong

+ } + console.log(props.login.user); + return (<> + + + {props.login.isLoggedIn ? <> + + + + :<> + + You are not logged in. + + } + + + ) +} \ No newline at end of file