Skip to content
Closed
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
2 changes: 1 addition & 1 deletion frontend/src/pages/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ export default function LoginPage() {
</p>
</div>
);
}
}
23 changes: 12 additions & 11 deletions frontend/src/pages/RegisterPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import PasswordInput from '../components/PasswordInput';
import { HiMail, HiArrowRight, HiCheckCircle, HiXCircle } from 'react-icons/hi';

export default function RegisterPage() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [errors, setErrors] = useState({});
const [serverError, setServerError] = useState('');
const [isLoading, setIsLoading] = useState(false);
Expand Down Expand Up @@ -38,31 +38,32 @@ export default function RegisterPage() {
const newErrors = {};
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
newErrors.email = 'Please enter a valid email address.';
newErrors.email = "Please enter a valid email address.";
} else {
// Frontend blacklist for instant feedback
const domain = email.split('@')[1];
const blockedDomains = ['example.com', 'test.com', 'invalid.com'];
const domain = email.split("@")[1];
const blockedDomains = ["example.com", "test.com", "invalid.com"];
if (blockedDomains.includes(domain)) {
newErrors.email = 'This email domain is not allowed.';
newErrors.email = "This email domain is not allowed.";
}
}

if (password.length < 8 || password.length > 16) {
newErrors.password = 'Password must be 8-16 characters long.';
newErrors.password = "Password must be 8-16 characters long.";
} else {
const passwordRegex = /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[\W_])/;
if (!passwordRegex.test(password)) {
newErrors.password = 'Password must contain an alphabet, a digit, and a symbol.';
newErrors.password =
"Password must contain an alphabet, a digit, and a symbol.";
}
}

return newErrors;
};

const handleSubmit = async (e) => {
e.preventDefault();
setServerError('');
setServerError(""); // Clear previous server errors
const validationErrors = validate();
if (Object.keys(validationErrors).length > 0) {
setErrors(validationErrors);
Expand Down Expand Up @@ -262,4 +263,4 @@ export default function RegisterPage() {
</p>
</div>
);
}
}