From f495d94019d6cd42d0d0d602e7b6c76ee4647216 Mon Sep 17 00:00:00 2001 From: Sidney Gomes Date: Tue, 21 Jul 2026 19:43:45 -0300 Subject: [PATCH] feat: add CPF to user registration and update seed users --- server.ts | 63 ++++++++++++++++++++++++++-------------------------- src/App.tsx | 15 ++++++++++++- src/db/db.ts | 6 +++++ src/types.ts | 1 + 4 files changed, 53 insertions(+), 32 deletions(-) diff --git a/server.ts b/server.ts index 923234f..14e48fe 100644 --- a/server.ts +++ b/server.ts @@ -56,9 +56,9 @@ function requireAdmin(req: AuthenticatedRequest, res: Response, next: NextFuncti // 1. Auth: Register app.post('/api/auth/register', async (req: Request, res: Response) => { - const { name, email, password, birthDate, whatsapp } = req.body; + const { name, email, password, cpf, birthDate, whatsapp } = req.body; - if (!name || !email || !password || !birthDate || !whatsapp) { + if (!name || !email || !password || !cpf || !birthDate || !whatsapp) { res.status(400).json({ error: 'Preencha todos os campos obrigatórios' }); return; } @@ -71,33 +71,34 @@ app.post('/api/auth/register', async (req: Request, res: Response) => { return; } - try { - // Generate Asaas Customer ID (Real call if configured, or simulated) - const asaasCustomerId = await AsaasService.createCustomer(name, email); - - const salt = bcrypt.genSaltSync(10); - const passwordHash = bcrypt.hashSync(password, salt); - - const createdAt = new Date(); - - // Calculate trial ends at - const trialDays = db.settings?.trialDurationDays || 7; - const trialEndsAt = new Date(createdAt); - trialEndsAt.setDate(trialEndsAt.getDate() + trialDays); - - const newUser: User = { - id: `usr_${Math.random().toString(36).substring(2, 9)}`, - name, - email: email.toLowerCase(), - password: passwordHash, - role: 'student', - subscriptionStatus: 'TRIAL', // Defaults to trial - asaasCustomerId, - birthDate, - whatsapp, - trialEndsAt: trialEndsAt.toISOString(), - createdAt: createdAt.toISOString() - }; + try { + // Generate Asaas Customer ID (Real call if configured, or simulated) + const asaasCustomerId = await AsaasService.createCustomer(name, email, cpf); + + const salt = bcrypt.genSaltSync(10); + const passwordHash = bcrypt.hashSync(password, salt); + + const createdAt = new Date(); + + // Calculate trial ends at + const trialDays = db.settings?.trialDurationDays || 7; + const trialEndsAt = new Date(createdAt); + trialEndsAt.setDate(trialEndsAt.getDate() + trialDays); + + const newUser: User = { + id: `usr_${Math.random().toString(36).substring(2, 9)}`, + name, + email: email.toLowerCase(), + password: passwordHash, + role: 'student', + subscriptionStatus: 'TRIAL', // Defaults to trial + asaasCustomerId, + cpf, + birthDate, + whatsapp, + trialEndsAt: trialEndsAt.toISOString(), + createdAt: createdAt.toISOString() + }; db.users.push(newUser); saveDb(db); @@ -336,7 +337,7 @@ app.post('/api/courses/:id/unlock', authenticateToken, checkoutRateLimiter, asyn customerId = null; } if (!customerId) { - customerId = await AsaasService.createCustomer(user.name, user.email); + customerId = await AsaasService.createCustomer(user.name, user.email, user.cpf); user.asaasCustomerId = customerId; } @@ -520,7 +521,7 @@ app.post('/api/subscription/subscribe', authenticateToken, async (req: Authentic customerId = null; } if (!customerId) { - customerId = await AsaasService.createCustomer(user.name, user.email); + customerId = await AsaasService.createCustomer(user.name, user.email, user.cpf); user.asaasCustomerId = customerId; } diff --git a/src/App.tsx b/src/App.tsx index 5dd0393..b63c4eb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -35,6 +35,7 @@ export default function App() { const [regName, setRegName] = useState(''); const [regEmail, setRegEmail] = useState(''); const [regPassword, setRegPassword] = useState(''); + const [regCpf, setRegCpf] = useState(''); const [regBirthDate, setRegBirthDate] = useState(''); const [regWhatsapp, setRegWhatsapp] = useState(''); const [authError, setAuthError] = useState(null); @@ -134,7 +135,7 @@ export default function App() { const res = await fetch('/api/auth/register', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ name: regName, email: regEmail, password: regPassword, birthDate: regBirthDate, whatsapp: regWhatsapp }) + body: JSON.stringify({ name: regName, email: regEmail, password: regPassword, cpf: regCpf, birthDate: regBirthDate, whatsapp: regWhatsapp }) }); const data = await res.json(); @@ -355,6 +356,18 @@ export default function App() { /> +
+ + setRegCpf(e.target.value)} + placeholder="000.000.000-00" + className="w-full glass-input rounded-lg p-3 text-xs text-white focus:outline-none" + /> +
+