layout; routing; login
This commit is contained in:
10
.vscode/launch.json
vendored
10
.vscode/launch.json
vendored
@ -4,11 +4,19 @@
|
|||||||
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
|
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "chrome",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Chrome mit \"localhost:3000/dog\" starten",
|
||||||
|
"url": "http://localhost:3000/dog",
|
||||||
|
"webRoot": "${workspaceFolder}"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "chrome",
|
"type": "chrome",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Chrome mit \"localhost/dog\" starten",
|
"name": "Chrome mit \"localhost/dog\" starten",
|
||||||
"url": "http://localhost:3000/dog",
|
"url": "http://localhost/dog",
|
||||||
"webRoot": "${workspaceFolder}"
|
"webRoot": "${workspaceFolder}"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
//require __DIR__ . '/classes/JwtHandler.php';
|
//require __DIR__ . '/classes/JwtHandler.php';
|
||||||
|
require __DIR__ . '/classes/lib.php';
|
||||||
|
|
||||||
//class Auth extends JwtHandler
|
//class Auth extends JwtHandler
|
||||||
class Auth
|
class Auth
|
||||||
@ -53,26 +54,17 @@ class Auth
|
|||||||
isset($data['data']->id) &&
|
isset($data['data']->id) &&
|
||||||
$user = $this->fetchUser($data['data']->id)
|
$user = $this->fetchUser($data['data']->id)
|
||||||
) :
|
) :
|
||||||
return [
|
$retVal = new CMsg(1, 200, "User found", null, $user);
|
||||||
"success" => 1,
|
return $retVal->jsonarray();
|
||||||
"message" => "User found",
|
|
||||||
"user" => $user
|
|
||||||
];
|
|
||||||
else :
|
else :
|
||||||
return [
|
$retVal = new CMsg(0, 422, $data['message'], null, null);
|
||||||
"success" => 0,
|
return $retVal->jsonarray();
|
||||||
"message" => $data['message'],
|
|
||||||
"user" => null
|
|
||||||
];
|
|
||||||
endif;
|
endif;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return [
|
$retVal = new CMsg(0, 422, "User not found in request", null, null);
|
||||||
"success" => 0,
|
return $retVal->jsonarray();
|
||||||
"message" => "User not found in request",
|
|
||||||
"user" => null
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,10 +78,9 @@ class Auth
|
|||||||
|
|
||||||
if ($query_stmt->rowCount()) :
|
if ($query_stmt->rowCount()) :
|
||||||
$returnVal = $query_stmt->fetch(PDO::FETCH_ASSOC);
|
$returnVal = $query_stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
$returnVal->session = $_SESSION;
|
|
||||||
return $returnVal;
|
return $returnVal;
|
||||||
else :
|
else :
|
||||||
return false;
|
return null;
|
||||||
endif;
|
endif;
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -15,5 +15,5 @@ $db_connection = new Database();
|
|||||||
$conn = $db_connection->dbConnection();
|
$conn = $db_connection->dbConnection();
|
||||||
$auth = new Auth($conn, $allHeaders);
|
$auth = new Auth($conn, $allHeaders);
|
||||||
|
|
||||||
echo json_encode($auth->isValid());
|
echo $auth->isValid();
|
||||||
?>
|
?>
|
||||||
@ -4,3 +4,11 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.neben
|
||||||
|
{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,9 +18,10 @@ function App()
|
|||||||
<div className="col middle">
|
<div className="col middle">
|
||||||
<BrowserRouter basename='/dog'>
|
<BrowserRouter basename='/dog'>
|
||||||
<Routes>
|
<Routes>
|
||||||
|
{user && <Route path="/" element={<Home/>} />}
|
||||||
|
{!user && <Route path="/" element={<Login/>} />}
|
||||||
<Route path="/:qr_id" element={<Dog/>} />
|
<Route path="/:qr_id" element={<Dog/>} />
|
||||||
<Route path="/" element={<Home/>} />
|
{user && <Route path="/d" element={<Dog/>} />}
|
||||||
<Route path="/d" element={<Dog/>} />
|
|
||||||
<Route path="/login" element={<Login/>} />
|
<Route path="/login" element={<Login/>} />
|
||||||
<Route path="/reg" element={<Register/>} />
|
<Route path="/reg" element={<Register/>} />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|||||||
@ -5,10 +5,7 @@
|
|||||||
margin: 5px;
|
margin: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.neben
|
button
|
||||||
{
|
{
|
||||||
display: flex;
|
max-width: 30%;
|
||||||
flex-direction: row;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
}
|
||||||
@ -1,9 +1,13 @@
|
|||||||
import React from 'react'
|
import React, { useContext } from 'react'
|
||||||
|
import { UserCtx, UserCtxT } from '../context/UserContext';
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
|
const {loginUser, wait, getUser, user} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1>Home</h1>
|
<h1>Home</h1>
|
||||||
|
<div>Logged in als:</div>
|
||||||
|
<div>{user?.email}</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
8
src/components/Login.css
Normal file
8
src/components/Login.css
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
.Login
|
||||||
|
form
|
||||||
|
{
|
||||||
|
width: 65%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
}
|
||||||
@ -1,8 +1,10 @@
|
|||||||
import {useState,useContext} from 'react';
|
import {useState,useContext} from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import {UserCtx, UserCtxT} from '../context/UserContext';
|
import {UserCtx, UserCtxT} from '../context/UserContext';
|
||||||
|
import './Login.css'
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
const {loginUser, wait, getUser} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
const {loginUser, wait, getUser, user} = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||||
const [redirect, setRedirect] = useState("false");
|
const [redirect, setRedirect] = useState("false");
|
||||||
const [errMsg, setErrMsg] = useState("false");
|
const [errMsg, setErrMsg] = useState("false");
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
@ -31,27 +33,40 @@ const Login = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = await loginUser(formData);
|
const data = await loginUser(formData);
|
||||||
if(data.success){
|
if(data.success)
|
||||||
|
{
|
||||||
setRedirect('Redirecting...');
|
setRedirect('Redirecting...');
|
||||||
|
setErrMsg(data.message);
|
||||||
await getUser();
|
await getUser();
|
||||||
//e.currentTarget.reset();
|
e.currentTarget.reset();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setErrMsg(data.message);
|
setErrMsg(data.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className='Login'>
|
||||||
<h2>Login</h2>
|
<h2>Login</h2>
|
||||||
<form onSubmit={submitForm}>
|
{ user &&
|
||||||
<label htmlFor="email">Email:</label>
|
<>
|
||||||
<input type="email" name="email" onChange={onChangeInput} placeholder="Your email" id="email" value={formData.email} required />
|
<div>Logged in als:</div>
|
||||||
<label htmlFor="password">Password:</label>
|
<div>{user?.email}</div>
|
||||||
<input type="password" name="password" onChange={onChangeInput} placeholder="New password" id="password" value={formData.password} required />
|
<div className="bottom-link"><Link to="/">Home</Link></div>
|
||||||
|
</> }
|
||||||
|
|
||||||
|
{!user &&<form onSubmit={submitForm}>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="email">Email:</label>
|
||||||
|
<input type="email" name="email" onChange={onChangeInput} placeholder="Your email" id="email" value={formData.email} required />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label htmlFor="password">Password:</label>
|
||||||
|
<input type="password" name="password" onChange={onChangeInput} placeholder="New password" id="password" value={formData.password} required />
|
||||||
|
</div>
|
||||||
{errMsg !== "false" && <div className="err-msg">{errMsg}</div>}
|
{errMsg !== "false" && <div className="err-msg">{errMsg}</div>}
|
||||||
{redirect !== "false" ? redirect : <button type="submit" disabled={wait}>Login</button>}
|
{redirect !== "false" ? redirect : <button type="submit" disabled={wait}>Login</button>}
|
||||||
<div className="bottom-link"><Link to="/reg">Register</Link></div>
|
<div className="bottom-link"><Link to="/reg">Register</Link></div>
|
||||||
</form>
|
</form> }
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
8
src/components/Register.css
Normal file
8
src/components/Register.css
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
.Register
|
||||||
|
form
|
||||||
|
{
|
||||||
|
width: 65%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import {useContext, useState} from 'react'
|
import {useContext, useState} from 'react'
|
||||||
import {Link} from 'react-router-dom'
|
import {Link} from 'react-router-dom'
|
||||||
import {UserCtx, UserCtxT} from '../context/UserContext';
|
import {UserCtx, UserCtxT} from '../context/UserContext';
|
||||||
|
import './Register.css';
|
||||||
|
|
||||||
|
|
||||||
const Register = () => {
|
const Register = () => {
|
||||||
@ -9,7 +10,8 @@ const Register = () => {
|
|||||||
const [successMsg, setSuccessMsg] = useState("false");
|
const [successMsg, setSuccessMsg] = useState("false");
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
email:'',
|
email:'',
|
||||||
password:''
|
password:'',
|
||||||
|
password2:''
|
||||||
});
|
});
|
||||||
|
|
||||||
const onChangeInput = (e: React.FormEvent<HTMLInputElement> ) => {
|
const onChangeInput = (e: React.FormEvent<HTMLInputElement> ) => {
|
||||||
@ -29,6 +31,14 @@ const Register = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(formData.password !== formData.password2)
|
||||||
|
{
|
||||||
|
setSuccessMsg("false");
|
||||||
|
setErrMsg('Bitte 2mal das gleiche Passwort eingeben!');
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const data = await registerUser(formData);
|
const data = await registerUser(formData);
|
||||||
if(data.success){
|
if(data.success){
|
||||||
setSuccessMsg('Erfolgreich Registriert!');
|
setSuccessMsg('Erfolgreich Registriert!');
|
||||||
@ -42,13 +52,21 @@ const Register = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className='Register'>
|
||||||
<h2>Sign Up</h2>
|
<h2>Register</h2>
|
||||||
<form onSubmit={submitForm}>
|
<form onSubmit={submitForm}>
|
||||||
<label htmlFor="email">Email:</label>
|
<div className='neben'>
|
||||||
<input type="email" name="email" onChange={onChangeInput} placeholder="Deine email" id="email" value={formData.email} required />
|
<label htmlFor="email">Email: </label>
|
||||||
<label htmlFor="password">Password:</label>
|
<input type="email" name="email" onChange={onChangeInput} placeholder="Deine email" id="email" value={formData.email} required />
|
||||||
<input type="password" name="password" onChange={onChangeInput} placeholder="New password" id="password" value={formData.password} required />
|
</div>
|
||||||
|
<div className='neben'>
|
||||||
|
<label htmlFor="password">Passwort: </label>
|
||||||
|
<input type="password" name="password" onChange={onChangeInput} placeholder="New password" id="password" value={formData.password} required />
|
||||||
|
</div>
|
||||||
|
<div className='neben'>
|
||||||
|
<label htmlFor="password2">Passwort wiederholen: </label>
|
||||||
|
<input type="password" name="password2" onChange={onChangeInput} placeholder="New password" id="password2" value={formData.password2} required />
|
||||||
|
</div>
|
||||||
{successMsg !== "false" && <div className="success-msg">{successMsg}</div>}
|
{successMsg !== "false" && <div className="success-msg">{successMsg}</div>}
|
||||||
{errMsg !== "false" && <div className="err-msg">{errMsg}</div>}
|
{errMsg !== "false" && <div className="err-msg">{errMsg}</div>}
|
||||||
<button type="submit" disabled={wait}>Register</button>
|
<button type="submit" disabled={wait}>Register</button>
|
||||||
|
|||||||
11
src/components/logout.php
Normal file
11
src/components/logout.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
header("Access-Control-Allow-Origin: *");
|
||||||
|
header("Access-Control-Allow-Headers: access");
|
||||||
|
header("Access-Control-Allow-Methods: POST");
|
||||||
|
header("Content-Type: application/json; charset=UTF-8");
|
||||||
|
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
session_destroy();
|
||||||
|
session_abort();
|
||||||
|
?>
|
||||||
@ -74,8 +74,8 @@ export type UserCtxT =
|
|||||||
export const UserCtx = createContext<UserCtxT | null>(null);
|
export const UserCtx = createContext<UserCtxT | null>(null);
|
||||||
|
|
||||||
export const Axios = axios.create({
|
export const Axios = axios.create({
|
||||||
// baseURL: 'http://localhost/dog/php-dog/',
|
baseURL: 'http://localhost/dog/php-dog/',
|
||||||
baseURL: 'https://hope-fly.de/dog/php-dog/',
|
// baseURL: 'https://hope-fly.de/dog/php-dog/',
|
||||||
});
|
});
|
||||||
|
|
||||||
export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
|
export const UserCtxProvider = ({children}:TUserContextProviderProps) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user