|
|
|
@ -4,7 +4,7 @@ import prisma from '../lib/prisma'
|
|
|
|
import Image from 'next/image';
|
|
|
|
import Image from 'next/image';
|
|
|
|
import * as Yup from 'yup';
|
|
|
|
import * as Yup from 'yup';
|
|
|
|
import Head from "next/head";
|
|
|
|
import Head from "next/head";
|
|
|
|
import { signIn, useSession } from "next-auth/react";
|
|
|
|
import { getCsrfToken, signIn, useSession } from "next-auth/react";
|
|
|
|
import { yupResolver } from "@hookform/resolvers/yup";
|
|
|
|
import { yupResolver } from "@hookform/resolvers/yup";
|
|
|
|
import { useForm } from "react-hook-form";
|
|
|
|
import { useForm } from "react-hook-form";
|
|
|
|
|
|
|
|
|
|
|
|
@ -21,31 +21,43 @@ import imageConnexion from '../public/images/connexion_image.png'
|
|
|
|
import Link from "next/link";
|
|
|
|
import Link from "next/link";
|
|
|
|
|
|
|
|
|
|
|
|
import { SiGnuprivacyguard } from 'react-icons/si'
|
|
|
|
import { SiGnuprivacyguard } from 'react-icons/si'
|
|
|
|
|
|
|
|
import { toast } from "react-toastify";
|
|
|
|
|
|
|
|
import { Token } from "nodemailer/lib/xoauth2";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function getServerSideProps(context) {
|
|
|
|
|
|
|
|
const csrfToken = await getCsrfToken(context)
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
props: { csrfToken },
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type LoginSubmitForm = {
|
|
|
|
type LoginSubmitForm = {
|
|
|
|
email: string,
|
|
|
|
email: string,
|
|
|
|
acceptTerms: boolean
|
|
|
|
acceptTerms: boolean
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
csrfToken: Token
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const MainPage = () => {
|
|
|
|
const MainPage = ({ csrfToken }: Props) => {
|
|
|
|
const { data: session } = useSession();
|
|
|
|
const { data: session } = useSession();
|
|
|
|
|
|
|
|
|
|
|
|
const validationSchema = Yup.object().shape({
|
|
|
|
const validationSchema = Yup.object().shape({
|
|
|
|
email: Yup.string().email(),
|
|
|
|
email: Yup.string().email(
|
|
|
|
|
|
|
|
"Veuillez rentrer une adresse mail valide"
|
|
|
|
|
|
|
|
),
|
|
|
|
acceptTerms: Yup.bool().oneOf(
|
|
|
|
acceptTerms: Yup.bool().oneOf(
|
|
|
|
[true],
|
|
|
|
[true],
|
|
|
|
"Accepter les conditions est obligatoire"
|
|
|
|
"Vous devez accepter les conditions obligatoire"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
register,
|
|
|
|
register,
|
|
|
|
|
|
|
|
clearErrors,
|
|
|
|
handleSubmit,
|
|
|
|
handleSubmit,
|
|
|
|
watch,
|
|
|
|
watch,
|
|
|
|
trigger,
|
|
|
|
trigger,
|
|
|
|
@ -56,36 +68,68 @@ const MainPage = () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const term = watch("acceptTerms")
|
|
|
|
const term = watch("acceptTerms")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const connexionWithGoogle = async () => {
|
|
|
|
const connexionWithGoogle = async () => {
|
|
|
|
|
|
|
|
clearErrors("acceptTerms")
|
|
|
|
if (term) {
|
|
|
|
if (term) {
|
|
|
|
signIn("google");
|
|
|
|
signIn("google");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
toast.error('Vous devez accepter les conditions obligatoire', {
|
|
|
|
|
|
|
|
position: "top-center",
|
|
|
|
|
|
|
|
autoClose: 5000,
|
|
|
|
|
|
|
|
hideProgressBar: false,
|
|
|
|
|
|
|
|
closeOnClick: true,
|
|
|
|
|
|
|
|
pauseOnHover: true,
|
|
|
|
|
|
|
|
draggable: true,
|
|
|
|
|
|
|
|
progress: undefined,
|
|
|
|
|
|
|
|
theme: "light",
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
//relance une vérification de la checkbox
|
|
|
|
|
|
|
|
// await trigger("acceptTerms");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//relance une vérification de la checkbox
|
|
|
|
|
|
|
|
await trigger("acceptTerms");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const onSubmit = async (data: LoginSubmitForm) => {
|
|
|
|
const onSubmit = async (data: LoginSubmitForm) => {
|
|
|
|
|
|
|
|
if (term && !errors.email?.message) {
|
|
|
|
|
|
|
|
console.log("email", data.email);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
signIn("email", { email: data.email, callbackUrl: `${window.location.origin}/create` })
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
toast.error('Vous devez accepter les conditions obligatoire', {
|
|
|
|
|
|
|
|
position: "top-center",
|
|
|
|
|
|
|
|
autoClose: 5000,
|
|
|
|
|
|
|
|
hideProgressBar: false,
|
|
|
|
|
|
|
|
closeOnClick: true,
|
|
|
|
|
|
|
|
pauseOnHover: true,
|
|
|
|
|
|
|
|
draggable: true,
|
|
|
|
|
|
|
|
progress: undefined,
|
|
|
|
|
|
|
|
theme: "light",
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// const body = { bioValue: data.bio };
|
|
|
|
|
|
|
|
// await fetch(`/api/profile`, {
|
|
|
|
|
|
|
|
// method: "POST",
|
|
|
|
|
|
|
|
// headers: { "Content-Type": "application/json" },
|
|
|
|
|
|
|
|
// body: JSON.stringify(body),
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// .then((res) => res.json())
|
|
|
|
|
|
|
|
// .then((data) => {
|
|
|
|
|
|
|
|
// setResponse(data);
|
|
|
|
|
|
|
|
// console.log('response', data);
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// await Router.push("/profile");
|
|
|
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
|
|
|
// console.error(error);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// const body = { bioValue: data.bio };
|
|
|
|
|
|
|
|
// await fetch(`/api/profile`, {
|
|
|
|
|
|
|
|
// method: "POST",
|
|
|
|
|
|
|
|
// headers: { "Content-Type": "application/json" },
|
|
|
|
|
|
|
|
// body: JSON.stringify(body),
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// .then((res) => res.json())
|
|
|
|
|
|
|
|
// .then((data) => {
|
|
|
|
|
|
|
|
// setResponse(data);
|
|
|
|
|
|
|
|
// console.log('response', data);
|
|
|
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
// await Router.push("/profile");
|
|
|
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
|
|
|
// console.error(error);
|
|
|
|
|
|
|
|
// }
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<Head>
|
|
|
|
<Head>
|
|
|
|
@ -93,70 +137,48 @@ const MainPage = () => {
|
|
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
|
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
|
|
|
</Head>
|
|
|
|
</Head>
|
|
|
|
|
|
|
|
|
|
|
|
<div className={`${style['bloc-content']} col-12 col-lg-6`}>
|
|
|
|
<div className={`${style['bloc-content']} col-12 col-lg-6`}>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<h1 className="fw-light">Connexion</h1>
|
|
|
|
<h1 className="fw-light">Connexion</h1>
|
|
|
|
<SiGnuprivacyguard size={50} />
|
|
|
|
<SiGnuprivacyguard size={50} />
|
|
|
|
|
|
|
|
|
|
|
|
<form onSubmit={handleSubmit(onSubmit)}>
|
|
|
|
<form onSubmit={handleSubmit(onSubmit)}>
|
|
|
|
<div className="form-group mx-auto my-3 w-100">
|
|
|
|
<div className="form-group mx-auto my-3 w-100">
|
|
|
|
|
|
|
|
<input
|
|
|
|
<div className="mb-3">
|
|
|
|
type="email" id="email" name="email"
|
|
|
|
|
|
|
|
className={`mb-3 form-control ${errors.email ? 'is-invalid' : ''}`}
|
|
|
|
<input
|
|
|
|
placeholder="Email..."
|
|
|
|
type="email"
|
|
|
|
{...register("email")}
|
|
|
|
className={`form-control ${errors.email ? 'is-invalid' : ''}`}
|
|
|
|
/>
|
|
|
|
placeholder="Email..."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{...register("email")}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="d-grid">
|
|
|
|
<div className="d-grid">
|
|
|
|
<button type="submit" className="btn btn-primary">
|
|
|
|
<button type="submit" className="btn d-grid btn-primary">
|
|
|
|
Se connecter avec mon email
|
|
|
|
Se connecter avec mon email
|
|
|
|
</button>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="invalid-feedback alert alert-danger">{errors.email?.message}</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
<div className="d-grid">
|
|
|
|
<hr />
|
|
|
|
<button onClick={connexionWithGoogle} type="button" className={`btn btn-primary ${style.loginButton}`} style={{ backgroundColor: "#dd4b39" }}>
|
|
|
|
|
|
|
|
<span className={style.logo}><AiOutlineGoogle /></span>Se connecter avec google
|
|
|
|
<div className="d-grid">
|
|
|
|
</button>
|
|
|
|
<button onClick={connexionWithGoogle} type="button" className={`btn btn-primary ${style.loginButton}`} style={{ backgroundColor: "#dd4b39" }}>
|
|
|
|
</div>
|
|
|
|
<span className={style.logo}><AiOutlineGoogle /></span>Se connecter avec google
|
|
|
|
<div className="form-group">
|
|
|
|
</button>
|
|
|
|
<label
|
|
|
|
</div>
|
|
|
|
htmlFor="acceptTerms"
|
|
|
|
|
|
|
|
className="form-check-label"
|
|
|
|
<div className="form-check">
|
|
|
|
>
|
|
|
|
<label
|
|
|
|
J'ai lu et j'accepte les
|
|
|
|
htmlFor="acceptTerms"
|
|
|
|
conditions
|
|
|
|
className="form-check-label"
|
|
|
|
</label>
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
J'ai lu et j'accepte les
|
|
|
|
type="checkbox"
|
|
|
|
conditions
|
|
|
|
className={`form-check-input ${errors.acceptTerms ? 'is-invalid' : ''}`}
|
|
|
|
</label>
|
|
|
|
{...register("acceptTerms")}
|
|
|
|
<input
|
|
|
|
name="acceptTerms"
|
|
|
|
type="checkbox"
|
|
|
|
/>
|
|
|
|
className="form-check-input"
|
|
|
|
{/* <div className="invalid-feedback alert alert-danger">{errors.acceptTerms?.message}</div> */}
|
|
|
|
{...register("acceptTerms")}
|
|
|
|
|
|
|
|
name="acceptTerms"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</form>
|
|
|
|
</form>
|
|
|
|
<div className="invalid-feedback alert alert-danger">{errors.acceptTerms?.message}</div>
|
|
|
|
</div >
|
|
|
|
<div className="invalid-feedback alert alert-danger">{errors.email?.message}</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</>)
|
|
|
|
</>)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|