Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Código exemplo #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/app/signup/page.tsx
Original file line number Diff line number Diff line change
@@ -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<SignupForm>({ email: '', password: '', confirmPassword: '' });

const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
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 (
<div className="flex justify-center items-center h-screen">
<form onSubmit={handleSubmit} className="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4">
<label>
Email:
<input type="email" name="email" value={form.email} onChange={handleInputChange} required className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" />
</label>
<label>
Password:
<input type="password" name="password" value={form.password} onChange={handleInputChange} required className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" />
</label>
<label>
Confirm Password:
<input type="password" name="confirmPassword" value={form.confirmPassword} onChange={handleInputChange} required className="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline" />
</label>
<button type="submit" className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline">Sign Up</button>
</form>
</div>
);
};

export default SignupPage;
9 changes: 9 additions & 0 deletions src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export const Header = async ({
/>
</div>
</div>
{/* Div with a blue signup button styled with TailwindCSS pointing to /signup */}
<div className="ml-2">
<a
href="/signup"
className="bg-blue-600 text-white px-4 py-2 rounded-md text-sm"
>
Sign Up
</a>
</div>
</Block>
);
};
Expand Down
11 changes: 11 additions & 0 deletions src/lib/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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." }
]
}
]
15 changes: 15 additions & 0 deletions src/lib/password_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}