L'inscription Classeo se fait via invitation : un admin crée un compte, l'utilisateur reçoit un lien d'activation par email pour définir son mot de passe. Ce flow sécurisé évite les inscriptions non autorisées et garantit que seuls les utilisateurs légitimes accèdent au système. Points clés de l'implémentation : - Tokens d'activation à usage unique stockés en cache (Redis/filesystem) - Validation du consentement parental pour les mineurs < 15 ans (RGPD) - L'échec d'activation ne consume pas le token (retry possible) - Users dans un cache séparé sans TTL (pas d'expiration) - Hot reload en dev (FrankenPHP sans mode worker) Story: 1.3 - Inscription et activation de compte
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { execSync } from 'child_process';
|
|
import { writeFileSync } from 'fs';
|
|
import { join, dirname } from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
/**
|
|
* Global setup for E2E tests.
|
|
* Seeds a test activation token before tests run.
|
|
*/
|
|
async function globalSetup() {
|
|
console.warn('🌱 Seeding test activation token...');
|
|
|
|
try {
|
|
// Call the backend command to create a test token
|
|
// Project root is 2 levels up from frontend/e2e/
|
|
const projectRoot = join(__dirname, '../..');
|
|
const composeFile = join(projectRoot, 'compose.yaml');
|
|
|
|
const result = execSync(
|
|
`docker compose -f "${composeFile}" exec -T php php bin/console app:dev:create-test-activation-token --email=e2e-test@example.com 2>&1`,
|
|
{
|
|
encoding: 'utf-8'
|
|
}
|
|
);
|
|
|
|
// Extract the token from the output
|
|
// Output format: "Token f9174245-9766-4ef1-b6e9-a6795aa2da04"
|
|
const tokenMatch = result.match(/Token\s+([a-f0-9-]{36})/i);
|
|
if (!tokenMatch) {
|
|
console.error('❌ Could not extract token from output:', result);
|
|
throw new Error('Failed to extract token from command output');
|
|
}
|
|
|
|
const token = tokenMatch[1];
|
|
console.warn(`✅ Test token created: ${token}`);
|
|
|
|
// Write the token to a file for tests to use
|
|
const tokenFile = join(__dirname, '.test-token');
|
|
writeFileSync(tokenFile, token);
|
|
|
|
console.warn('✅ Token saved to .test-token file');
|
|
} catch (error) {
|
|
console.error('❌ Failed to seed test token:', error);
|
|
// Don't throw - tests can still run with skipped token-dependent tests
|
|
console.warn('⚠️ Tests requiring valid tokens will be skipped');
|
|
}
|
|
}
|
|
|
|
export default globalSetup;
|