feature/page-admin
C 4 years ago
commit d480a3f8b2

@ -9,8 +9,13 @@ GITHUB_SECRET=YOUR_GITHUB_CLIENT_SECRET
GOOGLE_CLIENT_ID=5572607706-p6dftn0ss3m2qnvqbhk4khqte8lk7kt3.apps.googleusercontent.com GOOGLE_CLIENT_ID=5572607706-p6dftn0ss3m2qnvqbhk4khqte8lk7kt3.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=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 GOOGLE_CLIENT_SECRET=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
DATABASE_URL="postgres://postgres:postgrespwd@localhost:5432/thetiptop"
# Email (magic link) # Email (magic link)
EMAIL_SERVER=smtp://2bfdbee5372880:af828174d7f2ad@smtp.mailtrap.io:2525 EMAIL_SERVER_USER=2bfdbee5372880
EMAIL_SERVER_PASSWORD=af828174d7f2ad
EMAIL_SERVER_HOST=smtp.mailtrap.io
EMAIL_SERVER_PORT=2525
EMAIL_FROM=thetiptop@test.com EMAIL_FROM=thetiptop@test.com
DATABASE_URL="postgres://postgres:postgrespwd@127.0.0.1:5454/thetiptop" DATABASE_URL="postgres://postgres:postgrespwd@127.0.0.1:5454/thetiptop"

@ -7,8 +7,13 @@ type Props = {
children?: React.ReactNode; children?: React.ReactNode;
}; };
const layoutStyle = {
height: "100vh"
}
const Layout = ({ children }: Props) => const Layout = ({ children }: Props) =>
<div> <div style={layoutStyle}>
<NavBar /> <NavBar />
<Content children={children} /> <Content children={children} />
<Footer /> <Footer />

@ -6,6 +6,8 @@ import { signOut, useSession } from "next-auth/react";
import style from '../styles/NavBar.module.css'; import style from '../styles/NavBar.module.css';
import Image from 'next/image'; import Image from 'next/image';
import { FiArrowRight } from 'react-icons/fi';
const NavBar = () => { const NavBar = () => {
const navRef = useRef<HTMLInputElement>(); const navRef = useRef<HTMLInputElement>();
@ -33,12 +35,20 @@ const NavBar = () => {
width={250} width={250}
height={100} height={100}
/> />
</div> </div>
<div className={`justify-content-center text-center ${style['hidden-mobile']}`}> <div className={`justify-content-center text-center ${style['hidden-mobile']}`}>
<Link href="/" legacyBehavior><a className={style.link} >Accueil</a></Link> | <Link href="/" legacyBehavior><a className={style.link} >Accueil</a></Link> |
<Link href="/contact" legacyBehavior><a className={style.link} >Nos produits</a></Link> | <Link href="/contact" legacyBehavior><a className={style.link} >Nos produits</a></Link> |
<Link href="/" legacyBehavior><a className={style.link} >Contactez-nous</a></Link> | <Link href="/" legacyBehavior><a className={style.link} >Contactez-nous</a></Link> |
<Link href="/connexion" legacyBehavior><a className={style.link} >Connexion</a></Link> {!session && <Link href="/connexion" legacyBehavior><a className={style.link} >Connexion</a></Link>}
{session && <Link href="/connexion" legacyBehavior><a className={style.link} >Mon compte</a></Link>}
{session && <Link href="/" legacyBehavior><a onClick={() => signOut()} className={style.link} >Se déconnecter</a></Link>}
{session && <span className={`${style.connexion} badge rounded-pill bg-light text-dark`}><FiArrowRight />{session.user.email}</span>}
</div> </div>
@ -46,6 +56,9 @@ const NavBar = () => {
<span className={`${style.burgerButton}`} onClick={openNav}>&#9776;</span> <span className={`${style.burgerButton}`} onClick={openNav}>&#9776;</span>
</div> </div>
<div className="d-flex justify-content-center">
</div>
<div ref={navRef} className={style.overlay} onClick={closeNav}> <div ref={navRef} className={style.overlay} onClick={closeNav}>
@ -54,8 +67,11 @@ const NavBar = () => {
<div className="overlay-content"> <div className="overlay-content">
<Link href="/" legacyBehavior><a className={style.link} >Accueil</a></Link> | <Link href="/" legacyBehavior><a className={style.link} >Accueil</a></Link> |
<Link href="/contact" legacyBehavior><a className={style.link} >Nos produits</a></Link> | <Link href="/contact" legacyBehavior><a className={style.link} >Nos produits</a></Link> |
<Link href="/" legacyBehavior><a className={style.link} >Contactez-nous</a></Link> | <Link href="/" legacyBehavior><a className={style.link} >Contactez-nous</a></Link> |
<Link href="/user" legacyBehavior><a className={style.link} >Connexion</a></Link> <Link href="/connexion" legacyBehavior><a className={style.link} >Connexion</a></Link>
{session && <span className={`${style.connexion} badge rounded-pill bg-light text-dark`}><FiArrowRight />{session.user.email}</span>}
</div> </div>
</div> </div>

@ -18,28 +18,35 @@ const options = {
authorization: 'https://accounts.google.com/o/oauth2/v2/auth?prompt=consent&access_type=offline&response_type=code', authorization: 'https://accounts.google.com/o/oauth2/v2/auth?prompt=consent&access_type=offline&response_type=code',
}), }),
EmailProvider({ EmailProvider({
server: process.env.EMAIL_SERVER, server: {
from: process.env.EMAIL_FROM, host: process.env.EMAIL_SERVER_HOST,
port: parseInt(process.env.EMAIL_SERVER_PORT),
auth: {
user: process.env.EMAIL_SERVER_USER,
pass: process.env.EMAIL_SERVER_PASSWORD
}
},
from: process.env.EMAIL_FROM
}), }),
], ],
adapter: PrismaAdapter(prisma), adapter: PrismaAdapter(prisma),
secret: process.env.SECRET, secret: process.env.SECRET,
callbacks: { callbacks: {
async session({ session, user }) { async session({ session, user }) {
const getCurrentUser = await prisma.user.findMany({ const getCurrentUser = await prisma.user.findMany({
where: { email: session.user.email }, where: { email: session.user.email },
}) })
//récupération du role //récupération du role
const { role } = getCurrentUser[0]; const { role } = getCurrentUser[0];
session.user.role = role session.user.role = role
return session return session
} }
}, },
error: '/error', pages: {
// signIn: '/auth/signin',
// signOut: '/auth/signout',
// error: '/auth/error', // Error code passed in query string as ?error=
verifyRequest: '/verify-request', // (used for check email message)
// newUser: '/auth/new-user' // New users will be directed here on first sign in (leave the property out if not of interest)
}
} }

@ -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,42 @@ 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";
import { isGeneratorFunction } from "util/types";
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 = ({ csrfToken }: Props) => {
const MainPage = () => {
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(
acceptTerms: Yup.bool().oneOf( // "Veuillez rentrer une adresse mail valide"
[true], // ),
"Accepter les conditions est obligatoire" // acceptTerms: Yup.bool().oneOf(
) // [true],
// "Vous devez accepter les conditions obligatoire"
// )
}) })
const { const {
register, register,
clearErrors,
handleSubmit, handleSubmit,
watch, watch,
trigger, trigger,
@ -55,16 +66,45 @@ const MainPage = () => {
}); });
const term = watch("acceptTerms") const acceptTermCheckBox = watch("acceptTerms")
const connexionWithGoogle = async () => { const connexionWithGoogle = async () => {
if (term) { if (onCheckTerms()) {
signIn("google"); signIn("google")
} }
//relance une vérification de la checkbox
await trigger("acceptTerms"); await trigger("acceptTerms");
} }
const onSubmit = async (data: LoginSubmitForm) => {
const onMailSubmit = async (data: LoginSubmitForm) => {
if (onCheckTerms()) {
signIn("email", { email: data.email, callbackUrl: `${window.location.origin}/create` })
}
await trigger("acceptTerms");
await trigger("email");
}
const onCheckTerms = (): any => {
if (acceptTermCheckBox) {
return true;
} else {
toast.error('Vous devez accepter les conditions obligatoires', {
position: "top-center",
autoClose: 2000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "light",
});
}
}
// try { // try {
@ -83,9 +123,6 @@ const MainPage = () => {
// } catch (error) { // } catch (error) {
// console.error(error); // console.error(error);
// } // }
};
return ( return (
<> <>
<Head> <Head>
@ -93,44 +130,31 @@ 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} />
<form onSubmit={handleSubmit(onSubmit)}> <SiGnuprivacyguard size={50} />
<form onSubmit={handleSubmit(onMailSubmit)}>
<div className="form-group mx-auto my-3 w-100"> <div className="form-group mx-auto my-3 w-100">
<div className="mb-3">
<input <input
type="email" type="email" id="email" name="email"
className={`form-control ${errors.email ? 'is-invalid' : ''}`} className={`mb-3 form-control ${errors.email ? 'is-invalid' : ''}`}
placeholder="Email..." placeholder="Email..."
{...register("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>
<hr /> <hr />
<div className="d-grid"> <div className="d-grid">
<button onClick={connexionWithGoogle} type="button" className={`btn btn-primary ${style.loginButton}`} style={{ backgroundColor: "#dd4b39" }}> <button onClick={connexionWithGoogle} type="button" className={`btn btn-primary ${style.loginButton}`} style={{ backgroundColor: "#dd4b39" }}>
<span className={style.logo}><AiOutlineGoogle /></span>Se connecter avec google <span className={style.logo}><AiOutlineGoogle /></span>Se connecter avec google
</button> </button>
</div> </div>
<div className="form-group">
<div className="form-check">
<label <label
htmlFor="acceptTerms" htmlFor="acceptTerms"
className="form-check-label" className="form-check-label"
@ -140,23 +164,13 @@ const MainPage = () => {
</label> </label>
<input <input
type="checkbox" type="checkbox"
className="form-check-input" className={`form-check-input ${errors.acceptTerms ? 'is-invalid' : ''}`}
{...register("acceptTerms")} {...register("acceptTerms")}
name="acceptTerms" name="acceptTerms"
/> />
</div>
</div> </div>
</form> </form>
<div className="invalid-feedback alert alert-danger">{errors.acceptTerms?.message}</div>
<div className="invalid-feedback alert alert-danger">{errors.email?.message}</div>
</div > </div >
</>) </>)
}; };

@ -0,0 +1,61 @@
import React, { useEffect } from "react";
import prisma from '../lib/prisma'
import Image from 'next/image';
import * as Yup from 'yup';
import Head from "next/head";
import { getCsrfToken, signIn, useSession } from "next-auth/react";
import { yupResolver } from "@hookform/resolvers/yup";
import { useForm } from "react-hook-form";
import { AiOutlineCheck } from 'react-icons/ai'
import Router from "next/router";
import style from '../styles/Connexion.module.css';
import imageConnexion from '../public/images/connexion_image.png'
import Link from "next/link";
import { GrValidate } from 'react-icons/gr'
import { toast } from "react-toastify";
import { Token } from "nodemailer/lib/xoauth2";
import { isGeneratorFunction } from "util/types";
const VerifyRequest = () => {
//va rediriger après 3 seconde
useEffect(() => {
setTimeout(() => {
Router.push("/")
}, 3000)
}, [])
return (
<>
<Head>
<title>Page Confirmation email</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
</Head>
<div className={`${style['bloc-content']} col-12 col-lg-6`}>
<h1 className="fw-light">Un email a été envoyé</h1>
<GrValidate size={100} />
<div className="d-grid mt-4">
<button onClick={() => Router.push("/")} type="button" className={`btn btn-primary`}>
Cliquez ici si vous n'êtes pas rediriger à l'accueil
</button>
</div>
</div >
</>)
};
export default VerifyRequest;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

@ -5,7 +5,7 @@
background-position: 50% 50%; background-position: 50% 50%;
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: contain; background-size: contain;
animation: zoomInOut 4s ease-in-out infinite; /* animation: zoomInOut 4s ease-in-out infinite; */
z-index: 9000; z-index: 9000;
} }

@ -9,6 +9,12 @@
text-decoration: underline; text-decoration: underline;
} }
.connexion {
position: absolute;
top: 0;
right: 0;
}
/**************************/ /**************************/
.overlay { .overlay {

@ -5,6 +5,7 @@ body {
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
font-size: small;
} }
a, a,

Loading…
Cancel
Save