merge branch develop
This commit is contained in:
commit
8871df3582
24 files changed
+49399
-554
No files matched your search
@@ -6,8 +6,8 @@ GITHUB_ID=YOUR_GITHUB_CLIENT_ID
|
||||
GITHUB_SECRET=YOUR_GITHUB_CLIENT_SECRET
|
||||
|
||||
# Google Auth Provider
|
||||
GOOGLE_CLIENT_ID=5572607706-p6dftn0ss3m2qnvqbhk4khqte8lk7kt3.apps.googleusercontent.com
|
||||
GOOGLE_CLIENT_SECRET=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
|
||||
GOOGLE_CLIENT_ID=965228443747-049kq59pm43bd23aplfu9ja2333dpo5s.apps.googleusercontent.com
|
||||
GOOGLE_CLIENT_SECRET=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
|
||||
|
||||
DATABASE_URL="postgres://postgres:postgrespwd@localhost:5432/thetiptop"
|
||||
|
||||
|
||||
Vendored
+5
@@ -1,2 +1,7 @@
|
||||
{
|
||||
"workbench.colorCustomizations": {
|
||||
"activityBar.background": "#4C1F25",
|
||||
"titleBar.activeBackground": "#6A2C34",
|
||||
"titleBar.activeForeground": "#FEFCFC"
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
FROM node:alpine
|
||||
|
||||
#copy source
|
||||
COPY . /app
|
||||
|
||||
# Install deps
|
||||
RUN cd /app && npm install
|
||||
|
||||
# Build
|
||||
RUN npm run build
|
||||
|
||||
ENTRYPOINT [ "npm", "run", "start" ]
|
||||
Vendored
+40
-12
@@ -1,13 +1,41 @@
|
||||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('build') {
|
||||
steps {
|
||||
sh '''npm install
|
||||
npm run build
|
||||
npm run start'''
|
||||
}
|
||||
}
|
||||
rm -rf $WORKSPACE/the_tip_top
|
||||
git clone git@172.17.0.3:cedric/The_Tip_Top.git $WORKSPACE/the_tip_top
|
||||
|
||||
}
|
||||
}
|
||||
cd $WORKSPACE/the_tip_top
|
||||
git checkout master
|
||||
|
||||
yarn install
|
||||
yarn build
|
||||
|
||||
mkdir the_tip_top
|
||||
|
||||
mv public/ the_tip_top/
|
||||
|
||||
NEXT_BUILD_ID=$(cat build/BUILD_ID)
|
||||
LAST_COMMIT=$(git rev-parse HEAD)
|
||||
|
||||
# That's just for debugging purposes
|
||||
echo "{git: ${LAST_COMMIT}, ci: ${BUILD_ID}, next: ${NEXT_BUILD_ID}}" > the_tip_top/CI
|
||||
|
||||
# trim package.json and leave only things that you need in production
|
||||
cat package.json | jq '. | {name: .name, private: true, version: .version, scripts: {start: .scripts.start}, dependencies: .dependencies}' > the_tip_top/package.json
|
||||
|
||||
# I'm using next-compose-plugins, so here we need to dump config. If you have next.config.js as an object then just copy config file
|
||||
NEXT_CONFIG=$(node -e 'var configFile = require("./next.config.js"); var config = configFile([], {}); delete config.webpack; console.log(JSON.stringify(config));')
|
||||
echo "module.exports = ${NEXT_CONFIG}" > the_tip_top/next.config.js # result => {distDir: "build", poweredByHeader: false}
|
||||
|
||||
mv build the_tip_top/
|
||||
|
||||
cd the_tip_top
|
||||
|
||||
yarn install
|
||||
|
||||
cd $WORKSPACE/the_tip_top
|
||||
|
||||
# dump folder tree structure just for Jenkins console output logs
|
||||
tree -h -L 1 build/
|
||||
|
||||
tar czf $WORKSPACE/the_tip_top.tar.gz the_tip_top
|
||||
cd $WORKSPACE
|
||||
|
||||
rm -rf $WORKSPACE/the_tip_top
|
||||
@@ -32,6 +32,9 @@ pour upgrade votre compte en superadmin (vous devez être connecté)
|
||||
http://localhost:3000/api/gain
|
||||
pour générer un gain (vous devez être connecté en tant que superadmin ou admin)
|
||||
|
||||
**npm run test**
|
||||
tests faits avec Playwright
|
||||
|
||||
***********************************
|
||||
|
||||
|
||||
|
||||
Generated
+73
@@ -16,6 +16,8 @@
|
||||
"bootstrap": "^5.2.2",
|
||||
"chance": "^1.1.9",
|
||||
"crypto-random-string": "^3.0.0",
|
||||
"date-format": "^4.0.14",
|
||||
"dateformat": "^5.0.3",
|
||||
"js-confetti": "^0.11.0",
|
||||
"next": "13.0.2",
|
||||
"next-auth": "4.16.4",
|
||||
@@ -31,6 +33,7 @@
|
||||
"yup-phone": "^1.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.28.1",
|
||||
"@types/chance": "^1.1.3",
|
||||
"@types/next-auth": "3.13.0",
|
||||
"@types/node": "18.11.9",
|
||||
@@ -322,6 +325,22 @@
|
||||
"url": "https://github.com/sponsors/panva"
|
||||
}
|
||||
},
|
||||
"node_modules/@playwright/test": {
|
||||
"version": "1.28.1",
|
||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.28.1.tgz",
|
||||
"integrity": "sha512-xN6spdqrNlwSn9KabIhqfZR7IWjPpFK1835tFNgjrlysaSezuX8PYUwaz38V/yI8TJLG9PkAMEXoHRXYXlpTPQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/node": "*",
|
||||
"playwright-core": "1.28.1"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/@popperjs/core": {
|
||||
"version": "2.11.6",
|
||||
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz",
|
||||
@@ -900,6 +919,22 @@
|
||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz",
|
||||
"integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw=="
|
||||
},
|
||||
"node_modules/date-format": {
|
||||
"version": "4.0.14",
|
||||
"resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz",
|
||||
"integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==",
|
||||
"engines": {
|
||||
"node": ">=4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/dateformat": {
|
||||
"version": "5.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-5.0.3.tgz",
|
||||
"integrity": "sha512-Kvr6HmPXUMerlLcLF+Pwq3K7apHpYmGDVqrxcDasBg86UcKeTSNWbEzU8bwdXnxnR44FtMhJAxI4Bov6Y/KUfA==",
|
||||
"engines": {
|
||||
"node": ">=12.20"
|
||||
}
|
||||
},
|
||||
"node_modules/debug": {
|
||||
"version": "4.3.4",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||
@@ -2600,6 +2635,18 @@
|
||||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright-core": {
|
||||
"version": "1.28.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.28.1.tgz",
|
||||
"integrity": "sha512-3PixLnGPno0E8rSBJjtwqTwJe3Yw72QwBBBxNoukIj3lEeBNXwbNiKrNuB1oyQgTBw5QHUhNO3SteEtHaMK6ag==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/postcss": {
|
||||
"version": "8.4.14",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz",
|
||||
@@ -3908,6 +3955,16 @@
|
||||
"resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.0.2.tgz",
|
||||
"integrity": "sha512-MSAs9t3Go7GUkMhpKC44T58DJ5KGk2vBo+h1cqQeqlMfdGkxaVB78ZWpv9gYi/g2fa4sopag9gJsNvS8XGgWJA=="
|
||||
},
|
||||
"@playwright/test": {
|
||||
"version": "1.28.1",
|
||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.28.1.tgz",
|
||||
"integrity": "sha512-xN6spdqrNlwSn9KabIhqfZR7IWjPpFK1835tFNgjrlysaSezuX8PYUwaz38V/yI8TJLG9PkAMEXoHRXYXlpTPQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*",
|
||||
"playwright-core": "1.28.1"
|
||||
}
|
||||
},
|
||||
"@popperjs/core": {
|
||||
"version": "2.11.6",
|
||||
"resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.6.tgz",
|
||||
@@ -4339,6 +4396,16 @@
|
||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz",
|
||||
"integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw=="
|
||||
},
|
||||
"date-format": {
|
||||
"version": "4.0.14",
|
||||
"resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz",
|
||||
"integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg=="
|
||||
},
|
||||
"dateformat": {
|
||||
"version": "5.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-5.0.3.tgz",
|
||||
"integrity": "sha512-Kvr6HmPXUMerlLcLF+Pwq3K7apHpYmGDVqrxcDasBg86UcKeTSNWbEzU8bwdXnxnR44FtMhJAxI4Bov6Y/KUfA=="
|
||||
},
|
||||
"debug": {
|
||||
"version": "4.3.4",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||
@@ -5441,6 +5508,12 @@
|
||||
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
|
||||
"integrity": "sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg=="
|
||||
},
|
||||
"playwright-core": {
|
||||
"version": "1.28.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.28.1.tgz",
|
||||
"integrity": "sha512-3PixLnGPno0E8rSBJjtwqTwJe3Yw72QwBBBxNoukIj3lEeBNXwbNiKrNuB1oyQgTBw5QHUhNO3SteEtHaMK6ag==",
|
||||
"dev": true
|
||||
},
|
||||
"postcss": {
|
||||
"version": "8.4.14",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.14.tgz",
|
||||
|
||||
+5
-1
@@ -9,7 +9,8 @@
|
||||
"dev": "next",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"db": "npx prisma migrate reset --force"
|
||||
"db": "npx prisma migrate reset --force",
|
||||
"test": "playwright test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hookform/resolvers": "^2.9.10",
|
||||
@@ -19,6 +20,8 @@
|
||||
"bootstrap": "^5.2.2",
|
||||
"chance": "^1.1.9",
|
||||
"crypto-random-string": "^3.0.0",
|
||||
"date-format": "^4.0.14",
|
||||
"dateformat": "^5.0.3",
|
||||
"js-confetti": "^0.11.0",
|
||||
"next": "13.0.2",
|
||||
"next-auth": "4.16.4",
|
||||
@@ -34,6 +37,7 @@
|
||||
"yup-phone": "^1.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.28.1",
|
||||
"@types/chance": "^1.1.3",
|
||||
"@types/next-auth": "3.13.0",
|
||||
"@types/node": "18.11.9",
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getSession } from 'next-auth/react';
|
||||
import prisma from '../../../../lib/prisma'
|
||||
|
||||
|
||||
// DELETE /api/post/:id
|
||||
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
|
||||
const postId = req.query.id;
|
||||
|
||||
const session = await getSession({ req })
|
||||
|
||||
if (req.method === "DELETE") {
|
||||
if (session) {
|
||||
const post = await prisma.post.delete({
|
||||
where: { id: Number(postId) },
|
||||
});
|
||||
res.json(post);
|
||||
} else {
|
||||
res.status(401).send({ message: 'Unauthorized' })
|
||||
}
|
||||
} else {
|
||||
throw new Error(
|
||||
`The HTTP ${req.method} method is not supported at this route.`
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import prisma from '../../../../lib/prisma'
|
||||
import { getSession } from 'next-auth/react'
|
||||
|
||||
|
||||
// POST /api/post
|
||||
// Required fields in body: title
|
||||
// Optional fields in body: content
|
||||
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { title, content } = req.body;
|
||||
|
||||
const session = await getSession({ req });
|
||||
if (session) {
|
||||
const result = await prisma.post.create({
|
||||
data: {
|
||||
title: title,
|
||||
content: content,
|
||||
author: { connect: { email: session?.user?.email } },
|
||||
},
|
||||
});
|
||||
res.json(result);
|
||||
} else {
|
||||
res.status(401).send({ message: 'Unauthorized' })
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import prisma from '../../../../lib/prisma'
|
||||
import { getSession } from 'next-auth/react'
|
||||
|
||||
|
||||
// UPDATE /api/profile
|
||||
// Required fields in body: title
|
||||
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { bioValue } = req.body;
|
||||
console.log('server biovalue:', bioValue)
|
||||
const session = await getSession({ req });
|
||||
|
||||
if (req.method === "PUT") {
|
||||
if (session) {
|
||||
const updateUserProfil = await prisma.user.update({
|
||||
where: { email: session.user.email },
|
||||
data: {
|
||||
profile: {
|
||||
update: {
|
||||
bio: bioValue,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
res.status(200).send({ result: updateUserProfil, message: 'Profiled updated !' });
|
||||
} else {
|
||||
res.status(401).send({ message: 'Unauthorized' })
|
||||
}
|
||||
} else {
|
||||
throw new Error(
|
||||
`The HTTP ${req.method} method is not supported at this route.`
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getSession } from 'next-auth/react';
|
||||
import prisma from '../../../../lib/prisma'
|
||||
|
||||
// PUT /api/publish/:id
|
||||
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
|
||||
const postId = req.query.id;
|
||||
const session = await getSession({ req })
|
||||
|
||||
if (session) {
|
||||
const post = await prisma.post.update({
|
||||
where: { id: Number(postId) },
|
||||
data: { published: true },
|
||||
});
|
||||
res.json(post);
|
||||
} else {
|
||||
res.status(401).send({ message: 'Unauthorized' })
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
import React, { useState } from "react";
|
||||
import Layout from "../../components/Layout";
|
||||
import Router from "next/router";
|
||||
|
||||
const Draft = () => {
|
||||
const [title, setTitle] = useState("");
|
||||
const [content, setContent] = useState("");
|
||||
|
||||
const submitData = async (e: React.SyntheticEvent) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
const body = { title, content };
|
||||
await fetch(`/api/post`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
await Router.push("/drafts");
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<div>
|
||||
<form onSubmit={submitData}>
|
||||
<h1>New Draft</h1>
|
||||
<input
|
||||
autoFocus
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder="Title"
|
||||
type="text"
|
||||
value={title}
|
||||
/>
|
||||
<textarea
|
||||
cols={50}
|
||||
onChange={(e) => setContent(e.target.value)}
|
||||
placeholder="Content"
|
||||
rows={8}
|
||||
value={content}
|
||||
/>
|
||||
<input disabled={!content || !title} type="submit" value="Create" />
|
||||
<a className="back" href="#" onClick={() => Router.push("/")}>
|
||||
or Cancel
|
||||
</a>
|
||||
</form>
|
||||
</div>
|
||||
<style jsx>{`
|
||||
.page {
|
||||
background: white;
|
||||
padding: 3rem;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
input[type="text"],
|
||||
textarea {
|
||||
width: 100%;
|
||||
padding: 0.5rem;
|
||||
margin: 0.5rem 0;
|
||||
border-radius: 0.25rem;
|
||||
border: 0.125rem solid rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
input[type="submit"] {
|
||||
background: #ececec;
|
||||
border: 0;
|
||||
padding: 1rem 2rem;
|
||||
}
|
||||
|
||||
.back {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
`}</style>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Draft;
|
||||
@@ -1,78 +0,0 @@
|
||||
import React from "react";
|
||||
import { GetServerSideProps } from "next";
|
||||
import Layout from "../../components/Layout";
|
||||
import Post, { PostProps } from "../../components/Post";
|
||||
import { useSession, getSession } from "next-auth/react";
|
||||
import prisma from '../../lib/prisma'
|
||||
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
|
||||
const session = await getSession({ req });
|
||||
if (!session) {
|
||||
res.statusCode = 403;
|
||||
return { props: { drafts: [] } };
|
||||
}
|
||||
|
||||
const drafts = await prisma.post.findMany({
|
||||
where: {
|
||||
author: { email: session.user.email },
|
||||
published: false,
|
||||
},
|
||||
include: {
|
||||
author: {
|
||||
select: { name: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
return {
|
||||
props: { drafts },
|
||||
};
|
||||
};
|
||||
|
||||
type Props = {
|
||||
drafts: PostProps[];
|
||||
};
|
||||
|
||||
const Drafts = (props: Props) => {
|
||||
const { data: session } = useSession();
|
||||
|
||||
if (!session) {
|
||||
return (
|
||||
<Layout>
|
||||
<h1>My Drafts</h1>
|
||||
<div>You need to be authenticated to view this page.</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<div className="page">
|
||||
<h1>My Drafts</h1>
|
||||
<main>
|
||||
{props.drafts.map((post) => (
|
||||
<div key={post.id} className="post">
|
||||
<Post post={post} />
|
||||
</div>
|
||||
))}
|
||||
</main>
|
||||
</div>
|
||||
<style jsx>{`
|
||||
.post {
|
||||
background: white;
|
||||
transition: box-shadow 0.1s ease-in;
|
||||
}
|
||||
|
||||
.post:hover {
|
||||
box-shadow: 1px 1px 3px #aaa;
|
||||
}
|
||||
|
||||
.post + .post {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
`}</style>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Drafts;
|
||||
@@ -1,91 +0,0 @@
|
||||
import React from "react";
|
||||
import { GetServerSideProps } from "next";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import Layout from "../../../components/Layout";
|
||||
import Router from "next/router";
|
||||
import { PostProps } from "../../../components/Post";
|
||||
import prisma from '../../../lib/prisma'
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async ({ params }) => {
|
||||
const post = await prisma.post.findUnique({
|
||||
where: {
|
||||
id: Number(params?.id) || -1,
|
||||
},
|
||||
include: {
|
||||
author: {
|
||||
select: { name: true, email: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
return {
|
||||
props: post,
|
||||
};
|
||||
};
|
||||
|
||||
async function publishPost(id: number): Promise<void> {
|
||||
await fetch(`/api/publish/${id}`, {
|
||||
method: "PUT",
|
||||
});
|
||||
await Router.push("/")
|
||||
}
|
||||
|
||||
async function deletePost(id: number): Promise<void> {
|
||||
await fetch(`/api/post/${id}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
await Router.push("/")
|
||||
}
|
||||
|
||||
const Post = (props: PostProps) => {
|
||||
const { data: session, status } = useSession();
|
||||
if (status === 'loading') {
|
||||
return <div>Authenticating ...</div>;
|
||||
}
|
||||
const userHasValidSession = Boolean(session);
|
||||
const postBelongsToUser = session?.user?.email === props.author?.email;
|
||||
let title = props.title;
|
||||
if (!props.published) {
|
||||
title = `${title} (Draft)`;
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<div>
|
||||
<h2>{title}</h2>
|
||||
<p>By {props?.author?.name || "Unknown author"}</p>
|
||||
<ReactMarkdown children={props.content} />
|
||||
{!props.published && userHasValidSession && postBelongsToUser && (
|
||||
<button onClick={() => publishPost(props.id)}>Publish</button>
|
||||
)}
|
||||
{userHasValidSession && postBelongsToUser && (
|
||||
<button onClick={() => deletePost(props.id)}>Delete</button>
|
||||
)}
|
||||
</div>
|
||||
<style jsx>{`
|
||||
.page {
|
||||
background: white;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.actions {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
button {
|
||||
background: #ececec;
|
||||
border: 0;
|
||||
border-radius: 0.125rem;
|
||||
padding: 1rem 2rem;
|
||||
}
|
||||
|
||||
button + button {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
`}</style>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Post;
|
||||
@@ -1,171 +0,0 @@
|
||||
import React, { useState } from "react";
|
||||
import { GetServerSideProps } from "next";
|
||||
import Layout from "../../components/Layout";
|
||||
import { useSession, getSession } from "next-auth/react";
|
||||
import prisma from '../../lib/prisma'
|
||||
import Router from "next/router";
|
||||
import { ProfileProps } from "../../types/profile";
|
||||
import { Resolver, SubmitHandler } from "react-hook-form";
|
||||
|
||||
|
||||
//https://www.bezkoder.com/react-hook-form-typescript/
|
||||
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import * as Yup from 'yup';
|
||||
|
||||
type UserSubmitForm = {
|
||||
bio: string;
|
||||
};
|
||||
|
||||
type Profil = {
|
||||
isUserProfile: any;
|
||||
}
|
||||
|
||||
interface ResponseData {
|
||||
result: string;
|
||||
message: string
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
|
||||
const session = await getSession({ req });
|
||||
|
||||
//pas de session ? on ne retourne un code erreur
|
||||
//voir pour rediriger vers la page de connection
|
||||
//ou afficher pop up "vous n'est pas connecter"
|
||||
if (!session) {
|
||||
res.statusCode = 403;
|
||||
return { props: { profile: null } };
|
||||
}
|
||||
|
||||
// si session ? on récupére le profil de l'utilisateur si il existe
|
||||
if (session) {
|
||||
const isUserProfile = await prisma.profile.findMany({
|
||||
where: {
|
||||
user: { email: session.user.email },
|
||||
}
|
||||
})
|
||||
console.log('profil utilisateur ?', isUserProfile);
|
||||
|
||||
|
||||
// il n'existe pas ? on le crée
|
||||
if (isUserProfile.length <= 0) {
|
||||
const newProfil = await prisma.profile.create({
|
||||
data: {
|
||||
bio: "",
|
||||
user: {
|
||||
connect: { email: session.user.email },
|
||||
},
|
||||
},
|
||||
});
|
||||
console.log('newProfil', newProfil);
|
||||
|
||||
}
|
||||
|
||||
// on renvoi le profil
|
||||
return { props: { isUserProfile } };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const Profil = ({ isUserProfile }: Profil) => {
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
bio: Yup.string().trim().required("ce champ ne peux etre vide..."),
|
||||
});
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { errors }
|
||||
} = useForm<UserSubmitForm>({
|
||||
resolver: yupResolver(validationSchema)
|
||||
});
|
||||
|
||||
const [response, setResponse] = useState<ResponseData | undefined>();
|
||||
const { data: session } = useSession();
|
||||
|
||||
React.useEffect(() => {
|
||||
console.log('user profil props', isUserProfile)
|
||||
}, [])
|
||||
|
||||
const onSubmit = async (data: UserSubmitForm) => {
|
||||
console.log(data);
|
||||
|
||||
try {
|
||||
const body = { bioValue: data.bio };
|
||||
await fetch(`/api/profile`, {
|
||||
method: "PUT",
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
if (!session) {
|
||||
return (
|
||||
<Layout>
|
||||
<h1>Mon Compte</h1>
|
||||
<div>Vous devez être authentifié pour voir cette page.</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<div className="page">
|
||||
<h1>Mon compte</h1>
|
||||
<main>
|
||||
|
||||
<div className="register-form">
|
||||
<p>Ma bio : {isUserProfile[0]?.bio}</p>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="form-group">
|
||||
<label>Ma bio :</label>
|
||||
<input
|
||||
placeholder="Ma bio..."
|
||||
defaultValue={isUserProfile[0]?.bio}
|
||||
type="text"
|
||||
{...register('bio')}
|
||||
className={`form-control ${errors.bio ? 'is-invalid' : ''}`}
|
||||
/>
|
||||
<div className="invalid-feedback">{errors.bio?.message}</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="form-group">
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Valider les changements
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => reset()}
|
||||
className="btn btn-warning float-right"
|
||||
>
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
<p>Email : {session.user.email}</p>
|
||||
{response && <p>{response.message}</p>}
|
||||
</main>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
export default Profil;
|
||||
+36
-6
@@ -1,6 +1,8 @@
|
||||
import React, { useEffect, useState, useSyncExternalStore } from "react";
|
||||
import prisma from '../lib/prisma'
|
||||
|
||||
import dateFormat, { masks } from "dateformat";
|
||||
|
||||
|
||||
import Image from 'next/image';
|
||||
import * as Yup from 'yup';
|
||||
@@ -14,6 +16,8 @@ import { AiOutlineCheck } from 'react-icons/ai'
|
||||
|
||||
import Router from "next/router";
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
|
||||
import style from '../styles/Connexion.module.css';
|
||||
|
||||
@@ -92,11 +96,14 @@ const Admin = (props: Props) => {
|
||||
const [response, setResponse] = useState(null)
|
||||
const [currentUser, setCurrentUser] = useState(null)
|
||||
const [users, setUsers] = useState(props.users)
|
||||
const [currentUserGain, setCurrentUserGain] = useState(null)
|
||||
const router = useRouter()
|
||||
|
||||
|
||||
const { register, setValue, handleSubmit, formState: { errors } } = useForm<FormData>({
|
||||
});
|
||||
|
||||
const fetcher = async (url, method, body = {}) => {
|
||||
const fetcher = async (url, method, body = {}, callback?: any) => {
|
||||
try {
|
||||
await fetch(url, {
|
||||
method,
|
||||
@@ -106,7 +113,7 @@ const Admin = (props: Props) => {
|
||||
.then((res) => res.json())
|
||||
.then(async (data) => {
|
||||
setResponse(data);
|
||||
setUsers(data.res)
|
||||
callback;
|
||||
if (data.err) {
|
||||
toast.error(data.err, {
|
||||
position: "top-center",
|
||||
@@ -178,8 +185,10 @@ const Admin = (props: Props) => {
|
||||
fetcher('/api/user/delete', 'DELETE', body)
|
||||
};
|
||||
|
||||
const selectUser = (user: User) => {
|
||||
const selectUser = (user: any) => {
|
||||
console.log('d', user.gains)
|
||||
setCurrentUser(user);
|
||||
setCurrentUserGain(user.gains)
|
||||
setValue("name", user.name)
|
||||
setValue("email", user.email)
|
||||
setValue("surname", user.surname)
|
||||
@@ -188,6 +197,26 @@ const Admin = (props: Props) => {
|
||||
setValue("phoneNumber", user.phoneNumber)
|
||||
}
|
||||
|
||||
const changeGiftStatus = async (gain: Gain) => {
|
||||
const body = { gain }
|
||||
fetcher('/api/user/update-gift', 'PUT', body)
|
||||
console.log('g', gain);
|
||||
|
||||
setCurrentUserGain(gain)
|
||||
// router.refresh();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
@@ -217,6 +246,7 @@ const Admin = (props: Props) => {
|
||||
</thead>
|
||||
<tbody>
|
||||
{users.map((info: User, index: number) => {
|
||||
|
||||
return <tr key={index} className={`${style.cursor}`} onClick={() => selectUser(info)}>
|
||||
<th scope="row">{++index}</th>
|
||||
<td>{info.surname}</td>
|
||||
@@ -320,19 +350,19 @@ const Admin = (props: Props) => {
|
||||
<th scope="col">Codes joués</th>
|
||||
<th scope="col">Cadeaux</th>
|
||||
<th scope="col">Retiré en magasin</th>
|
||||
<th scope="col">Retrait</th>
|
||||
<th scope="col">Date Retrait</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{currentUser?.gains.map((gain: Gain, index: number) => {
|
||||
{currentUserGain.map((gain: Gain, index: number) => {
|
||||
return <tr key={index}>
|
||||
<th scope="row">{++index}</th>
|
||||
<td>{gain?.codeCadeau}</td>
|
||||
<td>{props.produits[gain.produitId - 1].nomProduit}</td>
|
||||
<td>{gain?.retrait ? '❌ déja récupéré' : '✔️ disponible'}</td>
|
||||
<td>{gain?.dateRetrait ? dateFormat(gain?.dateRetrait, "dd/mm/yyyy") : ''}</td>
|
||||
<td>
|
||||
<button className="btn btn-primary">OUI</button>
|
||||
<button className="btn btn-primary" disabled={gain?.retrait} onClick={() => changeGiftStatus(gain)}>OUI</button>
|
||||
</td>
|
||||
</tr>
|
||||
})}
|
||||
|
||||
@@ -6,7 +6,7 @@ import GoogleProvider from "next-auth/providers/google";
|
||||
import EmailProvider from 'next-auth/providers/email'
|
||||
import prisma from '../../../lib/prisma'
|
||||
import { Session } from "@prisma/client";
|
||||
|
||||
import { CustomsendVerificationRequest } from "./signinemail"
|
||||
|
||||
const authHandler: NextApiHandler = (req, res) => NextAuth(req, res, options);
|
||||
export default authHandler;
|
||||
@@ -27,7 +27,10 @@ const options = {
|
||||
pass: process.env.EMAIL_SERVER_PASSWORD
|
||||
}
|
||||
},
|
||||
from: process.env.EMAIL_FROM
|
||||
from: process.env.EMAIL_FROM,
|
||||
sendVerificationRequest({ identifier, url, provider }) {
|
||||
CustomsendVerificationRequest({ identifier, url, provider })
|
||||
}
|
||||
}),
|
||||
],
|
||||
adapter: PrismaAdapter(prisma),
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
// https://craftingemails.com/blog/nextauth-signin-custom-email
|
||||
import { Theme } from "next-auth"
|
||||
import { createTransport } from "nodemailer"
|
||||
|
||||
export async function CustomsendVerificationRequest(params) {
|
||||
const { identifier, url, provider, theme } = params
|
||||
const { host } = new URL(url)
|
||||
// NOTE: You are not required to use `nodemailer`, use whatever you want.
|
||||
const transport = createTransport(provider.server)
|
||||
const result = await transport.sendMail({
|
||||
to: identifier,
|
||||
from: provider.from,
|
||||
subject: `Sign in to ${host}`,
|
||||
text: text({ url, host }),
|
||||
html: html({ url, host, theme }),
|
||||
})
|
||||
const failed = result.rejected.concat(result.pending).filter(Boolean)
|
||||
if (failed.length) {
|
||||
throw new Error(`Email(s) (${failed.join(", ")}) could not be sent`)
|
||||
}
|
||||
}
|
||||
|
||||
function html(params: { url: string; host: string; theme: Theme }) {
|
||||
const { url, host, theme } = params
|
||||
|
||||
const escapedHost = host.replace(/\./g, "​.")
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html lang="fr" xmlns:v="urn:schemas-microsoft-com:vml">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="x-apple-disable-message-reformatting">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="format-detection" content="telephone=no, date=no, address=no, email=no">
|
||||
<meta name="color-scheme" content="light dark">
|
||||
<meta name="supported-color-schemes" content="light dark">
|
||||
<!--[if mso]>
|
||||
<noscript>
|
||||
<xml>
|
||||
<o:OfficeDocumentSettings xmlns:o="urn:schemas-microsoft-com:office:office">
|
||||
<o:PixelsPerInch>96</o:PixelsPerInch>
|
||||
</o:OfficeDocumentSettings>
|
||||
</xml>
|
||||
</noscript>
|
||||
<style>
|
||||
td,th,div,p,a,h1,h2,h3,h4,h5,h6 {font-family: "Segoe UI", sans-serif; mso-line-height-rule: exactly;}
|
||||
</style>
|
||||
<![endif]-->
|
||||
<title>Connection à Thé Tip Top</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet" media="screen">
|
||||
<style>
|
||||
img {
|
||||
max-width: 100%;
|
||||
vertical-align: middle;
|
||||
line-height: 100%;
|
||||
border: 0
|
||||
}
|
||||
.hover-bg-slate-100:hover {
|
||||
background-color: #F7F8FA !important
|
||||
}
|
||||
.hover-bg-primary-600:hover {
|
||||
background-color: #006600e6 !important
|
||||
}
|
||||
.hover-text-slate-600:hover {
|
||||
color: #585E83 !important
|
||||
}
|
||||
.hover-text-primary-600:hover {
|
||||
color: #003CDF !important
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.dark-bg-gray-800 {
|
||||
background-color: #1E1E1E !important
|
||||
}
|
||||
.dark-bg-gray-900 {
|
||||
background-color: #121212 !important
|
||||
}
|
||||
.dark-bg-gray-50 {
|
||||
background-color: #f9fafb !important
|
||||
}
|
||||
.dark-bg-gray-600 {
|
||||
background-color: #272727 !important
|
||||
}
|
||||
.dark-text-gray-200 {
|
||||
color: #ABABAB !important
|
||||
}
|
||||
.dark-text-gray-50 {
|
||||
color: #f9fafb !important
|
||||
}
|
||||
.dark-text-gray-800 {
|
||||
color: #1E1E1E !important
|
||||
}
|
||||
.dark-text-gray-900 {
|
||||
color: #121212 !important
|
||||
}
|
||||
.dark-text-primary-500 {
|
||||
color: #006600e6 !important
|
||||
}
|
||||
.dark-text-primary-200 {
|
||||
color: #94B5FF !important
|
||||
}
|
||||
.dark-hover-bg-gray-50:hover {
|
||||
background-color: #f9fafb !important
|
||||
}
|
||||
.dark-hover-text-gray-100:hover {
|
||||
color: #D5D5D5 !important
|
||||
}
|
||||
.dark-hover-text-primary-100:hover {
|
||||
color: #C6D9FF !important
|
||||
}
|
||||
}
|
||||
@media (max-width: 648px) {
|
||||
.sm-mt-0 {
|
||||
margin-top: 0 !important
|
||||
}
|
||||
.sm-block {
|
||||
display: block !important
|
||||
}
|
||||
.sm-hidden {
|
||||
display: none !important
|
||||
}
|
||||
.sm-h-px {
|
||||
height: 1px !important
|
||||
}
|
||||
.sm-w-full {
|
||||
width: 100% !important
|
||||
}
|
||||
.sm-py-3 {
|
||||
padding-top: 12px !important;
|
||||
padding-bottom: 12px !important
|
||||
}
|
||||
.sm-px-0 {
|
||||
padding-left: 0 !important;
|
||||
padding-right: 0 !important
|
||||
}
|
||||
.sm-px-6 {
|
||||
padding-left: 24px !important;
|
||||
padding-right: 24px !important
|
||||
}
|
||||
.sm-leading-10 {
|
||||
line-height: 40px !important
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="dark-bg-gray-900" style="margin: 0; width: 100%; padding: 0; word-break: break-word; -webkit-font-smoothing: antialiased; background-color: #F7F8FA">
|
||||
<div style="display: none">
|
||||
Connexion à Thé Tip Top
|
||||
͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏
|
||||
</div>
|
||||
<div role="article" aria-roledescription="email" aria-label="Connexion à Thé Tip Top" lang="fr" style="font-size: 16px; font-size: 1rem; font-size: max(16px, 1rem)">
|
||||
<table style="width: 100%; font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif" cellpadding="0" cellspacing="0" role="presentation">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<!--[if mso]>
|
||||
<v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="height:300px; mso-width-percent: 1000; position: absolute; left: -10px; top: -20px; z-index: -1;">
|
||||
<v:fill type="tile" color="#dee2e9" />
|
||||
<v:textbox inset="0,0,0,0">
|
||||
<![endif]-->
|
||||
<div style="max-height: 40px">
|
||||
<div class="dark-bg-gray-900" style="height: 100vh; background-color: #DEE2E9"></div>
|
||||
</div>
|
||||
<!--[if mso]>
|
||||
</v:textbox>
|
||||
</v:rect>
|
||||
<![endif]-->
|
||||
<table class="sm-w-full" style="position: relative; max-height: 0; width: 568px; opacity: 0.999" cellpadding="0" cellspacing="0" role="presentation">
|
||||
<tr>
|
||||
<td style="vertical-align: top" valign="top">
|
||||
<div class="sm-px-6">
|
||||
<div role="separator" style="line-height: 40px">‌</div>
|
||||
<table class="dark-bg-gray-600" style="width: 100%; border-radius: 8px; background-color: #fff; box-shadow: 0px 10px 10px -5px rgba(0, 0, 0, 0.04), 0px 20px 25px -5px rgba(0, 0, 0, 0.1)" cellpadding="0" cellspacing="0" role="presentation">
|
||||
<tr>
|
||||
<td class="sm-px-6" style="padding: 40px">
|
||||
<table style="width: 100%" cellpadding="0" cellspacing="0" role="presentation">
|
||||
<tr>
|
||||
<td>
|
||||
<h1 class="dark-text-gray-50" style="margin: 0; font-size: 36px; font-weight: 700; line-height: 1; letter-spacing: -0.025em; color: #191847">
|
||||
Connexion à Thé Tip Top
|
||||
</h1>
|
||||
<div role="separator" style="line-height: 24px">
|
||||
‌
|
||||
</div>
|
||||
<p class="dark-text-gray-50" style="margin: 0; font-size: 16px; line-height: 26px; color: #191847">
|
||||
Bonjour,
|
||||
<br>
|
||||
<br>
|
||||
Connectez vous en cliquant sur le bouton ci-dessous.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr role="separator">
|
||||
<td style="line-height: 24px">‌</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center">
|
||||
<a href="${url}" class="sm-block dark-text-primary-500 hover-bg-primary-600 dark-bg-gray-50 dark-hover-bg-gray-50" style="text-decoration: none; display: inline-block; border-radius: 8px; background-color: #006600e6; padding: 14px 24px; text-align: center; font-size: 16px; font-weight: 700; color: #f9fafb; box-shadow: 0px 2px 4px -1px rgba(0, 0, 0, 0.06), 0px 4px 6px -1px rgba(0, 0, 0, 0.1)">
|
||||
<!--[if mso
|
||||
]><i
|
||||
style="
|
||||
letter-spacing: 24px;
|
||||
mso-font-width: -100%;
|
||||
mso-text-raise: 30px;
|
||||
"
|
||||
> </i><!
|
||||
[endif]-->
|
||||
<span style="mso-text-raise: 15px">Se connecter</span>
|
||||
<!--[if mso
|
||||
]><i
|
||||
style="
|
||||
letter-spacing: 24px;
|
||||
mso-font-width: -100%;
|
||||
"
|
||||
> </i><!
|
||||
[endif]-->
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div role="separator" style="line-height: 24px">
|
||||
‌
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>`
|
||||
}
|
||||
|
||||
// Email Text body (fallback for email clients that don't render HTML)
|
||||
function text({ url, host }: { url: string; host: string }) {
|
||||
return `Connectez vous à ${host}\n${url}\n\n`
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import prisma from '../../../lib/prisma';
|
||||
|
||||
|
||||
//api qui va rendre un utilisateur admin (pour les developpeurs)
|
||||
//--> http://localhost:3000/api/superadmin/admin?pass=1234 (a effacer)
|
||||
//--> http://localhost:3000/api/superadmin/make-admin?pass=1234 (a effacer)
|
||||
|
||||
export default async function makeMeAdmin(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { pass } = req.query;
|
||||
@@ -23,7 +23,7 @@ export default async function makeMeAdmin(req: NextApiRequest, res: NextApiRespo
|
||||
role: Role.SUPERADMIN,
|
||||
},
|
||||
})
|
||||
return res.status(200).send({ message: 'Profiled updated welcome SUPERADMIN !' });
|
||||
return res.status(200).send({ message: 'Profiled updated welcome ADMIN !' });
|
||||
} else {
|
||||
res.status(401).send({ message: 'Unauthorized' })
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import prisma from '../../../lib/prisma';
|
||||
import chance from 'chance'
|
||||
import cryptoRandomString from 'crypto-random-string';
|
||||
|
||||
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getSession } from 'next-auth/react';
|
||||
import { Cadeaux } from '../../../enum/cadeaux.enum';
|
||||
import { Role } from '../../../enum/role.enum';
|
||||
import { Gain } from '.prisma/client';
|
||||
|
||||
|
||||
|
||||
//API gain qui va generer un code cadeau qui sera sur la facture du client
|
||||
//On part du principe qu'une 'API caisse'(qu'on ne gere pas) déclenche l'appel à l'API gain
|
||||
|
||||
export default async function updtateGift(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
|
||||
|
||||
const session = await getSession({ req })
|
||||
|
||||
const { gain } = req.body;
|
||||
|
||||
// est-ce la méthode est un POST ou PUT?
|
||||
// if (req.method !== ("POST" || 'PUT')) {
|
||||
// throw new Error(
|
||||
// `The HTTP ${req.method} method is not supported at this route.`
|
||||
// );
|
||||
// }
|
||||
|
||||
// est-ce que utilisateur est connecté ?
|
||||
if (!session) {
|
||||
res.status(401).json({ err: "Vous devez être connecté" });
|
||||
return;
|
||||
}
|
||||
|
||||
//récupération des gain de l'utilisateur et mise à jour
|
||||
const updatedGain: Gain = await prisma.gain.update({
|
||||
where: { id: gain.id },
|
||||
data: {
|
||||
retrait: true,
|
||||
dateRetrait: new Date()
|
||||
},
|
||||
})
|
||||
|
||||
const updatedCurrentUser = await prisma.user.findFirst({
|
||||
where: { id: updatedGain.userId },
|
||||
include: { gains: true }
|
||||
})
|
||||
|
||||
// est-ce que utilisateur est un client classique ? Donc interdit pour lui de faire des updates
|
||||
// A ACTIVER EN PRODUCTION
|
||||
// if (user.role === 'USER') {
|
||||
// res.status(401).json({ err: "Vous n'avez pas l'autorisation" });
|
||||
// return;
|
||||
// }
|
||||
|
||||
////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
res.status(200).send({ message: `Le gain a ont été mis à jour !`, res: updatedCurrentUser });
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -37,8 +37,8 @@ async function main() {
|
||||
console.log(`Created user with id: ${user.id}`)
|
||||
}
|
||||
|
||||
//création de 5 gains
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
//création de gains
|
||||
for (let i = 1; i <= (50); i++) {
|
||||
await generateGains();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
|
After Width: | Height: | Size: 3.6 MiB |
@@ -91,6 +91,7 @@
|
||||
}
|
||||
|
||||
@keyframes blinking {
|
||||
|
||||
0%,
|
||||
50%,
|
||||
100% {
|
||||
@@ -113,7 +114,7 @@
|
||||
|
||||
.aButton {
|
||||
position: relative;
|
||||
z-index: 9992;
|
||||
z-index: 9000;
|
||||
}
|
||||
|
||||
.aButton:after {
|
||||
@@ -276,4 +277,4 @@
|
||||
50% {
|
||||
right: 0;
|
||||
}
|
||||
} */
|
||||
} */
|
||||
@@ -0,0 +1,14 @@
|
||||
// e2e/example.spec.ts
|
||||
|
||||
import { test, expect } from '@playwright/test'
|
||||
|
||||
test('navigate to /contact and check if h1 contains "Contactez nous"', async ({ page }) => {
|
||||
// Start from the index page (the baseURL is set via the webServer in the playwright.config.ts)
|
||||
await page.goto('http://localhost:3000/')
|
||||
// Find an element with the text 'About Page' and click on it
|
||||
await page.click('text=Contactez-nous')
|
||||
// The new URL should be "/about" (baseURL is used there)
|
||||
await expect(page).toHaveURL('http://localhost:3000/contact')
|
||||
// The new page should contain an h1 with "About Page"
|
||||
await expect(page.locator('h1')).toContainText('Contactez nous')
|
||||
})
|
||||
Reference in new issue
Block a user