Skip to content

Commit

Permalink
Merge pull request #47 from La-404-Devinci/dev
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
Kan-A-Pesh authored Mar 5, 2024
2 parents a49ab4a + 90795b1 commit 3ccb9be
Show file tree
Hide file tree
Showing 67 changed files with 8,346 additions and 6,203 deletions.
101 changes: 101 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# pixel-war

La Pixel war est l'évènement organisé par La 404 Devinci dans le cadre de la COVA.

Il s'agit d'une reproduction à échelle réduite et réservé au élèves du Pôle Léonard De Vinci de l'évènement éponyme organisé par Reddit.

## Technologies utilisées

<table>
<thead>
<tr>
<th colspan="2">App</th>
</tr>
</thead>
<tbody>
<tr>
<td>Frontend</td>
<td>ReactJs</td>
</tr>
<tr>
<td>Backend</td>
<td>ExpressJs</td>
</tr>
<tr>
<td>Base de données</td>
<td>Mysql</td>
</tr>
<tr>
<td>Websocket API</td>
<td>Socket.io</td>
</tr>
</tbody>
</table>


<table>
<thead>
<tr>
<th colspan="2">Devops</th>
</tr>
</thead>
<tbody>
<tr>
<td>Setup</td>
<td>Docker</td>
</tr>
<tr>
<td>CI/CD</td>
<td>Github Actions</td>
</tr>
</tbody>
</table>

## Installation

Cette section couvre la configuration à des fins de développement

### Frontend

Depuis la racine du projet :

```sh
cd ./frontend
npm i
npm run dev
```

### Backend

Depuis la racine du projet :

```sh
cd ./backend
npm i
```

Démarrez votre image MySql sur Docker :

```
docker compose up -d
```

Exécutez les migrations de bases de données :

> **Info :** Ne pas oublier de créer un fichier .env, coller le contenu de .env.example et modifier les variables d'environnement liées à la base de données

```
npx prisma migrate dev
```

```
npm i --save-dev prisma@latest
npm i @prisma/client@latest
```

Exécuter l'application :

```
npm run dev
```
22 changes: 11 additions & 11 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ PORT=3000

JWT_SECRET="s3cr3t"

MYSQL_USER="pixelwar"
MYSQL_PASSWORD="pixelwar"
MYSQL_HOST="localhost"
MYSQL_PORT="3336"
MYSQL_DATABASE="pixelwar"

REDIS_USER=""
REDIS_PASSWORD=""
REDIS_HOST="localhost"
REDIS_PORT="3337"
REDIS_DATABASE="0"
DATABASE_URL="mysql://root:root@localhost:3336/pixelwar"

API_URL="http://localhost:3000/api"

EMAIL_HOST="smtp.gmail.com"
EMAIL_PORT="587"
EMAIL_USER="username"
EMAIL_PASS="password"
EMAIL_FROM="[email protected]"

FRONTEND_URL="http://localhost:3000"
40 changes: 20 additions & 20 deletions backend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"env": {
"es2021": true,
"node": true
},
"ignorePatterns": ["node_modules", "dist", "data"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"indent": ["error", 4],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double"],
"semi": ["error", "always"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["warn"]
}
"env": {
"es2021": true,
"node": true
},
"ignorePatterns": ["node_modules", "dist", "data"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"indent": ["error", 4],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double"],
"semi": ["error", "always"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["warn"]
}
}
4 changes: 4 additions & 0 deletions backend/@types/french-badwords-list.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "french-badwords-list" {
const array: string[];
export { array };
}
5 changes: 5 additions & 0 deletions backend/@types/req.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare namespace Express {
export interface Request {
account: Account;
}
}
27 changes: 22 additions & 5 deletions backend/auth/tokenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ const verifyJwtToken = (token: string, targetEmail: string): Token | null => {
*/
const generateAuthorizationToken = (devinciEmail: string): string => {
const authorizationExpiration = 60 * 15; // 15 minutes
return generateJwtToken({ devinciEmail, type: "authorization" }, authorizationExpiration);
return generateJwtToken(
{ devinciEmail, type: "authorization" },
authorizationExpiration
);
};

/**
Expand All @@ -53,7 +56,10 @@ const generateAuthorizationToken = (devinciEmail: string): string => {
*/
const generateAuthenticationToken = (devinciEmail: string): string => {
const authenticationExpiration = 60 * 60 * 24 * 14; // 14 days
return generateJwtToken({ devinciEmail, type: "authentication" }, authenticationExpiration);
return generateJwtToken(
{ devinciEmail, type: "authentication" },
authenticationExpiration
);
};

/**
Expand All @@ -63,7 +69,10 @@ const generateAuthenticationToken = (devinciEmail: string): string => {
* @param targetEmail The email to be verified
* @returns Whether the token is valid
*/
const verifyAuthorizationToken = (token: string, targetEmail: string): boolean => {
const verifyAuthorizationToken = (
token: string,
targetEmail: string
): boolean => {
const decodedToken = verifyJwtToken(token, targetEmail);
if (decodedToken === null) return false;
return decodedToken.type === "authorization";
Expand All @@ -76,10 +85,18 @@ const verifyAuthorizationToken = (token: string, targetEmail: string): boolean =
* @param targetEmail The email to be verified
* @returns Whether the token is valid
*/
const verifyAuthenticationToken = (token: string, targetEmail: string): boolean => {
const verifyAuthenticationToken = (
token: string,
targetEmail: string
): boolean => {
const decodedToken = verifyJwtToken(token, targetEmail);
if (decodedToken === null) return false;
return decodedToken.type === "authentication";
};

export { generateAuthorizationToken, generateAuthenticationToken, verifyAuthorizationToken, verifyAuthenticationToken };
export {
generateAuthorizationToken,
generateAuthenticationToken,
verifyAuthorizationToken,
verifyAuthenticationToken,
};
Loading

0 comments on commit 3ccb9be

Please sign in to comment.