Skip to content

Commit

Permalink
logging in in Login page
Browse files Browse the repository at this point in the history
  • Loading branch information
dbence2002 committed Sep 18, 2023
1 parent d325034 commit fb73c5c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 20 deletions.
6 changes: 3 additions & 3 deletions frontend/src/RoutingComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {updateData} from "./util/UpdateData";
import FadeIn from "./components/util/FadeIn";
import {routeMap} from "./config/RouteConfig";
import UserContext from "./contexts/user/UserContext";
import {authenticate} from "./util/User";
import {authenticate} from "./util/Auth";
import {findRouteIndex} from "./util/FindRouteIndex";
import Logout from "./pages/auth/Logout";

Expand Down Expand Up @@ -96,12 +96,12 @@ function RoutingComponent() {
</FadeIn>}/>
<Route path={routeMap.logout} element={<Logout/>}/>
<Route path={routeMap.profile} element={<Profile/>}>
<Route path={routeMap.profile} element={<ProfileMain/>}/>
<Route index element={<ProfileMain/>}/>
<Route path={routeMap.profileSubmissions} element={<ProfileSubmissions/>}/>
<Route path={routeMap.profileSettings} element={<ProfileSettings/>}/>
</Route>
<Route path={routeMap.problem} element={<Problem/>}>
<Route path={routeMap.problem} element={<ProblemStatement/>}/>
<Route index element={<ProblemStatement/>}/>
<Route path={routeMap.problemSubmit} element={<ProblemSubmit/>}/>
<Route path={routeMap.problemSubmissions} element={<ProblemSubmissions/>}/>
<Route path={routeMap.problemRanklist} element={<ProblemRanklist/>}/>
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/pages/Archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import ProfileSideBar from '../components/concrete/other/ProfileSidebar'
import DropdownListFrame from '../components/container/DropdownListFrame'
import checkData from "../util/CheckData";
import React from "react";
import {login} from "../util/User";
import {login} from "../util/Auth";
import {matchPath, useLocation} from "react-router-dom";

function Archive({data}) {
login("dbence", "abcd1234").then(resp => {
window.flash(resp.message, resp.success? "success": "failure")
})
const categoriesContent = data.categories.map((item, index) =>
<div className="mb-3" key={index}>
<DropdownListFrame title={item.title} tree={{"children": item.children}}/>
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/pages/Info.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SVGTitleComponent from "../svg/SVGTitleComponent";
import RoundedTable from "../components/container/RoundedTable";
import checkData from "../util/CheckData";
import React, {useState} from "react";
import {authenticate} from "../util/User";
import {authenticate} from "../util/Auth";
import {matchPath, useLocation} from "react-router-dom";

function CopyButton({ command }) {
Expand Down Expand Up @@ -75,10 +75,6 @@ function InfoTable() {
}

function Info() {
authenticate().then(resp => {
window.flash(resp? "Sikeres azonosítás!": "Az azonosítás sikertelen.", resp? "success": "failure")
console.log(JSON.stringify(resp))
})
return (
<div className="w-full flex justify-center">
<div className="flex justify-center w-full max-w-7xl">
Expand Down
20 changes: 17 additions & 3 deletions frontend/src/pages/auth/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,34 @@ import RoundedFrame from '../../components/container/RoundedFrame';
import TextBox from '../../components/input/TextBox';
import {SVGAvatar, SVGGoogle} from '../../svg/SVGs';
import SVGTitleComponent from '../../svg/SVGTitleComponent';
import {login} from "../../util/Auth";
import {useState} from "react";
import {useNavigate} from "react-router-dom";
import {routeMap} from "../../config/RouteConfig";

function LoginFrame() {
const navigate = useNavigate()
const [username, setUsername] = useState("")
const [password, setPassword] = useState("")
const titleComponent = <SVGTitleComponent svg={<SVGAvatar cls="w-[1.1rem] h-[1.1rem] mr-2"/>} title="Belépés"/>
const handleLogin = () => {
login(username, password).then(resp => {
window.flash(resp.message, resp.success? "success": "failure")
}).then(() => {
navigate(routeMap.main)
})
}
return (
<RoundedFrame titleComponent={titleComponent}>
<div className="px-10 py-8">
<div className="mb-4">
<TextBox id="userName" label="Felhasználónév"/>
<TextBox id="userName" label="Felhasználónév" initText={username} onChange={(newText) => setUsername(newText)} />
</div>
<div className="mb-6">
<TextBox id="password" label="Jelszó" type="password"/>
<TextBox id="password" label="Jelszó" initText={password} type="password" onChange={(newText) => setPassword(newText)}/>
</div>
<div className="flex justify-center mb-2">
<button className="btn-indigo mr-2 w-1/2">Belépés</button>
<button className="btn-indigo mr-2 w-1/2" onClick={handleLogin}>Belépés</button>
<button className="relative btn-gray flex items-center justify-between w-1/2">
<div className="h-full flex items-center absolute left-2.5">
<SVGGoogle/>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/pages/auth/Logout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useNavigate} from "react-router-dom";
import {logout} from "../../util/User";
import {logout} from "../../util/Auth";
import {useEffect} from "react";
import {routeMap} from "../../config/RouteConfig";

function Logout() {
const navigate = useNavigate()
Expand All @@ -11,7 +12,7 @@ function Logout() {
} else {
window.flash("Nem vagy belépve.", "failure")
}
navigate("/")
navigate(routeMap.main)
}, [])
return (
<></>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/profile/Profile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import TabFrame from '../../components/container/TabFrame'
import {matchPath, Outlet, useLocation, useParams} from 'react-router-dom';
import React, {useContext, useEffect, useState} from "react";
import {updateData, updatePageData} from "../../util/UpdateData";
import {updatePageData} from "../../util/UpdateData";
import FadeIn from "../../components/util/FadeIn";
import {routeMap} from "../../config/RouteConfig";
import PageLoadingAnimation from "../../components/util/PageLoadingAnimation";
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/pages/profile/ProfileSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {SVGLock, SVGSettings} from "../../svg/SVGs";
import SVGTitleComponent from "../../svg/SVGTitleComponent";
import {useParams, useNavigate} from "react-router-dom";
import UserContext from "../../contexts/user/UserContext";
import {routeMap} from "../../config/RouteConfig";

function PasswordChangeFrame() {
const [oldPw, setOldPw] = useState("");
Expand Down Expand Up @@ -66,7 +67,7 @@ function ProfileSettings() {

useEffect(() => {
if (!isLoggedIn || userData.username !== user) {
navigate("/")
navigate(routeMap.main)
window.flash("Nincs jogosultságod ehhez a művelethez.", "failure")
} else {
setVisible(true)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion frontend/src/util/UpdateData.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {findRouteIndex} from "./FindRouteIndex";
import {authenticate} from "./User";
import {authenticate} from "./Auth";

export async function updatePageData(location,
routesToFetch,
Expand Down

0 comments on commit fb73c5c

Please sign in to comment.