clean css

This commit is contained in:
Romulus21
2023-09-11 08:24:22 +02:00
parent 2dab3b48e1
commit 89c179c7e7
17 changed files with 246 additions and 94 deletions

View File

@@ -62,7 +62,7 @@ class AuthController extends Controller
$token = Str::random(12); $token = Str::random(12);
DB::table('password_resets')->insert([ DB::table('password_reset_tokens')->insert([
'email' => $user->email, 'email' => $user->email,
'token' => $token, 'token' => $token,
'created_at' => now(), 'created_at' => now(),
@@ -96,7 +96,7 @@ class AuthController extends Controller
{ {
$data = $request->validate([ $data = $request->validate([
'email' => 'exists:users,email', 'email' => 'exists:users,email',
'token' => 'exists:password_resets,token', 'token' => 'exists:password_reset_tokens,token',
'password' => ['required', 'regex:/^(?=.*?[A-Z])(?=.*[a-z])(?=.*[0-9]).{8,}$/'], 'password' => ['required', 'regex:/^(?=.*?[A-Z])(?=.*[a-z])(?=.*[0-9]).{8,}$/'],
'confirm_password' => 'same:password', 'confirm_password' => 'same:password',
], [ ], [
@@ -104,7 +104,7 @@ class AuthController extends Controller
'confirm_password.same' => __('validation.password_confirm'), 'confirm_password.same' => __('validation.password_confirm'),
]); ]);
$token = DB::table('password_resets') $token = DB::table('password_reset_tokens')
->whereEmail($data['email']) ->whereEmail($data['email'])
->whereToken($data['token']) ->whereToken($data['token'])
->orderBy('created_at', 'desc') ->orderBy('created_at', 'desc')

View File

@@ -40,7 +40,7 @@ class Reset extends Mailable
return new Content( return new Content(
markdown: 'mail.reset', markdown: 'mail.reset',
with: [ with: [
'link' => config('app.url').'/reset/'.$this->token, 'link' => config('app.url').'/changer-le-mot-de-passe/'.$this->token,
], ],
); );
} }

View File

@@ -0,0 +1,15 @@
import React, {FC} from "react";
import {PropsWithChildren} from "react";
const Card: FC<PropsWithChildren<CardProps>> = ({children, className = ''}) => {
return <div className={`${className} border m-1 rounded py-1 px-2`}>
{children}
</div>
}
export default Card
interface CardProps {
className?: string
}

View File

@@ -11,16 +11,19 @@ const Header = () => {
<Link to="/">Bermite</Link> <Link to="/">Bermite</Link>
</div> </div>
{authUser && <nav className="flex gap-2"> {/*{authUser && <nav className="flex gap-2">*/}
<Link to="/pluviometrie">Pluviométrie</Link> {/* <Link to="/pluviometrie">Pluviométrie</Link>*/}
<Link to="/meteo">Météo</Link> {/* <Link to="/meteo">Météo</Link>*/}
</nav>} {/*</nav>}*/}
{authUser ? <span className="flex gap-2"><Link to="/profile">{authUser.name}</Link><button onClick={logout}>logout</button></span> {authUser
? <span className="flex gap-2">
<Link to="/profile">{authUser.name}</Link>
</span>
: <span className="flex gap-2"> : <span className="flex gap-2">
<Link to="/connexion">Connexion</Link> <Link to="/connexion">Connexion</Link>
<Link to="/sinscrire">S'inscrire</Link> {/*<Link to="/sinscrire">S'inscrire</Link>*/}
</span>} </span>}
</header> </header>
} }

View File

@@ -1,6 +1,7 @@
import React, {Dispatch, FC, FormEvent, SetStateAction, useState} from "react" import React, {Dispatch, FC, FormEvent, SetStateAction, useState} from "react"
import useAxiosTools from "../../hooks/AxiosTools"; import useAxiosTools from "../../hooks/AxiosTools";
import Field from "../Field"; import Field from "../Field";
import Card from "../Card";
const AddRainfall: FC<AddRainfallProps> = ({reload}) => { const AddRainfall: FC<AddRainfallProps> = ({reload}) => {
@@ -20,22 +21,26 @@ const AddRainfall: FC<AddRainfallProps> = ({reload}) => {
} }
} }
return <form onSubmit={handleSubmit}> return <Card className="min-w-[200px] overflow-hidden self-start w-full lg:w-auto">
<h2>Ajout d'une mesure</h2> <h2 className="text-center bg-blue-500 -mx-2 -mt-1 text-lg font-bold px-2 py-1">
<Field type="date" Ajout d'une mesure
name="date" </h2>
placeholder="Email" <form onSubmit={handleSubmit} className="p-2 flex flex-col gap-2">
value={date} <Field type="date"
onChange={event => setDate(event.target.value)} name="date"
autoFocus>Date</Field> placeholder="Email"
<Field type="number" value={date}
name="value" onChange={event => setDate(event.target.value)}
placeholder="10" autoFocus>Date</Field>
value={value} <Field type="number"
onChange={event => setValue(Number(event.target.value))}>Mesure</Field> name="value"
placeholder="10"
value={value}
onChange={event => setValue(Number(event.target.value))}>Mesure</Field>
<button type="submit" className="mt-3 w-full bg-blue-700 rounded">Valider</button> <button type="submit" className="mt-2 px-2 py-1 w-full text-lg font-bold bg-blue-700 rounded">Valider</button>
</form> </form>
</Card>
} }
export default AddRainfall export default AddRainfall

View File

@@ -2,6 +2,7 @@ import React, {FC, useEffect, useState} from "react"
import useAxiosTools from "../../hooks/AxiosTools"; import useAxiosTools from "../../hooks/AxiosTools";
import {rainfall} from "../../types"; import {rainfall} from "../../types";
import {AxiosError} from "axios"; import {AxiosError} from "axios";
import Card from "../Card";
const LastFiveMesure: FC<LastFiveMesureProps> = ({loadedAt}) => { const LastFiveMesure: FC<LastFiveMesureProps> = ({loadedAt}) => {
@@ -25,16 +26,18 @@ const LastFiveMesure: FC<LastFiveMesureProps> = ({loadedAt}) => {
} }
} }
return <div> return <Card className="min-w-[200px] overflow-hidden self-start w-full lg:w-auto">
<h1>5 dernières mesures</h1> <h1 className="text-center bg-blue-500 -mx-2 -mt-1 text-lg font-bold px-2 py-1">5 dernières mesures</h1>
{error && <div>{error}</div>} {error && <div>{error}</div>}
<ul> <table className="w-full text-center">
{data.map(line => <li key={line.id} className="w-36 flex justify-between"> <tbody>
<span>{(new Date(line.date)).toLocaleDateString()}</span> {data.map(line => <tr key={line.id} className="">
<span>{line.value}</span> <td>{(new Date(line.date)).toLocaleDateString()}</td>
</li>)} <td className="text-right px-2">{line.value}</td>
</ul> </tr>)}
</div> </tbody>
</table>
</Card>
} }
export default LastFiveMesure export default LastFiveMesure

View File

@@ -4,7 +4,7 @@ import Router from "./Router";
const App = () => { const App = () => {
return <main className="dark:bg-gray-900 dark:text-white h-screen"> return <main className="dark:bg-gray-900 dark:text-white h-screen overflow-scroll">
<AuthUserProvider> <AuthUserProvider>
<Router /> <Router />
</AuthUserProvider> </AuthUserProvider>

View File

@@ -0,0 +1,40 @@
import React, {FormEvent, SyntheticEvent, useState} from "react"
import Field from "../../components/Field";
import axios from "axios";
import {useNavigate} from "react-router-dom";
import useAuthUser from "../../hooks/AuthUser";
const ForgotPassword = () => {
const [email, setEmail] = useState('')
const [message, setMessage] = useState(false)
const handleSubmit = async (event: FormEvent) => {
event.preventDefault()
try {
await axios.get('/sanctum/csrf-cookie')
const res = await axios.post('/api/forgot', {email})
setMessage(true)
} catch (e) {
console.error(e)
}
}
return <div>
<form onSubmit={handleSubmit} className="w-96 mx-auto mt-10 border shadow p-3">
<h1 className="text-center">Connexion</h1>
{message && <p className="bg-green-600">Un email vous a é envoyer pour modifier le mot de passe.</p>}
<Field type="email"
name="email"
placeholder="Email"
value={email}
onChange={event => setEmail(event.target.value)}
autoFocus>Email</Field>
<button type="submit" className="mt-5 bg-blue-700 w-full block text-white px-5 py-2 text-lg rounded">Valider</button>
</form>
</div>
}
export default ForgotPassword

View File

@@ -1,8 +1,9 @@
import React, {FormEvent, SyntheticEvent, useState} from "react" import React, {FormEvent, SyntheticEvent, useState} from "react"
import Field from "../../components/Field"; import Field from "../../components/Field";
import axios from "axios"; import axios from "axios";
import {useNavigate} from "react-router-dom"; import {Link, useNavigate} from "react-router-dom";
import useAuthUser from "../../hooks/AuthUser"; import useAuthUser from "../../hooks/AuthUser";
import Card from "../../components/Card";
const Login = () => { const Login = () => {
@@ -24,22 +25,27 @@ const Login = () => {
} }
return <div> return <div>
<form onSubmit={handleSubmit} className="w-96 mx-auto mt-10 border shadow p-3"> <Card className="w-96 mx-auto mt-10 p-2 overflow-hidden">
<h1 className="text-center">Connexion</h1> <form onSubmit={handleSubmit}>
<h1 className="text-center bg-blue-500 -mx-2 -mt-1 text-lg font-bold px-2 py-1 mb-2">
Connexion
</h1>
<Field type="email" <Field type="email"
name="email" name="email"
placeholder="Email" placeholder="Email"
value={email} value={email}
onChange={event => setEmail(event.target.value)} onChange={event => setEmail(event.target.value)}
autoFocus>Email</Field> autoFocus>Email</Field>
<Field type="password" <Field type="password"
name="password" name="password"
placeholder="******" placeholder="******"
value={password} value={password}
onChange={event => setPassword(event.target.value)}>Mot de passe</Field> onChange={event => setPassword(event.target.value)}>Mot de passe</Field>
<button type="submit" className="mt-5 bg-blue-700 w-full block text-white px-5 py-2 text-lg rounded">Valider</button> <button type="submit" className="mt-5 bg-blue-700 w-full block text-white px-5 py-2 text-lg rounded">Valider</button>
</form> <Link to="/mot-de-passe-oubliee" className="mt-2 inline-block">Mot de passe oublié ?</Link>
</form>
</Card>
</div> </div>
} }

View File

@@ -1,19 +1,24 @@
import React from "react"; import React from "react";
import useAuthUser from "../../hooks/AuthUser"; import useAuthUser from "../../hooks/AuthUser";
import PageLayout from "../../components/PageLayout";
const Profile = () => { const Profile = () => {
const {authUser} = useAuthUser() const {authUser, logout} = useAuthUser()
return <> return <PageLayout>
<h1>Profile</h1> <h1 className="text-lg font-bold mb-5">Profile</h1>
<div> <div>
<span>Nom: <strong>{authUser?.name}</strong></span> <div>Nom: <strong>{authUser?.name}</strong></div>
<div>Email: <strong>{authUser?.email}</strong></div>
</div> </div>
<div>Update name & email</div> <div>
<div>Change password</div> <button onClick={logout} className="mt-5 bg-blue-700 text-white px-5 py-2 text-lg rounded">Se déconnecter</button>
<div>Delete Account</div> </div>
</> {/*<div>Update name & email</div>*/}
{/*<div>Change password</div>*/}
{/*<div>Delete Account</div>*/}
</PageLayout>
} }
export default Profile export default Profile

View File

@@ -2,6 +2,7 @@ import React, {ChangeEvent, FormEvent, SyntheticEvent, useState} from "react"
import Field from "../../components/Field"; import Field from "../../components/Field";
import axios from "axios"; import axios from "axios";
import {useNavigate} from "react-router-dom"; import {useNavigate} from "react-router-dom";
import Card from "../../components/Card";
const Register = () => { const Register = () => {
@@ -23,28 +24,32 @@ const Register = () => {
} }
return <div> return <div>
<form onSubmit={handleSubmit} className="w-96 mx-auto mt-10 border shadow p-3"> <Card className="w-96 mx-auto mt-10 p-2 overflow-hidden">
<h1 className="text-center">S'inscrire</h1> <form onSubmit={handleSubmit}>
<h1 className="text-center bg-blue-500 -mx-2 -mt-1 text-lg font-bold px-2 py-1 mb-2">
S'inscrire
</h1>
<Field placeholder="Nom" <Field placeholder="Nom"
name="name" name="name"
value={name} value={name}
onChange={event => setName(event.target.value)} onChange={event => setName(event.target.value)}
autoFocus>Nom</Field> autoFocus>Nom</Field>
<Field type="email" <Field type="email"
name="email" name="email"
placeholder="Email" placeholder="Email"
value={email} value={email}
onChange={event => setEmail(event.target.value)} onChange={event => setEmail(event.target.value)}
autoFocus>Email</Field> autoFocus>Email</Field>
<Field type="password" <Field type="password"
name="password" name="password"
placeholder="******" placeholder="******"
value={password} value={password}
onChange={event => setPassword(event.target.value)} onChange={event => setPassword(event.target.value)}
autoFocus>Mot de passe</Field> autoFocus>Mot de passe</Field>
<button type="submit" className="mt-5 bg-blue-700 w-full block text-white px-5 py-2 text-lg rounded">Valider</button> <button type="submit" className="mt-5 bg-blue-700 w-full block text-white px-5 py-2 text-lg rounded">Valider</button>
</form> </form>
</Card>
</div> </div>
} }

View File

@@ -0,0 +1,54 @@
import PageLayout from "../../components/PageLayout";
import Field from "../../components/Field";
import React, {FormEvent, useState} from "react";
import {useNavigate, useParams} from "react-router-dom";
import useAuthUser from "../../hooks/AuthUser";
import axios from "axios";
const Reset = () => {
let {token} = useParams()
const navigate = useNavigate()
const {setAuthUser} = useAuthUser()
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [samePassword, setSamePassword] = useState('')
const handleSubmit = async (event: FormEvent) => {
event.preventDefault()
try {
await axios.get('/sanctum/csrf-cookie')
const res = await axios.post('/api/reset', {email, token, password, samePassword})
setAuthUser(res.data.user)
navigate('/connexion')
} catch (e) {
console.error(e)
}
}
return <div>
<form onSubmit={handleSubmit} className="w-96 mx-auto mt-10 border shadow p-3">
<h1 className="text-center">Connexion</h1>
<Field type="email"
name="email"
placeholder="Email"
value={email}
onChange={event => setEmail(event.target.value)}
autoFocus>Email</Field>
<Field type="password"
name="password"
placeholder="******"
value={password}
onChange={event => setPassword(event.target.value)}>Mot de passe</Field>
<Field type="password"
name="same_password"
placeholder="******"
value={samePassword}
onChange={event => setSamePassword(event.target.value)}>Confirmation du mot de passe</Field>
<button type="submit" className="mt-5 bg-blue-700 w-full block text-white px-5 py-2 text-lg rounded">Valider</button>
</form>
</div>
}
export default Reset

View File

@@ -1,10 +1,20 @@
import React from "react" import React from "react"
import {Link} from "react-router-dom"; import {Link} from "react-router-dom";
import useAuthUser from "../hooks/AuthUser";
import Rainfall from "./Rainfall";
const Home = () => { const Home = () => {
return <div>Home <Link to="/connexion">Connexion</Link> const {authUser} = useAuthUser()
<Link to="/sinscrire">S'inscrire</Link>
return <div>
{authUser
? <Rainfall />
: <div className="pt-10 px-5">
<h1 className="text-lg font-bold">Application pour enregistrer sa pluviométrie</h1>
<p className="mt-5">Un compte est nécessaire mais les inscriptions ne sont pas ouvertes.</p>
</div>
}
</div> </div>
} }

View File

@@ -38,12 +38,12 @@ const Rainfall = () => {
} }
return <PageLayout> return <PageLayout>
<div className="flex justify-between"> <div className="flex flex-wrap gap-2 justify-between">
<LastFiveMesure loadedAt={loadedAt} /> <LastFiveMesure loadedAt={loadedAt} />
<AddRainfall reload={reload} /> <AddRainfall reload={reload} />
</div> </div>
<form className="flex"> <form className="flex mb-2 mx-5 flex gap-2">
<Field name="start_date" <Field name="start_date"
type="date" type="date"
value={graphDetails.start_date} value={graphDetails.start_date}

View File

@@ -8,6 +8,8 @@ import Profile from "./Auth/Profile";
import Header from "../components/Header"; import Header from "../components/Header";
import Rainfall from "./Rainfall"; import Rainfall from "./Rainfall";
import Meteo from "./Meteo"; import Meteo from "./Meteo";
import Reset from "./Auth/Reset";
import ForgotPassword from "./Auth/ForgotPassword";
const Router = () => { const Router = () => {
@@ -22,7 +24,9 @@ const Router = () => {
<Route path="/" element={<Home />} /> <Route path="/" element={<Home />} />
<Route path="/profile" element={<Profile />} /> <Route path="/profile" element={<Profile />} />
<Route path="/connexion" element={<Login />} /> <Route path="/connexion" element={<Login />} />
<Route path="/sinscrire" element={<Register />} /> {/*<Route path="/sinscrire" element={<Register />} />*/}
<Route path="/mot-de-passe-oubliee" element={<ForgotPassword />} />
<Route path="/changer-le-mot-de-passe/:token" element={<Reset />} />
<Route path="/meteo" element={<Meteo />} /> <Route path="/meteo" element={<Meteo />} />
<Route path="/pluviometrie" element={<Rainfall />} /> <Route path="/pluviometrie" element={<Rainfall />} />
</Routes> </Routes>

View File

@@ -1,12 +1,12 @@
<x-mail::message> <x-mail::message>
# Introduction # Créer un nouveau mot de passe
The body of your message. Veuillez cliquer sur le bouton de réinitilisation de votre de mot de passe.
<x-mail::button :url="''"> <x-mail::button :url="$link">
Button Text Réinitialisation de mot de passe
</x-mail::button> </x-mail::button>
Thanks,<br> Merci,<br>
{{ config('app.name') }} {{ config('app.name') }}
</x-mail::message> </x-mail::message>

View File

@@ -17,14 +17,16 @@ use Illuminate\Support\Facades\Route;
*/ */
Route::post('/login', [AuthController::class, 'login'])->name('login'); Route::post('/login', [AuthController::class, 'login'])->name('login');
Route::post('/forgot', [AuthController::class, 'forgot'])->name('forgot');
Route::post('/register', [AuthController::class, 'register'])->name('register'); Route::post('/register', [AuthController::class, 'register'])->name('register');
Route::post('/reset', [AuthController::class, 'reset'])->name('reset');
Route::middleware('auth:sanctum')->group(function () { Route::middleware('auth:sanctum')->group(function () {
Route::get('/user', [AuthController::class, 'user'])->name('user'); Route::get('/user', [AuthController::class, 'user'])->name('user');
Route::delete('/logout', [AuthController::class, 'logout'])->name('logout'); Route::delete('/logout', [AuthController::class, 'logout'])->name('logout');
Route::get('rainfalls/last', [RainfallController::class, 'lastRainfalls'])->name('rainfalls.last'); Route::get('/rainfalls/last', [RainfallController::class, 'lastRainfalls'])->name('rainfalls.last');
Route::get('rainfalls/graph', [RainfallController::class, 'graphValue'])->name('rainfalls.graph'); Route::get('/rainfalls/graph', [RainfallController::class, 'graphValue'])->name('rainfalls.graph');
Route::post('rainfalls', [RainfallController::class, 'store'])->name('rainfall.store'); Route::post('rainfalls', [RainfallController::class, 'store'])->name('rainfall.store');
// Route::resource('rainfalls', RainfallController::class); // Route::resource('rainfalls', RainfallController::class);