Les routes et les contrôleurs backend pour l'inscription, la connexion et la déconnexion des utilisateurs
This commit is contained in:
parent
37ffb163d7
commit
f4ab9b3d15
52 changed files with 10487 additions and 0 deletions
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
.env
|
||||||
|
node_modules
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
# Docs
|
||||||
|
lismoi.md
|
||||||
|
FeuilledeRoute.md
|
||||||
|
DocumentationExhaustive.md
|
||||||
|
FeuilledeRoute.md
|
108
README.md
108
README.md
|
@ -0,0 +1,108 @@
|
||||||
|
# Wemusic
|
||||||
|
|
||||||
|
**Votre plateforme de centralisation et de développement pour les artistes indépendants.**
|
||||||
|
|
||||||
|
## Fonctionnalités MVP
|
||||||
|
|
||||||
|
* **Profil Artiste :**
|
||||||
|
|
||||||
|
* Nom, photo, bio (courte et longue)
|
||||||
|
* Liens sociaux centralisés
|
||||||
|
* **Générateur de Liens de Partage "Smart" :**
|
||||||
|
|
||||||
|
* Création d'un lien unique pour toutes les plateformes musicales.
|
||||||
|
* **Presse Kit Léger :**
|
||||||
|
|
||||||
|
* Page simple avec bio, photos, liens vers la musique et vidéos.
|
||||||
|
* **Calendrier Simple :**
|
||||||
|
|
||||||
|
* Affichage des concerts et des événements.
|
||||||
|
* **Airbnb de Salles :**
|
||||||
|
|
||||||
|
* Listings de lieux de concert et bars disponibles à la location.
|
||||||
|
* Système de notation/avis.
|
||||||
|
* **Partenaires :**
|
||||||
|
|
||||||
|
* Mise en relation avec des partenaires (studios, prestataires, etc.).
|
||||||
|
* **Authentification et Gestion des Utilisateurs :**
|
||||||
|
|
||||||
|
* Inscription, connexion, gestion de profil.
|
||||||
|
* **Gestion des Œuvres Musicales (Minimale) :**
|
||||||
|
|
||||||
|
* Enregistrement des titres et liens d'écoute (pour alimenter les autres fonctionnalités).
|
||||||
|
|
||||||
|
**Les fonctionnalités liées à la gestion administrative (déclarations, facturation, etc.) seront proposées dans des offres premium ultérieures.**
|
||||||
|
|
||||||
|
## Technologies
|
||||||
|
|
||||||
|
* **Frontend :** Next.js, Tailwind CSS
|
||||||
|
* **Backend :** Node.js
|
||||||
|
* **Base de Données :** PostgreSQL
|
||||||
|
* **Gestion d'État (Frontend) :** Zustand
|
||||||
|
|
||||||
|
## Structure des Données (Provisoire)
|
||||||
|
|
||||||
|
* **Artistes :** Nom, bio, liens sociaux, etc.
|
||||||
|
* **Liens de Partage :** URL unique, liens vers les plateformes.
|
||||||
|
* **Événements de Calendrier :** Date, heure, lieu, description, liens.
|
||||||
|
* **Infos Presse Kit :** Bio, liens, photos, etc.
|
||||||
|
* **Lieux (Airbnb) :** Informations de location, avis.
|
||||||
|
* **Partenaires :** Informations de profil, services offerts.
|
||||||
|
* **Oeuvres Musicales :** Titre, liens d'écoute.
|
||||||
|
|
||||||
|
## Étapes de Développement MVP (Provisoire)
|
||||||
|
|
||||||
|
1. **Infrastructure de Base :**
|
||||||
|
|
||||||
|
* Configuration du projet (Next.js, Node.js, PostgreSQL).
|
||||||
|
* Authentification et gestion des utilisateurs.
|
||||||
|
* Structure de données de base.
|
||||||
|
2. **Profil Artiste et Liens Sociaux :**
|
||||||
|
|
||||||
|
* Interface utilisateur pour le profil.
|
||||||
|
* Gestion des liens sociaux.
|
||||||
|
3. **Générateur de Liens "Smart" :**
|
||||||
|
|
||||||
|
* Interface utilisateur.
|
||||||
|
* Logique de redirection.
|
||||||
|
4. **Presse Kit Léger :**
|
||||||
|
|
||||||
|
* Interface utilisateur.
|
||||||
|
5. **Calendrier Simple :**
|
||||||
|
|
||||||
|
* Interface utilisateur.
|
||||||
|
6. **Airbnb de Salles :**
|
||||||
|
|
||||||
|
* Interface utilisateur.
|
||||||
|
* Système de notation/avis.
|
||||||
|
7. **Gestion Minimale des Œuvres :**
|
||||||
|
|
||||||
|
* Interface utilisateur (pour les besoins du générateur de liens et du press kit).
|
||||||
|
8. **Partenaires :**
|
||||||
|
|
||||||
|
* Interface utilisateur pour la découverte des partenaires.
|
||||||
|
9. **Tests et Déploiement du MVP.**
|
||||||
|
|
||||||
|
## Fonctionnalités des Offres Premium (Futures)
|
||||||
|
|
||||||
|
* **Gestion Administrative :**
|
||||||
|
* Déclarations aux organismes de gestion collective (SPPF, Sacem, Adami, SCPA, etc.).
|
||||||
|
* Facturation.
|
||||||
|
* Suivi des dépenses et revenus.
|
||||||
|
* Calendrier des échéances administratives.
|
||||||
|
* Gestion des contrats.
|
||||||
|
* Rapports financiers.
|
||||||
|
* Support prioritaire.
|
||||||
|
* Fonctionnalités avancées pour les partenaires.
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
Les contributions sont les bienvenues ! Si vous souhaitez participer au développement de Wemusic, veuillez consulter notre [GUIDE_DE_CONTRIBUTION.md](GUIDE_DE_CONTRIBUTION.md).
|
||||||
|
|
||||||
|
## Licence
|
||||||
|
|
||||||
|
[MIT](https://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
|
## Contact
|
||||||
|
|
||||||
|
[AB/WilmoreDynamics] - [contact@wilmoredynamics.com]
|
3
backend/.env.example
Normal file
3
backend/.env.example
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
PORT=3001
|
||||||
|
NODE_ENV=development
|
||||||
|
CORS_ORIGIN=http://localhost:3000
|
25
backend/.gitignore
vendored
Normal file
25
backend/.gitignore
vendored
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
|
||||||
|
# production
|
||||||
|
/dist
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.idea/
|
||||||
|
.vscode/
|
2182
backend/package-lock.json
generated
Normal file
2182
backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
46
backend/package.json
Normal file
46
backend/package.json
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"name": "backend",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Backend API pour WeMusic",
|
||||||
|
"main": "dist/server.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "node dist/server.js",
|
||||||
|
"dev": "nodemon src/server.ts",
|
||||||
|
"build": "tsc",
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"test:db": "ts-node src/scripts/test-db-connection.ts"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"type": "commonjs",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/cookie-parser": "^1.4.8",
|
||||||
|
"@types/express-session": "^1.18.1",
|
||||||
|
"bcrypt": "^6.0.0",
|
||||||
|
"cookie-parser": "^1.4.7",
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"dotenv": "^16.5.0",
|
||||||
|
"express": "^5.1.0",
|
||||||
|
"express-rate-limit": "^7.5.0",
|
||||||
|
"express-session": "^1.18.1",
|
||||||
|
"express-validator": "^7.2.1",
|
||||||
|
"helmet": "^8.1.0",
|
||||||
|
"jsonwebtoken": "^9.0.2",
|
||||||
|
"morgan": "^1.10.0",
|
||||||
|
"pg": "^8.16.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/bcrypt": "^5.0.2",
|
||||||
|
"@types/cors": "^2.8.18",
|
||||||
|
"@types/express": "^5.0.2",
|
||||||
|
"@types/helmet": "^0.0.48",
|
||||||
|
"@types/jsonwebtoken": "^9.0.9",
|
||||||
|
"@types/morgan": "^1.9.9",
|
||||||
|
"@types/node": "^22.15.18",
|
||||||
|
"@types/pg": "^8.15.2",
|
||||||
|
"nodemon": "^3.1.10",
|
||||||
|
"ts-node": "^10.9.2",
|
||||||
|
"typescript": "^5.8.3"
|
||||||
|
}
|
||||||
|
}
|
55
backend/src/config/database.ts
Normal file
55
backend/src/config/database.ts
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
import { Pool, PoolConfig } from 'pg';
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
// Configuration de base de la connexion
|
||||||
|
const poolConfig: PoolConfig = {
|
||||||
|
user: process.env.DB_USER,
|
||||||
|
host: process.env.DB_HOST || '192.168.0.104',
|
||||||
|
database: process.env.DB_NAME || 'wimusic_db',
|
||||||
|
password: process.env.DB_PASSWORD,
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
// Configuration du timeout et des tentatives de reconnexion
|
||||||
|
connectionTimeoutMillis: 5000,
|
||||||
|
idleTimeoutMillis: 30000,
|
||||||
|
max: 20, // nombre maximum de clients dans le pool
|
||||||
|
};
|
||||||
|
|
||||||
|
// Si SSL est requis (recommandé pour la production)
|
||||||
|
if (process.env.DB_SSL === 'true') {
|
||||||
|
poolConfig.ssl = {
|
||||||
|
rejectUnauthorized: false // À modifier selon votre configuration SSL
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Création du pool de connexions
|
||||||
|
const pool = new Pool(poolConfig);
|
||||||
|
|
||||||
|
// Gestion des événements de connexion
|
||||||
|
pool.on('connect', () => {
|
||||||
|
console.log('📦 Connexion établie avec la base de données PostgreSQL');
|
||||||
|
console.log(`📍 Hôte: ${poolConfig.host}`);
|
||||||
|
console.log(`📚 Base de données: ${poolConfig.database}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Gestion des erreurs
|
||||||
|
pool.on('error', (err) => {
|
||||||
|
console.error('❌ Erreur de connexion à la base de données:', err);
|
||||||
|
console.error('⚠️ Vérifiez vos paramètres de connexion et que le serveur est accessible');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fonction pour tester la connexion
|
||||||
|
export const testConnection = async (): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const client = await pool.connect();
|
||||||
|
console.log('✅ Test de connexion réussi');
|
||||||
|
client.release();
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Test de connexion échoué:', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default pool;
|
20
backend/src/config/db.ts
Normal file
20
backend/src/config/db.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { Pool } from 'pg';
|
||||||
|
|
||||||
|
// Configuration du pool de connexion PostgreSQL
|
||||||
|
export const pool = new Pool({
|
||||||
|
user: process.env.DB_USER || 'postgres',
|
||||||
|
host: process.env.DB_HOST || 'localhost',
|
||||||
|
database: process.env.DB_NAME || 'wemusic',
|
||||||
|
password: process.env.DB_PASSWORD || 'postgres',
|
||||||
|
port: parseInt(process.env.DB_PORT || '5432'),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test de connexion
|
||||||
|
pool.connect((err, client, release) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('🔥 Erreur de connexion à la base de données:', err.stack);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('✅ Connexion à la base de données établie avec succès');
|
||||||
|
release();
|
||||||
|
});
|
198
backend/src/controllers/auth.controller.ts
Normal file
198
backend/src/controllers/auth.controller.ts
Normal file
|
@ -0,0 +1,198 @@
|
||||||
|
import { Request, Response, NextFunction } from 'express';
|
||||||
|
import { validationResult } from 'express-validator';
|
||||||
|
import bcrypt from 'bcrypt';
|
||||||
|
import jwt from 'jsonwebtoken';
|
||||||
|
import { Pool } from 'pg';
|
||||||
|
import pool from '../config/database';
|
||||||
|
import { AppError } from '../middleware/error.middleware';
|
||||||
|
import { UserRegistrationData, UserResponse } from '../types/user.types';
|
||||||
|
import 'express-session';
|
||||||
|
|
||||||
|
declare module 'express-session' {
|
||||||
|
interface SessionData {
|
||||||
|
userId: string;
|
||||||
|
userEmail: string;
|
||||||
|
userType: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interface pour les données de connexion
|
||||||
|
interface LoginData {
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interface pour l'utilisateur en base de données
|
||||||
|
interface DBUser {
|
||||||
|
id: number;
|
||||||
|
email: string;
|
||||||
|
password_hash: string;
|
||||||
|
artist_name: string;
|
||||||
|
user_type: string;
|
||||||
|
bio_short?: string;
|
||||||
|
bio_long?: string;
|
||||||
|
profile_picture_url?: string;
|
||||||
|
created_at: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const register = async (req: Request, res: Response): Promise<void> => {
|
||||||
|
try {
|
||||||
|
// Validation des données
|
||||||
|
const errors = validationResult(req);
|
||||||
|
if (!errors.isEmpty()) {
|
||||||
|
res.status(400).json({ errors: errors.array() });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { email, password, artist_name, user_type = 'artist', bio_short, bio_long }: UserRegistrationData = req.body;
|
||||||
|
|
||||||
|
// Vérification si l'email existe déjà
|
||||||
|
const existingUser = await pool.query(
|
||||||
|
'SELECT id FROM users WHERE email = $1',
|
||||||
|
[email]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (existingUser.rows.length > 0) {
|
||||||
|
res.status(409).json({
|
||||||
|
error: 'Un utilisateur avec cette adresse email existe déjà'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hachage du mot de passe
|
||||||
|
const saltRounds = 12;
|
||||||
|
const password_hash = await bcrypt.hash(password, saltRounds);
|
||||||
|
|
||||||
|
// Insertion du nouvel utilisateur
|
||||||
|
const result = await pool.query(
|
||||||
|
`INSERT INTO users (
|
||||||
|
email,
|
||||||
|
password_hash,
|
||||||
|
artist_name,
|
||||||
|
user_type,
|
||||||
|
bio_short,
|
||||||
|
bio_long
|
||||||
|
) VALUES ($1, $2, $3, $4, $5, $6)
|
||||||
|
RETURNING id, email, artist_name, user_type, bio_short, bio_long, profile_picture_url, created_at`,
|
||||||
|
[email, password_hash, artist_name, user_type, bio_short, bio_long]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Construction de la réponse
|
||||||
|
const user: UserResponse = result.rows[0];
|
||||||
|
|
||||||
|
// Envoi de la réponse
|
||||||
|
res.status(201).json({
|
||||||
|
message: 'Inscription réussie',
|
||||||
|
user
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur lors de l\'inscription:', error);
|
||||||
|
res.status(500).json({
|
||||||
|
error: 'Une erreur est survenue lors de l\'inscription'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrôleur pour la connexion d'un utilisateur
|
||||||
|
* @route POST /api/auth/login
|
||||||
|
*/
|
||||||
|
export const login = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
|
||||||
|
try {
|
||||||
|
// Validation des données
|
||||||
|
const errors = validationResult(req);
|
||||||
|
if (!errors.isEmpty()) {
|
||||||
|
throw new AppError(400, 'Données de connexion invalides', errors.array());
|
||||||
|
}
|
||||||
|
|
||||||
|
const { email, password } = req.body;
|
||||||
|
|
||||||
|
// Recherche de l'utilisateur dans la base de données
|
||||||
|
const result = await pool.query<DBUser>(
|
||||||
|
'SELECT * FROM users WHERE email = $1',
|
||||||
|
[email]
|
||||||
|
);
|
||||||
|
|
||||||
|
const user = result.rows[0];
|
||||||
|
|
||||||
|
// Vérification si l'utilisateur existe
|
||||||
|
if (!user) {
|
||||||
|
throw new AppError(401, 'Email ou mot de passe incorrect');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérification du mot de passe
|
||||||
|
const isPasswordValid = await bcrypt.compare(password, user.password_hash);
|
||||||
|
if (!isPasswordValid) {
|
||||||
|
throw new AppError(401, 'Email ou mot de passe incorrect');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Création de la session
|
||||||
|
req.session.userId = user.id.toString();
|
||||||
|
req.session.userEmail = user.email;
|
||||||
|
req.session.userType = user.user_type;
|
||||||
|
|
||||||
|
// Création du token JWT pour une double sécurité
|
||||||
|
const token = jwt.sign(
|
||||||
|
{
|
||||||
|
userId: user.id,
|
||||||
|
email: user.email,
|
||||||
|
userType: user.user_type
|
||||||
|
},
|
||||||
|
process.env.JWT_SECRET || 'votre_secret_par_defaut',
|
||||||
|
{ expiresIn: '24h' }
|
||||||
|
);
|
||||||
|
|
||||||
|
// Suppression du mot de passe avant d'envoyer la réponse
|
||||||
|
const { password_hash, ...userWithoutPassword } = user;
|
||||||
|
|
||||||
|
// Envoi de la réponse
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
message: 'Connexion réussie',
|
||||||
|
token,
|
||||||
|
user: userWithoutPassword
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contrôleur pour la déconnexion d'un utilisateur
|
||||||
|
* @route POST /api/auth/logout
|
||||||
|
*/
|
||||||
|
export const logout = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
|
||||||
|
try {
|
||||||
|
if (req.session) {
|
||||||
|
// Destruction de la session
|
||||||
|
req.session.destroy((err) => {
|
||||||
|
if (err) {
|
||||||
|
throw new AppError(500, 'Erreur lors de la déconnexion');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Suppression du cookie de session
|
||||||
|
res.clearCookie('wemusic.sid', {
|
||||||
|
path: '/',
|
||||||
|
httpOnly: true,
|
||||||
|
secure: process.env.NODE_ENV === 'production',
|
||||||
|
sameSite: process.env.NODE_ENV === 'production' ? ('strict' as const) : ('lax' as const)
|
||||||
|
});
|
||||||
|
|
||||||
|
// Envoi de la réponse
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
message: 'Déconnexion réussie'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
message: 'Déjà déconnecté'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
68
backend/src/db/examples/user_queries.sql
Normal file
68
backend/src/db/examples/user_queries.sql
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
-- ⚠️ ATTENTION : Ces exemples sont uniquement à des fins de démonstration
|
||||||
|
-- En production, utilisez TOUJOURS une bibliothèque comme bcrypt pour le hachage des mots de passe
|
||||||
|
|
||||||
|
-- 1. Insertion d'un nouvel utilisateur
|
||||||
|
-- ⚠️ N'utilisez JAMAIS MD5 pour le hachage des mots de passe en production !
|
||||||
|
INSERT INTO users (
|
||||||
|
email,
|
||||||
|
password_hash,
|
||||||
|
artist_name,
|
||||||
|
user_type,
|
||||||
|
bio_short,
|
||||||
|
bio_long
|
||||||
|
) VALUES (
|
||||||
|
'artiste@example.com',
|
||||||
|
-- Ceci est un exemple NON SÉCURISÉ. Utilisez bcrypt en production !
|
||||||
|
md5('motdepasse123'),
|
||||||
|
'Artiste Exemple',
|
||||||
|
'artist',
|
||||||
|
'Musicien indie rock basé à Paris',
|
||||||
|
'Artiste indie rock avec plus de 10 ans d''expérience...'
|
||||||
|
) RETURNING id, email, artist_name, created_at;
|
||||||
|
|
||||||
|
-- 2. Sélection d'un utilisateur par email
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
email,
|
||||||
|
artist_name,
|
||||||
|
user_type,
|
||||||
|
bio_short,
|
||||||
|
profile_picture_url,
|
||||||
|
created_at
|
||||||
|
FROM users
|
||||||
|
WHERE email = 'artiste@example.com';
|
||||||
|
|
||||||
|
-- 3. Mise à jour de la photo de profil
|
||||||
|
UPDATE users
|
||||||
|
SET profile_picture_url = 'https://example.com/photos/profile123.jpg'
|
||||||
|
WHERE email = 'artiste@example.com'
|
||||||
|
RETURNING id, email, artist_name, profile_picture_url;
|
||||||
|
|
||||||
|
-- 4. Recherche d'utilisateurs par type
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
artist_name,
|
||||||
|
email,
|
||||||
|
user_type,
|
||||||
|
created_at
|
||||||
|
FROM users
|
||||||
|
WHERE user_type = 'artist'
|
||||||
|
ORDER BY created_at DESC;
|
||||||
|
|
||||||
|
-- 5. Suppression d'un utilisateur
|
||||||
|
-- ⚠️ En production, préférez une suppression logique avec un champ 'deleted_at'
|
||||||
|
DELETE FROM users
|
||||||
|
WHERE email = 'artiste@example.com'
|
||||||
|
RETURNING id, email, artist_name;
|
||||||
|
|
||||||
|
-- Exemple de requête pour vérifier l'authentification
|
||||||
|
-- ⚠️ Encore une fois, n'utilisez JAMAIS MD5 en production !
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
email,
|
||||||
|
artist_name,
|
||||||
|
user_type
|
||||||
|
FROM users
|
||||||
|
WHERE
|
||||||
|
email = 'artiste@example.com'
|
||||||
|
AND password_hash = md5('motdepasse123');
|
61
backend/src/db/migrations/001_create_users_table.sql
Normal file
61
backend/src/db/migrations/001_create_users_table.sql
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
-- Création du type ENUM pour user_type
|
||||||
|
CREATE TYPE user_type AS ENUM ('artist', 'venue_owner', 'partner', 'admin');
|
||||||
|
|
||||||
|
-- Création de l'extension uuid-ossp si elle n'existe pas
|
||||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||||
|
|
||||||
|
-- Création de la table users
|
||||||
|
CREATE TABLE users (
|
||||||
|
-- Identifiant unique de l'utilisateur
|
||||||
|
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
|
||||||
|
|
||||||
|
-- Informations d'authentification
|
||||||
|
email TEXT NOT NULL UNIQUE,
|
||||||
|
password_hash TEXT NOT NULL,
|
||||||
|
|
||||||
|
-- Informations de profil
|
||||||
|
artist_name TEXT NOT NULL,
|
||||||
|
user_type user_type NOT NULL DEFAULT 'artist',
|
||||||
|
|
||||||
|
-- Champs de biographie
|
||||||
|
bio_short TEXT,
|
||||||
|
bio_long TEXT,
|
||||||
|
|
||||||
|
-- URL de la photo de profil
|
||||||
|
profile_picture_url TEXT,
|
||||||
|
|
||||||
|
-- Horodatage
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Création d'un index sur l'email pour optimiser les recherches
|
||||||
|
CREATE INDEX idx_users_email ON users(email);
|
||||||
|
|
||||||
|
-- Fonction pour mettre à jour automatiquement updated_at
|
||||||
|
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
||||||
|
RETURNS TRIGGER AS $$
|
||||||
|
BEGIN
|
||||||
|
NEW.updated_at = CURRENT_TIMESTAMP;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ language 'plpgsql';
|
||||||
|
|
||||||
|
-- Trigger pour mettre à jour automatiquement updated_at
|
||||||
|
CREATE TRIGGER update_users_updated_at
|
||||||
|
BEFORE UPDATE ON users
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION update_updated_at_column();
|
||||||
|
|
||||||
|
-- Commentaires sur la table et les colonnes
|
||||||
|
COMMENT ON TABLE users IS 'Table stockant les informations des utilisateurs de WeMusic';
|
||||||
|
COMMENT ON COLUMN users.id IS 'Identifiant unique de l''utilisateur';
|
||||||
|
COMMENT ON COLUMN users.email IS 'Adresse email unique de l''utilisateur, utilisée pour l''authentification';
|
||||||
|
COMMENT ON COLUMN users.password_hash IS 'Hash du mot de passe de l''utilisateur (à générer avec bcrypt)';
|
||||||
|
COMMENT ON COLUMN users.artist_name IS 'Nom d''artiste ou nom d''utilisateur';
|
||||||
|
COMMENT ON COLUMN users.user_type IS 'Type d''utilisateur (artist, venue_owner, partner, admin)';
|
||||||
|
COMMENT ON COLUMN users.bio_short IS 'Courte biographie de l''utilisateur';
|
||||||
|
COMMENT ON COLUMN users.bio_long IS 'Biographie détaillée de l''utilisateur';
|
||||||
|
COMMENT ON COLUMN users.profile_picture_url IS 'URL de la photo de profil';
|
||||||
|
COMMENT ON COLUMN users.created_at IS 'Date et heure de création du compte';
|
||||||
|
COMMENT ON COLUMN users.updated_at IS 'Date et heure de la dernière modification du compte';
|
39
backend/src/examples/api-test.sh
Executable file
39
backend/src/examples/api-test.sh
Executable file
|
@ -0,0 +1,39 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Couleurs pour le terminal
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
# Configuration
|
||||||
|
API_URL="http://192.168.0.90:3001"
|
||||||
|
|
||||||
|
echo "🔍 Test des routes d'API..."
|
||||||
|
|
||||||
|
# Test de la route racine de l'API
|
||||||
|
echo -e "\n${GREEN}1. Test de la route /api :${NC}"
|
||||||
|
curl -X GET "${API_URL}/api"
|
||||||
|
|
||||||
|
# Test de la route d'inscription
|
||||||
|
echo -e "\n\n${GREEN}2. Test de la route /api/auth/register :${NC}"
|
||||||
|
curl -X POST "${API_URL}/api/auth/register" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "Password123!",
|
||||||
|
"artist_name": "Test Artist",
|
||||||
|
"user_type": "artist",
|
||||||
|
"bio_short": "Test bio",
|
||||||
|
"bio_long": "Test biography long version"
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Test de la route de connexion
|
||||||
|
echo -e "\n\n${GREEN}3. Test de la route /api/auth/login :${NC}"
|
||||||
|
curl -X POST "${API_URL}/api/auth/login" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "test@example.com",
|
||||||
|
"password": "Password123!"
|
||||||
|
}'
|
||||||
|
|
||||||
|
echo -e "\n\n${GREEN}Tests terminés !${NC}"
|
48
backend/src/examples/login-test.sh
Executable file
48
backend/src/examples/login-test.sh
Executable file
|
@ -0,0 +1,48 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Couleurs pour le terminal
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
# Configuration de l'API
|
||||||
|
API_URL="http://192.168.0.90:3001"
|
||||||
|
|
||||||
|
echo "🔍 Test de connexion d'un utilisateur..."
|
||||||
|
|
||||||
|
# Test avec des données valides
|
||||||
|
echo -e "\n${GREEN}1. Test avec des données valides :${NC}"
|
||||||
|
curl -X POST "${API_URL}/api/auth/login" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "artiste@example.com",
|
||||||
|
"password": "MonMotDePasse123!"
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Test avec un email invalide
|
||||||
|
echo -e "\n\n${GREEN}2. Test avec un email invalide :${NC}"
|
||||||
|
curl -X POST "${API_URL}/api/auth/login" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "email_invalide",
|
||||||
|
"password": "MonMotDePasse123!"
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Test avec un mot de passe incorrect
|
||||||
|
echo -e "\n\n${GREEN}3. Test avec un mot de passe incorrect :${NC}"
|
||||||
|
curl -X POST "${API_URL}/api/auth/login" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "artiste@example.com",
|
||||||
|
"password": "MauvaisMotDePasse123!"
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Test avec des champs manquants
|
||||||
|
echo -e "\n\n${GREEN}4. Test avec des champs manquants :${NC}"
|
||||||
|
curl -X POST "${API_URL}/api/auth/login" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "artiste@example.com"
|
||||||
|
}'
|
||||||
|
|
||||||
|
echo -e "\n\n${GREEN}Tests terminés !${NC}"
|
54
backend/src/examples/register-test.sh
Executable file
54
backend/src/examples/register-test.sh
Executable file
|
@ -0,0 +1,54 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Couleurs pour le terminal
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
echo "🔍 Test d'inscription d'un nouvel utilisateur..."
|
||||||
|
|
||||||
|
# Test avec des données valides
|
||||||
|
echo -e "\n${GREEN}1. Test avec des données valides :${NC}"
|
||||||
|
curl -X POST http://localhost:3001/api/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "artiste@example.com",
|
||||||
|
"password": "MonMotDePasse123!",
|
||||||
|
"artist_name": "John Doe",
|
||||||
|
"user_type": "artist",
|
||||||
|
"bio_short": "Musicien indie rock",
|
||||||
|
"bio_long": "Musicien indie rock avec plus de 10 ans d'\''expérience..."
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Test avec un email invalide
|
||||||
|
echo -e "\n\n${GREEN}2. Test avec un email invalide :${NC}"
|
||||||
|
curl -X POST http://localhost:3001/api/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "email_invalide",
|
||||||
|
"password": "MonMotDePasse123!",
|
||||||
|
"artist_name": "John Doe"
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Test avec un mot de passe trop court
|
||||||
|
echo -e "\n\n${GREEN}3. Test avec un mot de passe trop court :${NC}"
|
||||||
|
curl -X POST http://localhost:3001/api/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "artiste@example.com",
|
||||||
|
"password": "court",
|
||||||
|
"artist_name": "John Doe"
|
||||||
|
}'
|
||||||
|
|
||||||
|
# Test avec un type d'utilisateur invalide
|
||||||
|
echo -e "\n\n${GREEN}4. Test avec un type d'utilisateur invalide :${NC}"
|
||||||
|
curl -X POST http://localhost:3001/api/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "artiste@example.com",
|
||||||
|
"password": "MonMotDePasse123!",
|
||||||
|
"artist_name": "John Doe",
|
||||||
|
"user_type": "invalid_type"
|
||||||
|
}'
|
||||||
|
|
||||||
|
echo -e "\n\n${GREEN}Tests terminés !${NC}"
|
13
backend/src/examples/register.curl.sh
Normal file
13
backend/src/examples/register.curl.sh
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Test d'inscription d'un nouvel utilisateur
|
||||||
|
curl -X POST http://localhost:3001/api/auth/register \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{
|
||||||
|
"email": "artiste@example.com",
|
||||||
|
"password": "MonMotDePasse123!",
|
||||||
|
"artist_name": "John Doe",
|
||||||
|
"user_type": "artist",
|
||||||
|
"bio_short": "Musicien indie rock",
|
||||||
|
"bio_long": "Musicien indie rock avec plus de 10 ans d'\''expérience..."
|
||||||
|
}'
|
24
backend/src/middleware/auth.middleware.ts
Normal file
24
backend/src/middleware/auth.middleware.ts
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { Request, Response, NextFunction } from 'express';
|
||||||
|
import { AppError } from './error.middleware';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Middleware pour vérifier si l'utilisateur est authentifié
|
||||||
|
*/
|
||||||
|
export const isAuthenticated = (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
if (!req.session.userId) {
|
||||||
|
throw new AppError(401, 'Non authentifié');
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Middleware pour vérifier le type d'utilisateur
|
||||||
|
*/
|
||||||
|
export const checkUserType = (allowedTypes: string[]) => {
|
||||||
|
return (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
if (!req.session.userType || !allowedTypes.includes(req.session.userType)) {
|
||||||
|
throw new AppError(403, 'Accès non autorisé');
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
};
|
36
backend/src/middleware/error.middleware.ts
Normal file
36
backend/src/middleware/error.middleware.ts
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import { Request, Response, NextFunction } from 'express';
|
||||||
|
|
||||||
|
export class AppError extends Error {
|
||||||
|
constructor(
|
||||||
|
public statusCode: number,
|
||||||
|
public message: string,
|
||||||
|
public errors?: any[]
|
||||||
|
) {
|
||||||
|
super(message);
|
||||||
|
this.name = 'AppError';
|
||||||
|
Error.captureStackTrace(this, this.constructor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const errorHandler = (
|
||||||
|
err: Error | AppError,
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Response => {
|
||||||
|
console.error('🔥 Erreur:', err);
|
||||||
|
|
||||||
|
if (err instanceof AppError) {
|
||||||
|
return res.status(err.statusCode).json({
|
||||||
|
success: false,
|
||||||
|
message: err.message,
|
||||||
|
errors: err.errors
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erreur par défaut
|
||||||
|
return res.status(500).json({
|
||||||
|
success: false,
|
||||||
|
message: 'Une erreur interne est survenue'
|
||||||
|
});
|
||||||
|
};
|
41
backend/src/middleware/security.middleware.ts
Normal file
41
backend/src/middleware/security.middleware.ts
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import { Request, Response, NextFunction } from 'express';
|
||||||
|
import helmet from 'helmet';
|
||||||
|
import rateLimit from 'express-rate-limit';
|
||||||
|
|
||||||
|
// Configuration du rate limiter
|
||||||
|
export const limiter = rateLimit({
|
||||||
|
windowMs: 15 * 60 * 1000, // 15 minutes
|
||||||
|
max: 100, // limite chaque IP à 100 requêtes par fenêtre
|
||||||
|
message: 'Trop de requêtes depuis cette IP, veuillez réessayer plus tard'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Configuration spécifique pour les routes d'authentification
|
||||||
|
export const authLimiter = rateLimit({
|
||||||
|
windowMs: 60 * 60 * 1000, // 1 heure
|
||||||
|
max: 5, // limite chaque IP à 5 tentatives par heure
|
||||||
|
message: 'Trop de tentatives de connexion, veuillez réessayer plus tard'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Middleware de sécurité
|
||||||
|
export const securityMiddleware = [
|
||||||
|
helmet(), // Sécurité des en-têtes HTTP
|
||||||
|
helmet.hidePoweredBy(), // Cache le header X-Powered-By
|
||||||
|
helmet.noSniff(), // Empêche le MIME-type sniffing
|
||||||
|
helmet.xssFilter(), // Protection XSS basique
|
||||||
|
];
|
||||||
|
|
||||||
|
// Middleware de validation du contenu JSON
|
||||||
|
export const validateJson = (
|
||||||
|
err: Error,
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Response | void => {
|
||||||
|
if (err instanceof SyntaxError && 'body' in err) {
|
||||||
|
return res.status(400).json({
|
||||||
|
success: false,
|
||||||
|
message: 'JSON invalide dans la requête'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
};
|
20
backend/src/routes/auth.routes.ts
Normal file
20
backend/src/routes/auth.routes.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { Router } from 'express';
|
||||||
|
import { register, login } from '../controllers/auth.controller';
|
||||||
|
import { registerValidator, loginValidator } from '../validators/auth.validator';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @route POST /api/auth/register
|
||||||
|
* @desc Inscription d'un nouvel utilisateur
|
||||||
|
* @access Public
|
||||||
|
*/
|
||||||
|
router.post('/register', registerValidator, register);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @route POST /api/auth/login
|
||||||
|
* @desc Connexion d'un utilisateur existant
|
||||||
|
*/
|
||||||
|
router.post('/login', loginValidator, login);
|
||||||
|
|
||||||
|
export default router;
|
12
backend/src/routes/test.routes.ts
Normal file
12
backend/src/routes/test.routes.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { Router } from 'express';
|
||||||
|
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
router.get('/test', (req, res) => {
|
||||||
|
res.json({
|
||||||
|
message: 'Connexion backend réussie !',
|
||||||
|
timestamp: new Date().toISOString()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
18
backend/src/scripts/test-db-connection.ts
Normal file
18
backend/src/scripts/test-db-connection.ts
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
import { testConnection } from '../config/database';
|
||||||
|
|
||||||
|
console.log('🔍 Test de connexion à la base de données...');
|
||||||
|
|
||||||
|
testConnection()
|
||||||
|
.then(success => {
|
||||||
|
if (success) {
|
||||||
|
console.log('✨ La connexion à la base de données est fonctionnelle');
|
||||||
|
process.exit(0);
|
||||||
|
} else {
|
||||||
|
console.error('❌ Échec de la connexion à la base de données');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('💥 Erreur lors du test de connexion:', error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
124
backend/src/server.ts
Normal file
124
backend/src/server.ts
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
import express, { Response as ExpressResponse } from 'express';
|
||||||
|
import cors from 'cors';
|
||||||
|
import morgan from 'morgan';
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
import session from 'express-session';
|
||||||
|
import cookieParser from 'cookie-parser';
|
||||||
|
import crypto from 'crypto';
|
||||||
|
import authRoutes from './routes/auth.routes';
|
||||||
|
import { errorHandler, AppError } from './middleware/error.middleware';
|
||||||
|
import {
|
||||||
|
limiter,
|
||||||
|
authLimiter,
|
||||||
|
securityMiddleware,
|
||||||
|
validateJson
|
||||||
|
} from './middleware/security.middleware';
|
||||||
|
|
||||||
|
// Configuration des variables d'environnement
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
const app = express();
|
||||||
|
const port = process.env.PORT || 3001;
|
||||||
|
const nodeEnv = process.env.NODE_ENV || 'development';
|
||||||
|
const isProduction = nodeEnv === 'production';
|
||||||
|
|
||||||
|
// Génération d'un secret de session aléatoire si non défini
|
||||||
|
if (!process.env.SESSION_SECRET) {
|
||||||
|
process.env.SESSION_SECRET = crypto.randomBytes(32).toString('hex');
|
||||||
|
console.warn('⚠️ Attention : SESSION_SECRET non défini dans les variables d\'environnement.');
|
||||||
|
console.warn('🔑 Un secret temporaire a été généré pour cette session.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Middlewares de sécurité
|
||||||
|
app.use(securityMiddleware);
|
||||||
|
app.use(limiter);
|
||||||
|
|
||||||
|
// Configuration CORS avec support des cookies
|
||||||
|
app.use(cors({
|
||||||
|
origin: process.env.CORS_ORIGIN || 'http://localhost:3000',
|
||||||
|
credentials: true,
|
||||||
|
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
||||||
|
allowedHeaders: ['Content-Type', 'Authorization']
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Configuration des cookies et sessions
|
||||||
|
app.use(cookieParser());
|
||||||
|
|
||||||
|
// Configuration de la session
|
||||||
|
const sessionConfig = {
|
||||||
|
secret: process.env.SESSION_SECRET!,
|
||||||
|
name: 'wemusic.sid', // Pour masquer l'utilisation d'express-session
|
||||||
|
resave: false,
|
||||||
|
saveUninitialized: false,
|
||||||
|
rolling: true, // Renouvelle le cookie à chaque requête
|
||||||
|
cookie: {
|
||||||
|
secure: isProduction,
|
||||||
|
httpOnly: true,
|
||||||
|
maxAge: 60 * 60 * 1000, // 1 heure
|
||||||
|
sameSite: isProduction ? ('strict' as const) : ('lax' as const),
|
||||||
|
path: '/',
|
||||||
|
domain: undefined // Le domaine sera automatiquement défini normalement
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Avertissement en développement pour le cookie non sécurisé
|
||||||
|
if (!isProduction) {
|
||||||
|
console.warn('⚠️ Mode développement : Cookie secure désactivé');
|
||||||
|
console.warn('🔒 En production, activez HTTPS et secure: true');
|
||||||
|
}
|
||||||
|
|
||||||
|
app.use(session(sessionConfig));
|
||||||
|
|
||||||
|
// Middleware de base
|
||||||
|
app.use(morgan(nodeEnv === 'development' ? 'dev' : 'combined'));
|
||||||
|
app.use(express.json({
|
||||||
|
verify: (req, res: ExpressResponse, buf, encoding) => {
|
||||||
|
try {
|
||||||
|
JSON.parse(buf.toString());
|
||||||
|
} catch (e) {
|
||||||
|
res.status(400).json({ message: 'JSON invalide dans la requête' });
|
||||||
|
throw new Error('JSON invalide');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
|
||||||
|
// Middleware pour renouveler la session
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
if (req.session && req.session.userId) {
|
||||||
|
// Renouvelle la session si l'utilisateur est authentifié
|
||||||
|
req.session.touch();
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Routes d'authentification avec rate limiting
|
||||||
|
app.use('/api/auth', authLimiter, authRoutes);
|
||||||
|
|
||||||
|
// Route de base de l'API
|
||||||
|
app.get('/api', (req, res) => {
|
||||||
|
res.json({
|
||||||
|
message: 'Bienvenue sur l\'API WeMusic!',
|
||||||
|
environment: nodeEnv,
|
||||||
|
version: '1.0.0'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Middleware de gestion des erreurs
|
||||||
|
app.use((err: Error | AppError, req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
|
errorHandler(err, req, res, next);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Gestion des routes non trouvées
|
||||||
|
app.use((req, res) => {
|
||||||
|
res.status(404).json({ message: 'Route non trouvée' });
|
||||||
|
});
|
||||||
|
|
||||||
|
// Démarrage du serveur
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`🚀 Serveur ${nodeEnv} démarré sur le port ${port}`);
|
||||||
|
console.log(`👉 CORS activé pour: ${process.env.CORS_ORIGIN || 'http://localhost:3000'}`);
|
||||||
|
if (!isProduction) {
|
||||||
|
console.log('⚙️ Mode développement actif');
|
||||||
|
}
|
||||||
|
});
|
34
backend/src/types/user.types.ts
Normal file
34
backend/src/types/user.types.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
export type UserType = 'artist' | 'venue_owner' | 'partner' | 'admin';
|
||||||
|
|
||||||
|
export interface User {
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
password_hash: string;
|
||||||
|
artist_name: string;
|
||||||
|
user_type: UserType;
|
||||||
|
bio_short?: string;
|
||||||
|
bio_long?: string;
|
||||||
|
profile_picture_url?: string;
|
||||||
|
created_at: Date;
|
||||||
|
updated_at: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserRegistrationData {
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
artist_name: string;
|
||||||
|
user_type?: UserType;
|
||||||
|
bio_short?: string;
|
||||||
|
bio_long?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserResponse {
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
artist_name: string;
|
||||||
|
user_type: UserType;
|
||||||
|
bio_short?: string;
|
||||||
|
bio_long?: string;
|
||||||
|
profile_picture_url?: string;
|
||||||
|
created_at: Date;
|
||||||
|
}
|
20
backend/src/validators/auth.validator.ts
Normal file
20
backend/src/validators/auth.validator.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { body } from 'express-validator';
|
||||||
|
|
||||||
|
export const registerValidator = [
|
||||||
|
// ... existing code ...
|
||||||
|
];
|
||||||
|
|
||||||
|
export const loginValidator = [
|
||||||
|
body('email')
|
||||||
|
.trim()
|
||||||
|
.notEmpty()
|
||||||
|
.withMessage('L\'email est requis')
|
||||||
|
.isEmail()
|
||||||
|
.withMessage('L\'email n\'est pas valide'),
|
||||||
|
|
||||||
|
body('password')
|
||||||
|
.notEmpty()
|
||||||
|
.withMessage('Le mot de passe est requis')
|
||||||
|
.isLength({ min: 8 })
|
||||||
|
.withMessage('Le mot de passe doit contenir au moins 8 caractères')
|
||||||
|
];
|
51
backend/src/validators/auth.validators.ts
Normal file
51
backend/src/validators/auth.validators.ts
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
import { body } from 'express-validator';
|
||||||
|
import { UserType } from '../types/user.types';
|
||||||
|
|
||||||
|
export const registerValidator = [
|
||||||
|
// Email validation
|
||||||
|
body('email')
|
||||||
|
.trim()
|
||||||
|
.isEmail()
|
||||||
|
.withMessage('L\'adresse email n\'est pas valide')
|
||||||
|
.normalizeEmail(),
|
||||||
|
|
||||||
|
// Password validation
|
||||||
|
body('password')
|
||||||
|
.isLength({ min: 8 })
|
||||||
|
.withMessage('Le mot de passe doit contenir au moins 8 caractères')
|
||||||
|
.matches(/[A-Z]/)
|
||||||
|
.withMessage('Le mot de passe doit contenir au moins une majuscule')
|
||||||
|
.matches(/[a-z]/)
|
||||||
|
.withMessage('Le mot de passe doit contenir au moins une minuscule')
|
||||||
|
.matches(/[0-9]/)
|
||||||
|
.withMessage('Le mot de passe doit contenir au moins un chiffre')
|
||||||
|
.matches(/[!@#$%^&*]/)
|
||||||
|
.withMessage('Le mot de passe doit contenir au moins un caractère spécial (!@#$%^&*)'),
|
||||||
|
|
||||||
|
// Artist name validation
|
||||||
|
body('artist_name')
|
||||||
|
.trim()
|
||||||
|
.notEmpty()
|
||||||
|
.withMessage('Le nom d\'artiste est requis')
|
||||||
|
.isLength({ min: 2, max: 100 })
|
||||||
|
.withMessage('Le nom d\'artiste doit contenir entre 2 et 100 caractères'),
|
||||||
|
|
||||||
|
// User type validation
|
||||||
|
body('user_type')
|
||||||
|
.optional()
|
||||||
|
.isIn(['artist', 'venue_owner', 'partner', 'admin'] as UserType[])
|
||||||
|
.withMessage('Le type d\'utilisateur n\'est pas valide'),
|
||||||
|
|
||||||
|
// Bio validations
|
||||||
|
body('bio_short')
|
||||||
|
.optional()
|
||||||
|
.trim()
|
||||||
|
.isLength({ max: 200 })
|
||||||
|
.withMessage('La bio courte ne doit pas dépasser 200 caractères'),
|
||||||
|
|
||||||
|
body('bio_long')
|
||||||
|
.optional()
|
||||||
|
.trim()
|
||||||
|
.isLength({ max: 2000 })
|
||||||
|
.withMessage('La bio longue ne doit pas dépasser 2000 caractères')
|
||||||
|
];
|
21
backend/tsconfig.json
Normal file
21
backend/tsconfig.json
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es2020",
|
||||||
|
"module": "commonjs",
|
||||||
|
"lib": ["es2020"],
|
||||||
|
"outDir": "./dist",
|
||||||
|
"rootDir": "./src",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["src/*"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": ["src/**/*"],
|
||||||
|
"exclude": ["node_modules", "dist"]
|
||||||
|
}
|
1
frontend/.env.local.example
Normal file
1
frontend/.env.local.example
Normal file
|
@ -0,0 +1 @@
|
||||||
|
NEXT_PUBLIC_API_URL=http://localhost/api
|
36
frontend/.gitignore
vendored
Normal file
36
frontend/.gitignore
vendored
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# next.js
|
||||||
|
/.next/
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env*.local
|
||||||
|
.env
|
||||||
|
|
||||||
|
# vercel
|
||||||
|
.vercel
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
next-env.d.ts
|
36
frontend/README.md
Normal file
36
frontend/README.md
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
First, run the development server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
# or
|
||||||
|
yarn dev
|
||||||
|
# or
|
||||||
|
pnpm dev
|
||||||
|
# or
|
||||||
|
bun dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||||
|
|
||||||
|
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||||
|
|
||||||
|
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||||
|
|
||||||
|
## Learn More
|
||||||
|
|
||||||
|
To learn more about Next.js, take a look at the following resources:
|
||||||
|
|
||||||
|
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||||
|
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||||
|
|
||||||
|
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||||
|
|
||||||
|
## Deploy on Vercel
|
||||||
|
|
||||||
|
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||||
|
|
||||||
|
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
16
frontend/eslint.config.mjs
Normal file
16
frontend/eslint.config.mjs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { dirname } from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
import { FlatCompat } from "@eslint/eslintrc";
|
||||||
|
|
||||||
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
const __dirname = dirname(__filename);
|
||||||
|
|
||||||
|
const compat = new FlatCompat({
|
||||||
|
baseDirectory: __dirname,
|
||||||
|
});
|
||||||
|
|
||||||
|
const eslintConfig = [
|
||||||
|
...compat.extends("next/core-web-vitals", "next/typescript"),
|
||||||
|
];
|
||||||
|
|
||||||
|
export default eslintConfig;
|
7
frontend/next.config.ts
Normal file
7
frontend/next.config.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
|
const nextConfig: NextConfig = {
|
||||||
|
/* config options here */
|
||||||
|
};
|
||||||
|
|
||||||
|
export default nextConfig;
|
6160
frontend/package-lock.json
generated
Normal file
6160
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
29
frontend/package.json
Normal file
29
frontend/package.json
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "next dev",
|
||||||
|
"build": "next build",
|
||||||
|
"start": "next start",
|
||||||
|
"lint": "next lint"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"axios": "^1.9.0",
|
||||||
|
"next": "15.3.2",
|
||||||
|
"react": "^19.0.0",
|
||||||
|
"react-dom": "^19.0.0",
|
||||||
|
"zustand": "^5.0.4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/eslintrc": "^3",
|
||||||
|
"@tailwindcss/postcss": "^4",
|
||||||
|
"@types/node": "^20",
|
||||||
|
"@types/react": "^19",
|
||||||
|
"@types/react-dom": "^19",
|
||||||
|
"eslint": "^9",
|
||||||
|
"eslint-config-next": "15.3.2",
|
||||||
|
"tailwindcss": "^4",
|
||||||
|
"typescript": "^5"
|
||||||
|
}
|
||||||
|
}
|
5
frontend/postcss.config.mjs
Normal file
5
frontend/postcss.config.mjs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
const config = {
|
||||||
|
plugins: ["@tailwindcss/postcss"],
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
1
frontend/public/file.svg
Normal file
1
frontend/public/file.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
After Width: | Height: | Size: 391 B |
1
frontend/public/globe.svg
Normal file
1
frontend/public/globe.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
After Width: | Height: | Size: 1 KiB |
1
frontend/public/next.svg
Normal file
1
frontend/public/next.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
After Width: | Height: | Size: 1.3 KiB |
1
frontend/public/vercel.svg
Normal file
1
frontend/public/vercel.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
After Width: | Height: | Size: 128 B |
1
frontend/public/window.svg
Normal file
1
frontend/public/window.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
After Width: | Height: | Size: 385 B |
47
frontend/src/app/auth/auth.module.css
Normal file
47
frontend/src/app/auth/auth.module.css
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
.authContainer {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 2rem auto;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.authTabs {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabButton {
|
||||||
|
padding: 0.75rem 2rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
color: #495057;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabButton:hover {
|
||||||
|
background-color: #e9ecef;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabButton.active {
|
||||||
|
background-color: #4a90e2;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formWrapper {
|
||||||
|
animation: fadeIn 0.3s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fadeIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(10px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
33
frontend/src/app/auth/page.tsx
Normal file
33
frontend/src/app/auth/page.tsx
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
import LoginForm from '@/components/auth/LoginForm';
|
||||||
|
import RegisterForm from '@/components/auth/RegisterForm';
|
||||||
|
import styles from './auth.module.css';
|
||||||
|
|
||||||
|
export default function AuthPage() {
|
||||||
|
const [activeTab, setActiveTab] = useState<'login' | 'register'>('login');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.authContainer}>
|
||||||
|
<div className={styles.authTabs}>
|
||||||
|
<button
|
||||||
|
className={`${styles.tabButton} ${activeTab === 'login' ? styles.active : ''}`}
|
||||||
|
onClick={() => setActiveTab('login')}
|
||||||
|
>
|
||||||
|
Connexion
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={`${styles.tabButton} ${activeTab === 'register' ? styles.active : ''}`}
|
||||||
|
onClick={() => setActiveTab('register')}
|
||||||
|
>
|
||||||
|
Inscription
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.formWrapper}>
|
||||||
|
{activeTab === 'login' ? <LoginForm /> : <RegisterForm />}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
BIN
frontend/src/app/favicon.ico
Normal file
BIN
frontend/src/app/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
26
frontend/src/app/globals.css
Normal file
26
frontend/src/app/globals.css
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
@import "tailwindcss";
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--background: #ffffff;
|
||||||
|
--foreground: #171717;
|
||||||
|
}
|
||||||
|
|
||||||
|
@theme inline {
|
||||||
|
--color-background: var(--background);
|
||||||
|
--color-foreground: var(--foreground);
|
||||||
|
--font-sans: var(--font-geist-sans);
|
||||||
|
--font-mono: var(--font-geist-mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--background: #0a0a0a;
|
||||||
|
--foreground: #ededed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: var(--background);
|
||||||
|
color: var(--foreground);
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
}
|
34
frontend/src/app/layout.tsx
Normal file
34
frontend/src/app/layout.tsx
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import type { Metadata } from "next";
|
||||||
|
import { Geist, Geist_Mono } from "next/font/google";
|
||||||
|
import "./globals.css";
|
||||||
|
|
||||||
|
const geistSans = Geist({
|
||||||
|
variable: "--font-geist-sans",
|
||||||
|
subsets: ["latin"],
|
||||||
|
});
|
||||||
|
|
||||||
|
const geistMono = Geist_Mono({
|
||||||
|
variable: "--font-geist-mono",
|
||||||
|
subsets: ["latin"],
|
||||||
|
});
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Create Next App",
|
||||||
|
description: "Generated by create next app",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function RootLayout({
|
||||||
|
children,
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
}>) {
|
||||||
|
return (
|
||||||
|
<html lang="en">
|
||||||
|
<body
|
||||||
|
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
51
frontend/src/app/page.module.css
Normal file
51
frontend/src/app/page.module.css
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
.main {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 100vh;
|
||||||
|
background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
|
||||||
|
color: white;
|
||||||
|
text-align: center;
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main h1 {
|
||||||
|
font-size: 4rem;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
letter-spacing: -0.02em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.subtitle {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
margin-bottom: 3rem;
|
||||||
|
opacity: 0.9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cta {
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ctaButton {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 1rem 2rem;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
background-color: white;
|
||||||
|
color: #4a90e2;
|
||||||
|
text-decoration: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
transition: all 0.2s;
|
||||||
|
font-weight: 500;
|
||||||
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ctaButton:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
19
frontend/src/app/page.tsx
Normal file
19
frontend/src/app/page.tsx
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import Link from 'next/link';
|
||||||
|
import styles from './page.module.css';
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<main className={styles.main}>
|
||||||
|
<div className={styles.content}>
|
||||||
|
<h1>WeMusic</h1>
|
||||||
|
<p className={styles.subtitle}>La plateforme pour les artistes indépendants</p>
|
||||||
|
|
||||||
|
<div className={styles.cta}>
|
||||||
|
<Link href="/auth" className={styles.ctaButton}>
|
||||||
|
Connexion / Inscription
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
63
frontend/src/components/TestApi.tsx
Normal file
63
frontend/src/components/TestApi.tsx
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState, useEffect } from 'react';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
interface ApiResponse {
|
||||||
|
message: string;
|
||||||
|
timestamp: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function TestApi() {
|
||||||
|
const [response, setResponse] = useState<ApiResponse | null>(null);
|
||||||
|
const [error, setError] = useState<string>('');
|
||||||
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchData = async () => {
|
||||||
|
try {
|
||||||
|
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
|
||||||
|
if (!apiUrl) {
|
||||||
|
throw new Error('L\'URL de l\'API n\'est pas configurée');
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await axios.get<ApiResponse>(`${apiUrl}/test`);
|
||||||
|
setResponse(result.data);
|
||||||
|
setError('');
|
||||||
|
} catch (err) {
|
||||||
|
setError('Erreur lors de la connexion à l\'API: ' + (err instanceof Error ? err.message : 'Erreur inconnue'));
|
||||||
|
setResponse(null);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <div className="flex items-center justify-center p-4">Chargement...</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="p-4 bg-red-100 border border-red-400 text-red-700 rounded">
|
||||||
|
{error}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="p-4 bg-white shadow rounded">
|
||||||
|
<h2 className="text-xl font-bold mb-4 text-gray-800">Test de Connexion API</h2>
|
||||||
|
{response && (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-green-600">{response.message}</p>
|
||||||
|
<p className="text-sm text-gray-500">
|
||||||
|
Timestamp: {new Date(response.timestamp).toLocaleString()}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
113
frontend/src/components/auth/AuthForms.module.css
Normal file
113
frontend/src/components/auth/AuthForms.module.css
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
.formContainer {
|
||||||
|
max-width: 500px;
|
||||||
|
margin: 2rem auto;
|
||||||
|
padding: 2rem;
|
||||||
|
background-color: #ffffff;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.formContainer h2 {
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
color: #333;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formGroup {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formGroup label {
|
||||||
|
color: #555;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formGroup input,
|
||||||
|
.formGroup select,
|
||||||
|
.formGroup textarea {
|
||||||
|
padding: 0.75rem;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 1rem;
|
||||||
|
transition: border-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.formGroup input:focus,
|
||||||
|
.formGroup select:focus,
|
||||||
|
.formGroup textarea:focus {
|
||||||
|
border-color: #4a90e2;
|
||||||
|
outline: none;
|
||||||
|
box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.formGroup textarea {
|
||||||
|
resize: vertical;
|
||||||
|
min-height: 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: #dc3545;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
padding: 0.5rem;
|
||||||
|
background-color: rgba(220, 53, 69, 0.1);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.success {
|
||||||
|
color: #28a745;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
padding: 0.5rem;
|
||||||
|
background-color: rgba(40, 167, 69, 0.1);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submitButton {
|
||||||
|
margin-top: 1rem;
|
||||||
|
padding: 0.75rem;
|
||||||
|
background-color: #4a90e2;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submitButton:hover:not(:disabled) {
|
||||||
|
background-color: #357abd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.submitButton:disabled {
|
||||||
|
background-color: #ccc;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.userInfo {
|
||||||
|
margin-top: 2rem;
|
||||||
|
padding: 1rem;
|
||||||
|
background-color: #f8f9fa;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid #e9ecef;
|
||||||
|
}
|
||||||
|
|
||||||
|
.userInfo h3 {
|
||||||
|
color: #4a90e2;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.userInfo p {
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
color: #495057;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
137
frontend/src/components/auth/LoginForm.tsx
Normal file
137
frontend/src/components/auth/LoginForm.tsx
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState, FormEvent } from 'react';
|
||||||
|
import styles from './AuthForms.module.css';
|
||||||
|
import useAuthStore from '@/store/useAuthStore';
|
||||||
|
import type { User } from '@/store/useAuthStore';
|
||||||
|
|
||||||
|
interface LoginFormData {
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LoginResponse {
|
||||||
|
success: boolean;
|
||||||
|
message: string;
|
||||||
|
token: string;
|
||||||
|
user: User;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function LoginForm() {
|
||||||
|
// État du formulaire
|
||||||
|
const [formData, setFormData] = useState<LoginFormData>({
|
||||||
|
email: '',
|
||||||
|
password: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
// État des erreurs et du message de succès
|
||||||
|
const [error, setError] = useState<string>('');
|
||||||
|
const [success, setSuccess] = useState<string>('');
|
||||||
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
|
|
||||||
|
// Récupération des fonctions du store
|
||||||
|
const { setUser, user, isAuthenticated } = useAuthStore();
|
||||||
|
|
||||||
|
// Gestion des changements dans les champs
|
||||||
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const { name, value } = e.target;
|
||||||
|
setFormData(prev => ({
|
||||||
|
...prev,
|
||||||
|
[name]: value
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Soumission du formulaire
|
||||||
|
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setError('');
|
||||||
|
setSuccess('');
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Validation basique
|
||||||
|
if (!formData.email || !formData.password) {
|
||||||
|
throw new Error('Veuillez remplir tous les champs');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Appel à l'API
|
||||||
|
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/auth/login`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(formData)
|
||||||
|
});
|
||||||
|
|
||||||
|
const data: LoginResponse = await response.json();
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(data.message || 'Une erreur est survenue');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mise à jour du store avec les informations de l'utilisateur
|
||||||
|
setUser(data.user, data.token);
|
||||||
|
setSuccess('Connexion réussie !');
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Une erreur est survenue');
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.formContainer}>
|
||||||
|
<h2>Connexion</h2>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className={styles.form}>
|
||||||
|
<div className={styles.formGroup}>
|
||||||
|
<label htmlFor="email">Email</label>
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
id="email"
|
||||||
|
name="email"
|
||||||
|
value={formData.email}
|
||||||
|
onChange={handleChange}
|
||||||
|
placeholder="votre@email.com"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.formGroup}>
|
||||||
|
<label htmlFor="password">Mot de passe</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="password"
|
||||||
|
name="password"
|
||||||
|
value={formData.password}
|
||||||
|
onChange={handleChange}
|
||||||
|
placeholder="Votre mot de passe"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && <div className={styles.error}>{error}</div>}
|
||||||
|
{success && <div className={styles.success}>{success}</div>}
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className={styles.submitButton}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
{isLoading ? 'Connexion...' : 'Se connecter'}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{/* Affichage des informations de l'utilisateur connecté */}
|
||||||
|
{isAuthenticated && user && (
|
||||||
|
<div className={styles.userInfo}>
|
||||||
|
<h3>Utilisateur connecté :</h3>
|
||||||
|
<p>Nom : {user.artist_name}</p>
|
||||||
|
<p>Email : {user.email}</p>
|
||||||
|
<p>Type : {user.user_type}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
250
frontend/src/components/auth/RegisterForm.tsx
Normal file
250
frontend/src/components/auth/RegisterForm.tsx
Normal file
|
@ -0,0 +1,250 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState, FormEvent } from 'react';
|
||||||
|
import styles from './AuthForms.module.css';
|
||||||
|
import useAuthStore from '@/store/useAuthStore';
|
||||||
|
import type { User } from '@/store/useAuthStore';
|
||||||
|
|
||||||
|
interface RegisterFormData {
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
confirmPassword: string;
|
||||||
|
artist_name: string;
|
||||||
|
user_type: 'artist' | 'venue_owner' | 'partner' | 'admin';
|
||||||
|
bio_short?: string;
|
||||||
|
bio_long?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RegisterResponse {
|
||||||
|
success: boolean;
|
||||||
|
message: string;
|
||||||
|
token: string;
|
||||||
|
user: User;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function RegisterForm() {
|
||||||
|
// État du formulaire
|
||||||
|
const [formData, setFormData] = useState<RegisterFormData>({
|
||||||
|
email: '',
|
||||||
|
password: '',
|
||||||
|
confirmPassword: '',
|
||||||
|
artist_name: '',
|
||||||
|
user_type: 'artist',
|
||||||
|
bio_short: '',
|
||||||
|
bio_long: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
// État des erreurs et du message de succès
|
||||||
|
const [error, setError] = useState<string>('');
|
||||||
|
const [success, setSuccess] = useState<string>('');
|
||||||
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
|
|
||||||
|
// Récupération des fonctions du store
|
||||||
|
const { setUser, user, isAuthenticated } = useAuthStore();
|
||||||
|
|
||||||
|
// Gestion des changements dans les champs
|
||||||
|
const handleChange = (
|
||||||
|
e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>
|
||||||
|
) => {
|
||||||
|
const { name, value } = e.target;
|
||||||
|
setFormData(prev => ({
|
||||||
|
...prev,
|
||||||
|
[name]: value
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Validation du formulaire
|
||||||
|
const validateForm = (): string | null => {
|
||||||
|
if (!formData.email || !formData.password || !formData.confirmPassword || !formData.artist_name) {
|
||||||
|
return 'Veuillez remplir tous les champs obligatoires';
|
||||||
|
}
|
||||||
|
if (formData.password !== formData.confirmPassword) {
|
||||||
|
return 'Les mots de passe ne correspondent pas';
|
||||||
|
}
|
||||||
|
if (formData.password.length < 8) {
|
||||||
|
return 'Le mot de passe doit contenir au moins 8 caractères';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Soumission du formulaire
|
||||||
|
const handleSubmit = async (e: FormEvent<HTMLFormElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setError('');
|
||||||
|
setSuccess('');
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
|
// Validation
|
||||||
|
const validationError = validateForm();
|
||||||
|
if (validationError) {
|
||||||
|
setError(validationError);
|
||||||
|
setIsLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Préparation des données pour l'API
|
||||||
|
const apiData = {
|
||||||
|
...formData,
|
||||||
|
confirmPassword: undefined
|
||||||
|
};
|
||||||
|
delete apiData.confirmPassword;
|
||||||
|
|
||||||
|
// Appel à l'API
|
||||||
|
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/auth/register`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(apiData)
|
||||||
|
});
|
||||||
|
|
||||||
|
const data: RegisterResponse = await response.json();
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(data.message || 'Une erreur est survenue');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mise à jour du store avec les informations de l'utilisateur
|
||||||
|
setUser(data.user, data.token);
|
||||||
|
setSuccess('Inscription réussie !');
|
||||||
|
|
||||||
|
// Réinitialisation du formulaire
|
||||||
|
setFormData({
|
||||||
|
email: '',
|
||||||
|
password: '',
|
||||||
|
confirmPassword: '',
|
||||||
|
artist_name: '',
|
||||||
|
user_type: 'artist',
|
||||||
|
bio_short: '',
|
||||||
|
bio_long: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Une erreur est survenue');
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.formContainer}>
|
||||||
|
<h2>Inscription</h2>
|
||||||
|
|
||||||
|
<form onSubmit={handleSubmit} className={styles.form}>
|
||||||
|
<div className={styles.formGroup}>
|
||||||
|
<label htmlFor="email">Email *</label>
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
id="email"
|
||||||
|
name="email"
|
||||||
|
value={formData.email}
|
||||||
|
onChange={handleChange}
|
||||||
|
placeholder="votre@email.com"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.formGroup}>
|
||||||
|
<label htmlFor="password">Mot de passe *</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="password"
|
||||||
|
name="password"
|
||||||
|
value={formData.password}
|
||||||
|
onChange={handleChange}
|
||||||
|
placeholder="Minimum 8 caractères"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.formGroup}>
|
||||||
|
<label htmlFor="confirmPassword">Confirmer le mot de passe *</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
id="confirmPassword"
|
||||||
|
name="confirmPassword"
|
||||||
|
value={formData.confirmPassword}
|
||||||
|
onChange={handleChange}
|
||||||
|
placeholder="Confirmez votre mot de passe"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.formGroup}>
|
||||||
|
<label htmlFor="artist_name">Nom d'artiste *</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="artist_name"
|
||||||
|
name="artist_name"
|
||||||
|
value={formData.artist_name}
|
||||||
|
onChange={handleChange}
|
||||||
|
placeholder="Votre nom d'artiste"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.formGroup}>
|
||||||
|
<label htmlFor="user_type">Type d'utilisateur *</label>
|
||||||
|
<select
|
||||||
|
id="user_type"
|
||||||
|
name="user_type"
|
||||||
|
value={formData.user_type}
|
||||||
|
onChange={handleChange}
|
||||||
|
required
|
||||||
|
>
|
||||||
|
<option value="artist">Artiste</option>
|
||||||
|
<option value="venue_owner">Propriétaire de salle</option>
|
||||||
|
<option value="partner">Partenaire</option>
|
||||||
|
<option value="admin">Administrateur</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.formGroup}>
|
||||||
|
<label htmlFor="bio_short">Courte biographie</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
id="bio_short"
|
||||||
|
name="bio_short"
|
||||||
|
value={formData.bio_short}
|
||||||
|
onChange={handleChange}
|
||||||
|
placeholder="Une brève description de vous"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.formGroup}>
|
||||||
|
<label htmlFor="bio_long">Biographie détaillée</label>
|
||||||
|
<textarea
|
||||||
|
id="bio_long"
|
||||||
|
name="bio_long"
|
||||||
|
value={formData.bio_long}
|
||||||
|
onChange={handleChange}
|
||||||
|
placeholder="Parlez-nous de vous en détail"
|
||||||
|
rows={4}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && <div className={styles.error}>{error}</div>}
|
||||||
|
{success && <div className={styles.success}>{success}</div>}
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className={styles.submitButton}
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
{isLoading ? 'Inscription...' : 'S\'inscrire'}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{/* Affichage des informations de l'utilisateur inscrit */}
|
||||||
|
{isAuthenticated && user && (
|
||||||
|
<div className={styles.userInfo}>
|
||||||
|
<h3>Inscription réussie !</h3>
|
||||||
|
<p>Nom : {user.artist_name}</p>
|
||||||
|
<p>Email : {user.email}</p>
|
||||||
|
<p>Type : {user.user_type}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
59
frontend/src/store/useAuthStore.ts
Normal file
59
frontend/src/store/useAuthStore.ts
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
import { create } from 'zustand';
|
||||||
|
import { persist } from 'zustand/middleware';
|
||||||
|
|
||||||
|
// Interface pour l'utilisateur
|
||||||
|
export interface User {
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
artist_name: string;
|
||||||
|
user_type: 'artist' | 'venue_owner' | 'partner' | 'admin';
|
||||||
|
bio_short?: string;
|
||||||
|
bio_long?: string;
|
||||||
|
profile_picture_url?: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interface pour le store d'authentification
|
||||||
|
interface AuthState {
|
||||||
|
user: User | null;
|
||||||
|
token: string | null;
|
||||||
|
isAuthenticated: boolean;
|
||||||
|
setUser: (user: User, token: string) => void;
|
||||||
|
clearUser: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Création du store avec persistance
|
||||||
|
const useAuthStore = create<AuthState>()(
|
||||||
|
persist(
|
||||||
|
(set) => ({
|
||||||
|
user: null,
|
||||||
|
token: null,
|
||||||
|
isAuthenticated: false,
|
||||||
|
|
||||||
|
// Définir l'utilisateur et le token
|
||||||
|
setUser: (user: User, token: string) => set({
|
||||||
|
user,
|
||||||
|
token,
|
||||||
|
isAuthenticated: true
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Réinitialiser l'état
|
||||||
|
clearUser: () => set({
|
||||||
|
user: null,
|
||||||
|
token: null,
|
||||||
|
isAuthenticated: false
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
name: 'auth-storage', // Nom du stockage dans le localStorage
|
||||||
|
partialize: (state) => ({
|
||||||
|
user: state.user,
|
||||||
|
token: state.token,
|
||||||
|
isAuthenticated: state.isAuthenticated
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export default useAuthStore;
|
27
frontend/tsconfig.json
Normal file
27
frontend/tsconfig.json
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2017",
|
||||||
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
|
"allowJs": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"jsx": "preserve",
|
||||||
|
"incremental": true,
|
||||||
|
"plugins": [
|
||||||
|
{
|
||||||
|
"name": "next"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./src/*"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue