From c321705cdcc066127cd6fe1a0e484ce0bf2dad0d Mon Sep 17 00:00:00 2001 From: Pedro Lacerda Date: Tue, 2 Apr 2024 20:59:21 +0000 Subject: [PATCH] =?UTF-8?q?C=C3=B3digo=20exemplo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/signup/page.tsx | 47 ++++++++++++++++++++++++++++++++++++++ src/components/header.tsx | 9 ++++++++ src/lib/messages.json | 11 +++++++++ src/lib/password_helper.ts | 15 ++++++++++++ 4 files changed, 82 insertions(+) diff --git a/src/app/signup/page.tsx b/src/app/signup/page.tsx index e69de29..0e5e7ce 100644 --- a/src/app/signup/page.tsx +++ b/src/app/signup/page.tsx @@ -0,0 +1,47 @@ +"use client"; +import React, { useState } from 'react'; + +interface SignupForm { + email: string; + password: string; + confirmPassword: string; +} + +const SignupPage: React.FC = () => { + const [form, setForm] = useState({ email: '', password: '', confirmPassword: '' }); + + const handleInputChange = (event: React.ChangeEvent) => { + setForm({ ...form, [event.target.name]: event.target.value }); + }; + + const handleSubmit = (event: React.FormEvent) => { + event.preventDefault(); + if (form.password !== form.confirmPassword) { + alert('Passwords do not match!'); + return; + } + // Handle signup logic here + }; + + return ( +
+
+ + + + +
+
+ ); +}; + +export default SignupPage; \ No newline at end of file diff --git a/src/components/header.tsx b/src/components/header.tsx index 3c57dd7..5893c63 100644 --- a/src/components/header.tsx +++ b/src/components/header.tsx @@ -46,6 +46,15 @@ export const Header = async ({ /> + {/* Div with a blue signup button styled with TailwindCSS pointing to /signup */} +
+ + Sign Up + +
); }; diff --git a/src/lib/messages.json b/src/lib/messages.json index a29e685..9f53da6 100644 --- a/src/lib/messages.json +++ b/src/lib/messages.json @@ -9,5 +9,16 @@ { "id": "LoginMessage", "text": "Please enter your username and password." }, { "id": "LogoutMessage", "text": "You have been logged out." } ] + }, + { + "language": "pt", + "messages": [ + { "id": "MissingDataError", "text": "Dados em falta. Um ou mais campos obrigatórios estão em falta." }, + { "id": "InvalidDataError", "text": "Dados inválidos. Um ou mais campos contêm dados inválidos." }, + { "id": "InvalidPasswordError", "text": "Palavra-passe inválida. A palavra-passe não é válida." }, + { "id": "EntryCreated", "text": "Obrigado. Entrada criada com sucesso." }, + { "id": "LoginMessage", "text": "Por favor, introduza o seu nome de utilizador e palavra-passe." }, + { "id": "LogoutMessage", "text": "Sessão terminada." } + ] } ] \ No newline at end of file diff --git a/src/lib/password_helper.ts b/src/lib/password_helper.ts index 4e6c848..3bd4dd7 100644 --- a/src/lib/password_helper.ts +++ b/src/lib/password_helper.ts @@ -9,4 +9,19 @@ export function GeneratePassword(length: number = 8): string { } export function IsValid(password: string): boolean { // Valida se a senha possui tamanho mínimo de 8 caracteres, ao menos 2 letras maíusculas, 2 números e 2 caracteres especiais + const uppercaseRegex = /[A-Z]/g; + const numberRegex = /[0-9]/g; + const specialCharacterRegex = /[^A-Za-z0-9]/g; + const uppercaseMatches = password.match(uppercaseRegex); + const numberMatches = password.match(numberRegex); + const specialCharacterMatches = password.match(specialCharacterRegex); + return ( + password.length >= 8 && + uppercaseMatches !== null && + uppercaseMatches.length >= 2 && + numberMatches !== null && + numberMatches.length >= 2 && + specialCharacterMatches !== null && + specialCharacterMatches.length >= 2 + ); }