update some login things
This commit is contained in:
parent
a52be45907
commit
b40c1db189
7 changed files with 333 additions and 37 deletions
|
@ -59,11 +59,16 @@ async function handler(
|
|||
}
|
||||
|
||||
const errors: string[] = [];
|
||||
|
||||
const validations: UserValidation[] = [
|
||||
{ check: isValidUsername(username), field: "Username" },
|
||||
{ check: isValidEmail(email), field: "Email" },
|
||||
{ check: isValidPassword(password), field: "Password" },
|
||||
];
|
||||
username
|
||||
? { check: isValidUsername(username), field: "Username" }
|
||||
: null,
|
||||
email ? { check: isValidEmail(email), field: "Email" } : null,
|
||||
password
|
||||
? { check: isValidPassword(password), field: "Password" }
|
||||
: null,
|
||||
].filter(Boolean) as UserValidation[];
|
||||
|
||||
validations.forEach(({ check }: UserValidation): void => {
|
||||
if (!check.valid && check.error) {
|
||||
|
@ -71,6 +76,10 @@ async function handler(
|
|||
}
|
||||
});
|
||||
|
||||
if (!username && !email) {
|
||||
errors.push("Either a username or an email is required.");
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
return Response.json(
|
||||
{
|
||||
|
@ -86,11 +95,11 @@ async function handler(
|
|||
let user: User | null = null;
|
||||
|
||||
try {
|
||||
user = await reservation`
|
||||
[user] = await reservation`
|
||||
SELECT * FROM users
|
||||
WHERE (username = ${username} OR email = ${email})
|
||||
LIMIT 1;
|
||||
`.then((rows: User[]): User | null => rows[0]);
|
||||
`;
|
||||
|
||||
if (!user) {
|
||||
await bunPassword.verify("fake", await bunPassword.hash("fake"));
|
||||
|
|
|
@ -8,10 +8,12 @@ const routeDef: RouteDef = {
|
|||
};
|
||||
|
||||
async function handler(): Promise<Response> {
|
||||
const instanceName: string =
|
||||
(await getSetting("instance_name")) || "Unnamed Instance";
|
||||
|
||||
const ejsTemplateData: EjsTemplateData = {
|
||||
title: "Hello, World!",
|
||||
instance_name:
|
||||
(await getSetting("instance_name")) || "Unnamed Instance",
|
||||
title: `Login - ${instanceName}`,
|
||||
instance_name: instanceName,
|
||||
};
|
||||
|
||||
return await renderEjsTemplate("auth/login", ejsTemplateData);
|
||||
|
|
|
@ -1,28 +1,56 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<%- include("../global", { styles: ["auth/login"], scripts: [] }) %>
|
||||
<%- include("../global", { styles: ["auth/login"], scripts: ["auth/login"] }) %>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1><%= instance_name %></h1>
|
||||
<div class="login-container">
|
||||
<div class="login-logo">
|
||||
<h1>
|
||||
<%= instance_name %>
|
||||
</h1>
|
||||
<p>Sign in to your account</p>
|
||||
</div>
|
||||
<div class="content">
|
||||
<form id="login-form">
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" name="email" id="email" required>
|
||||
|
||||
<div class="login-card">
|
||||
<div class="login-header">
|
||||
<h2>Welcome Back</h2>
|
||||
</div>
|
||||
|
||||
<div class="login-form">
|
||||
<div class="error-message" id="error-message">
|
||||
Invalid email or password. Please try again.
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" name="password" id="password" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
||||
<form id="login-form">
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" name="email" id="email" required placeholder="Enter your email">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" name="password" id="password" required placeholder="Enter your password">
|
||||
</div>
|
||||
|
||||
<div class="form-footer">
|
||||
<label>
|
||||
<input type="checkbox" name="remember" id="remember">Remember me
|
||||
</label>
|
||||
<a href="/auth/forgot-password">Forgot password?</a>
|
||||
</div>
|
||||
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
|
||||
<div class="login-register">
|
||||
<p>Don't have an account? <a href="/auth/register" class="register-link">Register</a></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue