First pass
This commit is contained in:
74
src/pages/signup.astro
Normal file
74
src/pages/signup.astro
Normal file
@@ -0,0 +1,74 @@
|
||||
---
|
||||
import Layout from '../layouts/Layout.astro';
|
||||
import { Icon } from 'astro-icon/components';
|
||||
import { db } from '../db';
|
||||
import { siteSettings, users } from '../db/schema';
|
||||
import { eq, count } from 'drizzle-orm';
|
||||
|
||||
if (Astro.locals.user) {
|
||||
return Astro.redirect('/dashboard');
|
||||
}
|
||||
|
||||
// Check if this would be the first user
|
||||
const userCountResult = await db.select({ count: count() }).from(users).get();
|
||||
const isFirstUser = userCountResult ? userCountResult.count === 0 : true;
|
||||
|
||||
// Check if registration is enabled (only if not first user)
|
||||
let registrationDisabled = false;
|
||||
if (!isFirstUser) {
|
||||
const registrationSetting = await db.select()
|
||||
.from(siteSettings)
|
||||
.where(eq(siteSettings.key, 'registration_enabled'))
|
||||
.get();
|
||||
registrationDisabled = registrationSetting?.value !== 'true';
|
||||
}
|
||||
---
|
||||
|
||||
<Layout title="Sign Up - Zamaan">
|
||||
<div class="flex justify-center items-center min-h-screen bg-base-200">
|
||||
<div class="card w-96 bg-base-100 shadow-xl">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title justify-center">Sign Up</h2>
|
||||
|
||||
{registrationDisabled ? (
|
||||
<div class="alert alert-warning">
|
||||
<Icon name="heroicons:exclamation-triangle" class="w-6 h-6" />
|
||||
<span>Registration is currently disabled.</span>
|
||||
</div>
|
||||
<div class="text-center mt-4">
|
||||
<a href="/login" class="link link-hover">Already have an account? Login</a>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<form action="/api/auth/signup" method="POST" class="space-y-4">
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text">Name</span>
|
||||
</label>
|
||||
<input type="text" name="name" placeholder="John Doe" class="input input-bordered" required />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text">Email</span>
|
||||
</label>
|
||||
<input type="email" name="email" placeholder="email@example.com" class="input input-bordered" required />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text">Password</span>
|
||||
</label>
|
||||
<input type="password" name="password" placeholder="********" class="input input-bordered" required />
|
||||
</div>
|
||||
<div class="form-control mt-6">
|
||||
<button class="btn btn-primary">Sign Up</button>
|
||||
</div>
|
||||
</form>
|
||||
<div class="text-center mt-4">
|
||||
<a href="/login" class="link link-hover">Already have an account? Login</a>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
Reference in New Issue
Block a user