-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from MarvinBo44/frontend/login-sec
add frontend security / login and logout
- Loading branch information
Showing
7 changed files
with
186 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import WeatherData from "./WeatherAPI.tsx"; | ||
import AddActivity from "./AddActivity.tsx"; | ||
import CurrentDay from "./DayView.tsx"; | ||
import {FormEvent, useEffect, useState} from "react"; | ||
import axios from "axios"; | ||
import {useNavigate} from "react-router-dom"; | ||
|
||
export default function HomePage(){ | ||
|
||
const [weather, setWeather] = useState<undefined>(); | ||
|
||
useEffect(() => { | ||
axios({ | ||
// url: "http://api.weatherapi.com/v1/forecast.json?key=6cc628764c7547e298d143025230108&q="+ort+"&days=3&aqi=yes&alerts=no", | ||
url: "https://api.weatherapi.com/v1/forecast.json?key=6cc628764c7547e298d143025230108&q=Lemgo&days=3&aqi=yes&alerts=no", | ||
method: "get" | ||
}).then(function (response) { | ||
setWeather(response.data); | ||
}); | ||
}, []); | ||
|
||
const nav = useNavigate(); | ||
function logout(event:FormEvent<HTMLFormElement>){ | ||
event.preventDefault() | ||
axios.post("/api/user/logout") | ||
.then((response) => console.log(response.data)) | ||
.then(()=>nav("/")) | ||
.catch((error) => console.log(error)) | ||
} | ||
|
||
return ( | ||
<div> | ||
<form onSubmit={logout}> | ||
<button>logout</button> | ||
</form> | ||
<WeatherData weather={weather}/> | ||
<AddActivity/> | ||
<CurrentDay weather={weather}/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {ChangeEvent, FormEvent, useState} from "react"; | ||
import axios from "axios"; | ||
import {Link, useNavigate} from "react-router-dom"; | ||
|
||
export default function LoginPage(){ | ||
|
||
const [username, setUsername] = useState(""); | ||
const [password, setPassword] = useState(""); | ||
|
||
const nav = useNavigate() | ||
|
||
function onChangeHandlerUsername(event:ChangeEvent<HTMLInputElement>){ | ||
setUsername(event.target.value) | ||
} | ||
|
||
function onChnageHandlerPassword(event:ChangeEvent<HTMLInputElement>){ | ||
setPassword(event.target.value) | ||
} | ||
|
||
function login(event:FormEvent<HTMLFormElement>){ | ||
event.preventDefault(); | ||
axios.post("/api/user/login", undefined, {auth: {username, password}}) | ||
.then(() => nav("/home")) | ||
.catch((error) => console.log(error)); | ||
} | ||
|
||
return( | ||
<div> | ||
<h1>LOGIN</h1> | ||
<form onSubmit={login}> | ||
<input type={"text"} id={"username"} placeholder={"enter your username"} required={true} onChange={onChangeHandlerUsername}/> | ||
<input type={"password"} id={"password"} placeholder={"*****************"} required={true} onChange={onChnageHandlerPassword}/> | ||
<button >Login</button> | ||
</form> | ||
<button><Link to={"/register"}>New here?</Link></button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {ChangeEvent, FormEvent, useState} from "react"; | ||
import {Link, useNavigate} from "react-router-dom"; | ||
import axios from "axios"; | ||
|
||
|
||
export default function RegisterPage() { | ||
|
||
const [username, setUsername] = useState("") | ||
const [password, setPassword] = useState("") | ||
|
||
const nav = useNavigate(); | ||
|
||
function onChangeHandlerUsername(event:ChangeEvent<HTMLInputElement>){ | ||
setUsername(event.target.value) | ||
} | ||
|
||
function onChnageHandlerPassword(event:ChangeEvent<HTMLInputElement>){ | ||
setPassword(event.target.value) | ||
} | ||
|
||
function registrieren(event:FormEvent<HTMLFormElement>){ | ||
event.preventDefault(); | ||
axios.post("/api/user/register", {username, password}) | ||
.then(() => nav("/home")) | ||
.catch((error) => console.log(error)); | ||
|
||
} | ||
|
||
return( | ||
<div> | ||
<h1>Registrieren</h1> | ||
<form onSubmit={registrieren}> | ||
<input type={"text"} id={"username"} placeholder={"enter your username"} required={true} onChange={onChangeHandlerUsername}/> | ||
<input type={"password"} id={"password"} placeholder={"*****************"} required={true} onChange={onChnageHandlerPassword}/> | ||
<button>Jetzt registrieren</button> | ||
</form> | ||
<button><Link to={"/"}>I have an login</Link></button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters