mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-07-10 15:38:06 +00:00
Merge branch 'dev' of https://github.com/LucasVbr/projet-web4 into dev
This commit is contained in:
@@ -4,7 +4,20 @@ import { PrismaClient } from '@prisma/client'
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export default async function readUser(req: NextApiRequest, res: NextApiResponse) {
|
||||
const users = await prisma.user.findMany()
|
||||
|
||||
const {email, password} = req.query
|
||||
|
||||
if(!email) {
|
||||
const users = await prisma.user.findMany()
|
||||
return res.status(200).send({message: "readUser", users});
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({where :{"email" : email}})
|
||||
|
||||
if (user?.password == password) {
|
||||
res.status(200).send({message: "User found", user});
|
||||
}
|
||||
|
||||
res.status(400).send({message: "Mot de passe incorrect"});
|
||||
|
||||
return res.status(200).send({message: "readUser", users});
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import Head from 'next/head';
|
||||
import Navbar from '@/components/Navbar';
|
||||
import {Box, Image} from '@chakra-ui/react';
|
||||
import HomeHero from '@/components/layout/Home/HomeHero';
|
||||
import HomePresentation from '@/components/layout/Home/HomePresentation';
|
||||
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
@@ -15,6 +17,7 @@ export default function Home() {
|
||||
|
||||
<Navbar/>
|
||||
<HomeHero/>
|
||||
<HomePresentation/>
|
||||
|
||||
<Box minH={'100vh'}>
|
||||
</Box>
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
Flex,
|
||||
FormControl,
|
||||
FormLabel,
|
||||
Heading,
|
||||
Image,
|
||||
Input,
|
||||
Spacer,
|
||||
} from "@chakra-ui/react";
|
||||
import { useRouter } from "next/router";
|
||||
import { useForm } from "react-hook-form";
|
||||
|
||||
export default function Login() {
|
||||
const {
|
||||
handleSubmit,
|
||||
register,
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const onLogin = async (values) => {
|
||||
try {
|
||||
const response = await fetch(`/api/user/?email=${values.email}&password=${values.password}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
});
|
||||
const data = await response.json();
|
||||
if (data.error) {
|
||||
alert(data.message);
|
||||
} else {
|
||||
console.log(data);
|
||||
alert("connexion réussie");
|
||||
// router.push("/");
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
const redirect_home = () => {
|
||||
router.push("/");
|
||||
};
|
||||
|
||||
const RightSide = () => (
|
||||
<Flex
|
||||
justify={"center"}
|
||||
direction={"column"}
|
||||
flexBasis={"100%"}
|
||||
align={"center"}
|
||||
>
|
||||
<Heading mb={"2.5rem"}>Connexion</Heading>
|
||||
<Box w={"25vw"}>
|
||||
<form onSubmit={handleSubmit(onLogin)}>
|
||||
<FormControl isInvalid={errors.name}>
|
||||
<Box mb={"1rem"}>
|
||||
<FormLabel>Adresse email</FormLabel>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
placeholder="Adresse@email.com"
|
||||
{...register("email", {
|
||||
required: "This is required",
|
||||
})}
|
||||
/>
|
||||
</Box>
|
||||
<Box mb={"1rem"}>
|
||||
<FormLabel>Mot de passe</FormLabel>
|
||||
<Input
|
||||
id="password"
|
||||
type="password"
|
||||
placeholder="Mot de passe"
|
||||
{...register("password", {
|
||||
required: "This is required",
|
||||
})}
|
||||
/>
|
||||
</Box>
|
||||
<Flex mt={"1rem"} w={"100%"}>
|
||||
<Button onClick={redirect_home}>Retour</Button>
|
||||
<Spacer />
|
||||
<Button colorScheme="purple" type="submit">
|
||||
Connexion
|
||||
</Button>
|
||||
</Flex>
|
||||
</FormControl>
|
||||
</form>
|
||||
</Box>
|
||||
</Flex>
|
||||
);
|
||||
|
||||
const LeftSide = () => (
|
||||
<Box flexBasis={"100%"}>
|
||||
<Image
|
||||
h={"100vh"}
|
||||
w={"100%"}
|
||||
src={"/couple_horizon.png"}
|
||||
alt="couple looking at horizon"
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Flex gap={10}>
|
||||
<LeftSide />
|
||||
<RightSide />
|
||||
</Flex>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import CardUser from "../components/CardUser";
|
||||
|
||||
export default function Test_card(){
|
||||
|
||||
const user = {
|
||||
name: "dujardin",
|
||||
surname: "jean",
|
||||
age:19,
|
||||
aPropos: "Je suis une personne fictive, pas tres fictive",
|
||||
images: [
|
||||
"401446.webp"
|
||||
],
|
||||
passions : [
|
||||
"Sport",
|
||||
"Piscine",
|
||||
"Formule1",
|
||||
]
|
||||
}
|
||||
|
||||
return(
|
||||
<CardUser user={user}/>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user