Features added : - Add sign-in page - Add sign-up page - Custom endpoint in Strapi to verify email - Add JWT authenticationfeature/blog
parent
e0dbb351a9
commit
b29f4a411e
@ -0,0 +1,22 @@
|
||||
module.exports = ({env}) => ({
|
||||
// ...
|
||||
email: {
|
||||
config: {
|
||||
provider: 'nodemailer',
|
||||
providerOptions: {
|
||||
host: env('SMTP_HOST', 'smtp.example.com'),
|
||||
port: env('SMTP_PORT', 587),
|
||||
auth: {
|
||||
user: env('SMTP_USERNAME'),
|
||||
pass: env('SMTP_PASSWORD'),
|
||||
},
|
||||
// ... any custom nodemailer options
|
||||
},
|
||||
settings: {
|
||||
defaultFrom: 'no-reply@naser.fr',
|
||||
defaultReplyTo: 'contact@naser.fr',
|
||||
},
|
||||
},
|
||||
},
|
||||
// ...
|
||||
});
|
||||
@ -0,0 +1,17 @@
|
||||
/**
|
||||
* A set of functions called "actions" for `username`
|
||||
*/
|
||||
|
||||
export default {
|
||||
findOne: async (ctx, next) => {
|
||||
try {
|
||||
const data = await strapi
|
||||
.service("api::username.username")
|
||||
.findUsername(ctx.params.username);
|
||||
|
||||
ctx.body = data;
|
||||
} catch (err) {
|
||||
ctx.badRequest("Post report controller error", {moreDetails: err});
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,13 @@
|
||||
export default {
|
||||
routes: [
|
||||
{
|
||||
method: 'GET',
|
||||
path: '/username/:username',
|
||||
handler: 'username.findOne',
|
||||
config: {
|
||||
policies: [],
|
||||
middlewares: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* username service
|
||||
*/
|
||||
|
||||
export default () => ({
|
||||
findUsername: async (username) => {
|
||||
try {
|
||||
console.log(username);
|
||||
let users = await strapi.entityService.findMany(
|
||||
"plugin::users-permissions.user", {filters: {email: username}}
|
||||
);
|
||||
|
||||
return users.length !== 0;
|
||||
} catch (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,79 @@
|
||||
{
|
||||
"kind": "collectionType",
|
||||
"collectionName": "up_users",
|
||||
"info": {
|
||||
"name": "user",
|
||||
"description": "",
|
||||
"singularName": "user",
|
||||
"pluralName": "users",
|
||||
"displayName": "User"
|
||||
},
|
||||
"options": {
|
||||
"draftAndPublish": false,
|
||||
"timestamps": true
|
||||
},
|
||||
"attributes": {
|
||||
"username": {
|
||||
"type": "string",
|
||||
"minLength": 3,
|
||||
"unique": true,
|
||||
"configurable": false,
|
||||
"required": true
|
||||
},
|
||||
"email": {
|
||||
"type": "email",
|
||||
"minLength": 6,
|
||||
"configurable": false,
|
||||
"required": true
|
||||
},
|
||||
"provider": {
|
||||
"type": "string",
|
||||
"configurable": false
|
||||
},
|
||||
"password": {
|
||||
"type": "password",
|
||||
"minLength": 6,
|
||||
"configurable": false,
|
||||
"private": true
|
||||
},
|
||||
"resetPasswordToken": {
|
||||
"type": "string",
|
||||
"configurable": false,
|
||||
"private": true
|
||||
},
|
||||
"confirmationToken": {
|
||||
"type": "string",
|
||||
"configurable": false,
|
||||
"private": true
|
||||
},
|
||||
"confirmed": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"configurable": false
|
||||
},
|
||||
"blocked": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"configurable": false
|
||||
},
|
||||
"role": {
|
||||
"type": "relation",
|
||||
"relation": "manyToOne",
|
||||
"target": "plugin::users-permissions.role",
|
||||
"inversedBy": "users",
|
||||
"configurable": false
|
||||
},
|
||||
"avatar": {
|
||||
"allowedTypes": [
|
||||
"images"
|
||||
],
|
||||
"type": "media",
|
||||
"configurable": false,
|
||||
"multiple": false
|
||||
},
|
||||
"newsletter": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1 +1,4 @@
|
||||
STRAPI_URL=http://127.0.0.1:1337/api
|
||||
STRAPI_URL_API=http://127.0.0.1:1337/api
|
||||
STRAPI_URL=http://127.0.0.1:1337/
|
||||
NEXTAUTH_SECRET=<SECRET>
|
||||
NEXTAUTH_URL=http://localhost:4200
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
/*
|
||||
* Replace this with your own classes
|
||||
*
|
||||
* e.g.
|
||||
* .container {
|
||||
* }
|
||||
*/
|
||||
@ -0,0 +1,10 @@
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import HeaderAuth from './header-auth';
|
||||
|
||||
describe('HeaderAuth', () => {
|
||||
it('should render successfully', () => {
|
||||
const { baseElement } = render(<HeaderAuth />);
|
||||
expect(baseElement).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,28 @@
|
||||
import styles from './header-auth.module.scss';
|
||||
import {useRouter} from "next/router";
|
||||
|
||||
export function HeaderAuth() {
|
||||
const router = useRouter();
|
||||
|
||||
const goBack = (event) => {
|
||||
router.back();
|
||||
}
|
||||
|
||||
return (
|
||||
<nav className="bg-white border-gray-200 px-2 sm:px-4 py-2.5 rounded dark:bg-gray-900">
|
||||
<div className="container flex flex-wrap items-center justify-between mx-auto">
|
||||
<div className="flex md:order-2">
|
||||
<button type="button"
|
||||
onClick={(event) => goBack(event)}
|
||||
className="py-2.5 px-5 mr-2 mb-2 text-sm font-medium text-gray-900 focus:outline-none bg-white rounded-lg border border-gray-200 hover:bg-gray-100 hover:text-blue-700 focus:z-10 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700">
|
||||
Retour au site
|
||||
</button>
|
||||
</div>
|
||||
<div className="items-center justify-between hidden w-full md:flex md:w-auto md:order-1"
|
||||
id="navbar-sticky"></div>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
export default HeaderAuth;
|
||||
@ -0,0 +1,7 @@
|
||||
export const environment = {
|
||||
production: true,
|
||||
strapi: {
|
||||
apiUrl: 'http://localhost:1337/api',
|
||||
url: 'http://localhost:1337'
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,7 @@
|
||||
export const environment = {
|
||||
production: false,
|
||||
strapi: {
|
||||
apiUrl: 'http://localhost:1337/api',
|
||||
url: 'http://localhost:1337'
|
||||
}
|
||||
};
|
||||
@ -0,0 +1,26 @@
|
||||
import axios from 'axios';
|
||||
import {signIn} from "next-auth/react";
|
||||
|
||||
const strapiUrl = process.env.STRAPI_URL_API;
|
||||
|
||||
export async function createJwtToken(email, password) {
|
||||
return await signIn('credentials', {
|
||||
redirect: false,
|
||||
email,
|
||||
password,
|
||||
});
|
||||
}
|
||||
|
||||
export async function signInStrapi({email, password}) {
|
||||
const res = await axios.post(`${strapiUrl}/auth/local`, {
|
||||
identifier: email,
|
||||
password,
|
||||
});
|
||||
if (res && res.data) {
|
||||
const user = await axios.get(`${strapiUrl}/users/${res.data.user.id}?populate=deep`);
|
||||
if (user && user.data) {
|
||||
res.data.user = {...res.data.user, ...user.data};
|
||||
}
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
import NextAuth, {Session, User} from 'next-auth';
|
||||
import CredentialsProvider from 'next-auth/providers/credentials';
|
||||
import {JWT} from "next-auth/jwt";
|
||||
import {AdapterUser} from "next-auth/adapters";
|
||||
|
||||
import {signInStrapi} from '../../../libs/auth';
|
||||
|
||||
export default NextAuth({
|
||||
// Configure one or more authentication providers
|
||||
providers: [
|
||||
CredentialsProvider({
|
||||
name: 'Sign in with Email',
|
||||
credentials: {
|
||||
email: {label: 'Email', type: 'text'},
|
||||
password: {label: 'Password', type: 'password'},
|
||||
},
|
||||
async authorize(credentials, req) {
|
||||
/**
|
||||
* This function is used to define if the user is authenticated or not.
|
||||
* If authenticated, the function should return an object contains the user data.
|
||||
* If not, the function should return `null`.
|
||||
*/
|
||||
if (credentials == null) return null;
|
||||
/**
|
||||
* credentials is defined in the config above.
|
||||
* We can expect it contains two properties: `email` and `password`
|
||||
*/
|
||||
try {
|
||||
const {user, jwt} = await signInStrapi({
|
||||
email: credentials.email,
|
||||
password: credentials.password,
|
||||
});
|
||||
return {...user, jwt};
|
||||
} catch (error) {
|
||||
// Sign In Fail
|
||||
return null;
|
||||
}
|
||||
},
|
||||
}),
|
||||
],
|
||||
callbacks: {
|
||||
session: async ({session, token}: {session: Session, token: JWT}) => {
|
||||
(session as any).id = token.id;
|
||||
(session as any).jwt = token.jwt;
|
||||
(session as any).user = {
|
||||
avatar: (token.user as any).avatar,
|
||||
username: (token.user as any).username,
|
||||
email: (token.user as any).email,
|
||||
};
|
||||
return Promise.resolve(session);
|
||||
},
|
||||
jwt: async ({token, user}: {token: JWT, user: User | AdapterUser}) => {
|
||||
const isSignIn = user ? true : false;
|
||||
if (isSignIn) {
|
||||
token.id = user.id;
|
||||
token.jwt = (user as any).jwt;
|
||||
token.user = (user as any);
|
||||
}
|
||||
return Promise.resolve(token);
|
||||
},
|
||||
},
|
||||
});
|
||||
@ -0,0 +1,7 @@
|
||||
/*
|
||||
* Replace this with your own classes
|
||||
*
|
||||
* e.g.
|
||||
* .container {
|
||||
* }
|
||||
*/
|
||||
@ -0,0 +1,33 @@
|
||||
import axios from "axios";
|
||||
import delve from "dlv";
|
||||
|
||||
import SeoConfig from "../../components/seo-config/seo-config";
|
||||
import Layout from "../../components/layout/layout";
|
||||
|
||||
export const getServerSideProps = async (context) => {
|
||||
const path = context.resolvedUrl;
|
||||
const menuHeader = await axios.get(`${process.env.STRAPI_URL_API}/menus/1?nested&populate=deep`);
|
||||
const menuFooter = await axios.get(`${process.env.STRAPI_URL_API}/menus/2?nested&populate=deep`);
|
||||
const page = await axios.get(`${process.env.STRAPI_URL_API}/pages?filters[slug]=${path === '/' ? 'home' : path.slice(1, path.length)}&populate=deep`);
|
||||
return {
|
||||
props: {
|
||||
menuHeader: delve(menuHeader, 'data.data.attributes.items.data', []),
|
||||
menuFooter: delve(menuFooter, 'data.data.attributes.items.data', []),
|
||||
page: delve(page, "data.data.0.attributes", {}),
|
||||
seo: delve(page, "data.data.0.attributes.seo", {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function Home({menuHeader, menuFooter, page, seo}) {
|
||||
return (
|
||||
<>
|
||||
<SeoConfig {...seo}/>
|
||||
<Layout menuHeader={menuHeader} menuFooter={menuFooter}>
|
||||
<p>Page d'accueil</p>
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Home;
|
||||
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Replace this with your own classes
|
||||
*
|
||||
* e.g.
|
||||
* .container {
|
||||
* }
|
||||
*/
|
||||
.page-sign-in {
|
||||
position: relative;
|
||||
height: 100vh;
|
||||
|
||||
.section {
|
||||
min-height: 100vh;
|
||||
justify-content: center;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,121 @@
|
||||
import delve from "dlv";
|
||||
import axios from "axios";
|
||||
import {useRouter} from "next/router";
|
||||
|
||||
import SeoConfig from "../../components/seo-config/seo-config";
|
||||
import Layout from "../../components/layout/layout";
|
||||
|
||||
import styles from './index.module.scss';
|
||||
import {createJwtToken} from "../../libs/auth";
|
||||
|
||||
export const getServerSideProps = async (context) => {
|
||||
const path = context.resolvedUrl;
|
||||
const menuFooter = await axios.get(`${process.env.STRAPI_URL_API}/menus/2?nested&populate=deep`);
|
||||
const page = await axios.get(`${process.env.STRAPI_URL_API}/pages?filters[slug]=${path === '/' ? 'home' : path.slice(1, path.length)}&populate=deep`);
|
||||
|
||||
return {
|
||||
props: {
|
||||
menuFooter: delve(menuFooter, 'data.data.attributes.items.data', []),
|
||||
page: delve(page, "data.data.0.attributes", {}),
|
||||
seo: delve(page, "data.data.0.attributes.seo", {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function SignIn({seo, menuFooter}) {
|
||||
const router = useRouter();
|
||||
|
||||
const onSubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
const result = await createJwtToken(e.target.email.value, e.target.password.value);
|
||||
if (result.ok) {
|
||||
await router.replace('/');
|
||||
return;
|
||||
}
|
||||
|
||||
alert('Credential is not valid');
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<SeoConfig {...seo}/>
|
||||
<Layout showHeaders={false} showFooter={false} menuFooter={menuFooter} className="bg-gray-50">
|
||||
<div className={styles['page-sign-in']}>
|
||||
<main className={styles['section']}>
|
||||
<div className="container max-w-5xl px-6 py-4 md:py-12 h-full mx-auto relative -top-[25px] md:-top-[50px]">
|
||||
<div className="flex flex-col justify-center items-center flex-wrap h-full g-6 text-gray-800">
|
||||
<header className="max-w-[440px] text-center block">
|
||||
<a href="https://flowbite.com/" className="flex items-center justify-center mb-6">
|
||||
<img src="https://flowbite.com/docs/images/logo.svg" className="h-6 mr-3 sm:h-9"
|
||||
alt="Flowbite Logo"/>
|
||||
<span
|
||||
className="self-center text-xl font-semibold whitespace-nowrap dark:text-white">Flowbite</span>
|
||||
</a>
|
||||
|
||||
<h3
|
||||
className="mb-4 text-2xl font-extrabold leading-none text-center tracking-tight text-gray-900 md:text-3xl lg:text-3xl dark:text-white">
|
||||
Connexion à votre compte
|
||||
</h3>
|
||||
<p className="mb-6 text-md font-normal text-gray-500 lg:text-xl dark:text-gray-400">
|
||||
Vous n'êtes pas encore inscrit ? <br/><a href="/sign-up"
|
||||
className="font-medium text-blue-600 dark:text-blue-500 hover:underline"
|
||||
target="_self">Créez un compte maintenant</a>.
|
||||
</p>
|
||||
</header>
|
||||
<section
|
||||
className="w-full max-w-[440px] p-4 bg-white border border-gray-200 rounded-lg shadow-md sm:p-6 md:p-8 dark:bg-gray-800 dark:border-gray-700">
|
||||
<div className="w-full">
|
||||
<form onSubmit={onSubmit}>
|
||||
<div className="mb-6">
|
||||
<label htmlFor="email"
|
||||
className="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
|
||||
E-mail
|
||||
</label>
|
||||
<input type="email"
|
||||
id="email"
|
||||
name="email"
|
||||
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"/>
|
||||
</div>
|
||||
<div className="mb-6">
|
||||
<label htmlFor="password"
|
||||
className="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
|
||||
Mot de passe
|
||||
</label>
|
||||
<input type="password"
|
||||
id="password"
|
||||
name="password"
|
||||
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"/>
|
||||
</div>
|
||||
<div className="flex justify-between items-center mb-6">
|
||||
<div className="form-group form-check flex items-center">
|
||||
<input id="default-checkbox" type="checkbox" value=""
|
||||
className="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 rounded focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600"/>
|
||||
<label htmlFor="default-checkbox"
|
||||
className="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">
|
||||
Rester connecté ?
|
||||
</label>
|
||||
</div>
|
||||
<a href=""
|
||||
className="text-blue-600 hover:text-blue-700 focus:text-blue-700 active:text-blue-800 duration-200 transition ease-in-out text-sm">
|
||||
Mot de passe oublié ?
|
||||
</a>
|
||||
</div>
|
||||
<button type="submit"
|
||||
className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800 w-full"
|
||||
data-mdb-ripple="true"
|
||||
data-mdb-ripple-color="light">
|
||||
Connexion
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default SignIn;
|
||||
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Replace this with your own classes
|
||||
*
|
||||
* e.g.
|
||||
* .container {
|
||||
* }
|
||||
*/
|
||||
.page-sign-up {
|
||||
|
||||
.section {
|
||||
min-height: 70vh;
|
||||
justify-content: center;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,248 @@
|
||||
import styles from './index.module.scss';
|
||||
import axios from "axios";
|
||||
import delve from 'dlv';
|
||||
import {useRouter} from "next/router";
|
||||
import {SubmitHandler, useForm} from 'react-hook-form';
|
||||
|
||||
import SeoConfig from "../../components/seo-config/seo-config";
|
||||
import Layout from "../../components/layout/layout";
|
||||
import {Inputs, signUpRequest} from "../../libs/api";
|
||||
import {createJwtToken} from "../../libs/auth";
|
||||
import {useEffect, useState} from "react";
|
||||
import {BehaviorSubject, debounceTime, distinctUntilChanged, filter, map, switchMap} from "rxjs";
|
||||
|
||||
export const getServerSideProps = async (context) => {
|
||||
const path = context.resolvedUrl;
|
||||
const menuHeader = await axios.get(`${process.env.STRAPI_URL_API}/menus/1?nested&populate=deep`);
|
||||
const menuFooter = await axios.get(`${process.env.STRAPI_URL_API}/menus/2?nested&populate=deep`);
|
||||
const page = await axios.get(`${process.env.STRAPI_URL_API}/pages?filters[slug]=${path === '/' ? 'home' : path.slice(1, path.length)}&populate=deep`);
|
||||
|
||||
return {
|
||||
props: {
|
||||
menuHeaders: delve(menuHeader, 'data.data.attributes.items.data', []),
|
||||
menuFooter: delve(menuFooter, 'data.data.attributes.items.data', []),
|
||||
page: delve(page, "data.data.0.attributes", {}),
|
||||
seo: delve(page, "data.data.0.attributes.seo", {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function SignUp({seo, menuHeaders, menuFooter}) {
|
||||
const router = useRouter();
|
||||
const {register, handleSubmit, watch, getValues, formState: {errors}, setError, clearErrors} = useForm({
|
||||
defaultValues: {
|
||||
email: "",
|
||||
username: "",
|
||||
password: "",
|
||||
passwordConfirmation: "",
|
||||
agreement: false,
|
||||
newsletter: false,
|
||||
}
|
||||
});
|
||||
const [spinner, setSpinner] = useState(false);
|
||||
const [subject, setSubject] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (subject === null) {
|
||||
const sub = new BehaviorSubject('');
|
||||
setSubject(sub);
|
||||
} else {
|
||||
subject.pipe(
|
||||
map((s: string) => s.trim()),
|
||||
distinctUntilChanged(),
|
||||
filter((s: string) => s.length >= 2),
|
||||
debounceTime(200),
|
||||
switchMap(async (value) => {
|
||||
setSpinner(true);
|
||||
const result = await axios.get(`http://localhost:1337/api/username/${value}`)
|
||||
if (result.data) {
|
||||
setError('email', {type: 'custom', message: "Cet email est déjà utilisé. Veuillez en saisir un autre."});
|
||||
} else {
|
||||
clearErrors('email');
|
||||
}
|
||||
}),
|
||||
).subscribe(() => setSpinner(false));
|
||||
}
|
||||
}, [subject]);
|
||||
|
||||
const onSubmit: SubmitHandler<Inputs> = async (data: Inputs) => {
|
||||
try {
|
||||
await signUpRequest(data);
|
||||
const result = await createJwtToken(data.email, data.password);
|
||||
if (result.ok) {
|
||||
await router.replace('/');
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
const onEmailChange = (e) => subject.next(e.target.value);
|
||||
|
||||
const hasErrors = () => Object.keys(errors).length > 0;
|
||||
|
||||
return (
|
||||
<>
|
||||
<SeoConfig {...seo}/>
|
||||
<Layout menuHeader={menuHeaders} menuFooter={menuFooter}>
|
||||
<div className={styles['page-sign-up']}>
|
||||
<section className={styles['section']}>
|
||||
<div className="container px-6 py-4 md:py-12 h-full mx-auto">
|
||||
<div className="flex justify-center items-center flex-wrap h-full g-6 text-gray-800">
|
||||
<div className="md:w-8/12 lg:w-6/12">
|
||||
<div
|
||||
className="w-full max-w-[560px] p-4 bg-white border border-gray-200 rounded-lg shadow-md sm:p-6 md:p-8 dark:bg-gray-800 dark:border-gray-700">
|
||||
<form className="space-y-6" onSubmit={handleSubmit(onSubmit)}>
|
||||
<header className="text-left block">
|
||||
<h3 className="text-3xl font-normal dark:text-white mb-6">Création de votre compte</h3>
|
||||
<p className="mb-6 text-base font-normal text-gray-500 dark:text-gray-400">
|
||||
Créez un compte gratuit 100% sécurisé. <br/>Vous avez déjà un compte ? <a href="/sign-in"
|
||||
className="font-medium text-blue-600 dark:text-blue-500 hover:underline"
|
||||
target="_self">
|
||||
Connectez-vous ici
|
||||
</a>.
|
||||
</p>
|
||||
</header>
|
||||
<main>
|
||||
<section className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label htmlFor="email"
|
||||
className="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
|
||||
E-mail
|
||||
</label>
|
||||
<div className="relative">
|
||||
{spinner && (
|
||||
<div className="absolute inset-y-0 right-0 flex items-center pr-1 pointer-events-none">
|
||||
<svg aria-hidden="true"
|
||||
className="w-5 h-5 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
|
||||
viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"/>
|
||||
</svg>
|
||||
<span className="sr-only">Loading...</span>
|
||||
</div>)}
|
||||
<input type="email"
|
||||
name="email"
|
||||
id="email"
|
||||
{...register("email", {required: "L'email est requis"})}
|
||||
onChange={onEmailChange}
|
||||
className={errors.email ? 'bg-red-50 border border-red-500 text-red-900 placeholder-red-700 text-sm rounded-lg focus:ring-red-500 dark:bg-gray-700 focus:border-red-500 block w-full p-2.5 dark:text-red-500 dark:placeholder-red-500 dark:border-red-500' : 'bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pr-10 p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white'}
|
||||
placeholder="name@company.com"/>
|
||||
{errors.email && (
|
||||
<p className="mt-2 text-sm text-red-600 dark:text-red-500">{errors.email.message}</p>)}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="username"
|
||||
className="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
|
||||
Nom d'utilisateur
|
||||
</label>
|
||||
<input type="text"
|
||||
name="username"
|
||||
id="username"
|
||||
{...register("username", {required: "Le nom d'utilisateur est requis"})}
|
||||
className={errors.username ? "bg-red-50 border border-red-500 text-red-900 placeholder-red-700 text-sm rounded-lg focus:ring-red-500 dark:bg-gray-700 focus:border-red-500 block w-full p-2.5 dark:text-red-500 dark:placeholder-red-500 dark:border-red-500" : "bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white"}
|
||||
placeholder="JohnDoe"/>
|
||||
{errors.username && (
|
||||
<p className="mt-2 text-sm text-red-600 dark:text-red-500">{errors.username.message}</p>)}
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="password"
|
||||
className="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
|
||||
Mot de passe
|
||||
</label>
|
||||
<input type="password"
|
||||
name="password"
|
||||
id="password"
|
||||
{...register("password", {required: "Le mot de passe est requis", minLength: 8})}
|
||||
className={errors.password ? "bg-red-50 border border-red-500 text-red-900 placeholder-red-700 text-sm rounded-lg focus:ring-red-500 dark:bg-gray-700 focus:border-red-500 block w-full p-2.5 dark:text-red-500 dark:placeholder-red-500 dark:border-red-500" : "bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white"}
|
||||
placeholder=""/>
|
||||
{errors.password && errors.password.type !== "minLength" && (
|
||||
<p className="mt-2 text-sm text-red-600 dark:text-red-500">{errors.password.message}</p>)}
|
||||
{errors.password && errors.password.type === "minLength" && (
|
||||
<p className="mt-2 text-sm text-red-600 dark:text-red-500">Le mot de passe doit avoir une
|
||||
longueur minimum de 8 charactères</p>)}
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="password2"
|
||||
className="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
|
||||
Confirmez le mot de passe
|
||||
</label>
|
||||
<input type="password"
|
||||
name="passwordConfirmation"
|
||||
id="passwordConfirmation"
|
||||
{...register("passwordConfirmation", {
|
||||
required: "Veuillez confirmer le mot de passe", validate: {
|
||||
matchesPreviousPassword: (value) => {
|
||||
const {password} = getValues();
|
||||
return password === value || "Les mots de passe ne correspondent pas";
|
||||
}
|
||||
}
|
||||
})}
|
||||
className={errors.passwordConfirmation ? "bg-red-50 border border-red-500 text-red-900 placeholder-red-700 text-sm rounded-lg focus:ring-red-500 dark:bg-gray-700 focus:border-red-500 block w-full p-2.5 dark:text-red-500 dark:placeholder-red-500 dark:border-red-500" : "bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white"}
|
||||
placeholder=""/>
|
||||
{errors.passwordConfirmation && (
|
||||
<p
|
||||
className="mt-2 text-sm text-red-600 dark:text-red-500">{errors.passwordConfirmation.message}</p>)}
|
||||
</div>
|
||||
</section>
|
||||
<section className="py-5">
|
||||
<div className="flex items-center">
|
||||
<input id="agreement"
|
||||
type="checkbox"
|
||||
value=""
|
||||
name="agreement"
|
||||
{...register("agreement", {required: "Vous devez accepter les conditions d'utilisation"})}
|
||||
className="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-blue-600 dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800"/>
|
||||
<label htmlFor="agreement"
|
||||
className="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">
|
||||
En vous inscrivant, vous créez un compte MeCP et vous acceptez les conditions
|
||||
d'utilisation et la politique de confidentialité de MeCP.
|
||||
</label>
|
||||
</div>
|
||||
{errors.agreement && (
|
||||
<p className="mt-2 text-sm text-red-600 dark:text-red-500">{errors.agreement.message}</p>)}
|
||||
</section>
|
||||
<section className="flex items-center pb-5">
|
||||
<input id="newsletter"
|
||||
type="checkbox"
|
||||
value=""
|
||||
name="newsletter"
|
||||
{...register("newsletter")}
|
||||
className="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-blue-300 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-blue-600 dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800"/>
|
||||
<label htmlFor="newsletter"
|
||||
className="ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">
|
||||
Envoyez-moi un e-mail sur les mises à jour de l'école, des cours et les produits.
|
||||
</label>
|
||||
</section>
|
||||
<section className="flex items-center pt-5">
|
||||
<button type="submit"
|
||||
className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800 w-full disabled:bg-gray-500 focus:disabled:bg-gray-500 hover:disabled:bg-gray-500"
|
||||
data-mdb-ripple="true"
|
||||
data-mdb-ripple-color="light" disabled={hasErrors()}>
|
||||
Inscription
|
||||
</button>
|
||||
</section>
|
||||
</main>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div className="md:w-8/12 lg:w-6/12 mb-12 md:mb-0 hidden md:block">
|
||||
<img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-login-form/draw2.png"
|
||||
className="w-full" alt="Phone image"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default SignUp;
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue