feat: verified sign-up and several organizations per account
New accounts confirm their email address before signing in: sign-up mails a link valid for 24 hours, and its page confirms only when the visitor presses the button, so mail scanners opening links do not sign in. Confirming signs the account in; unconfirmed accounts are told so only after giving the right password, can ask for a new link, and are deleted after a week. UPTIME_SIGNUP_VERIFY requires confirmation always in the cloud edition and self-hosted wherever mail can be sent; without a mail server, sign-up that needs it stays closed. One account per mailbox: users.email_key drops +suffixes, and dots for Gmail, and is unique, including for accounts created through invitations and SSO, which count as confirmed. A client address (IPv6: its /64) may create UPTIME_SIGNUPS_PER_IP accounts a day, 2 by default; refused sign-ups do not count. Sign-up asks only for name, email and password. Accounts without an organization are led to create one; signed-in users create further organizations from the switcher, within the per-account limit, and POST /api/v1/orgs does the same. Closes #112 Closes #113 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
d644312f25
commit
87b2f2a256
29 files changed
+1698
-377
No files matched your search
@@ -1,7 +1,21 @@
|
||||
-- name: CreateUser :one
|
||||
INSERT INTO users (email, display_name, password_hash, locale) VALUES ($1, $2, $3, $4)
|
||||
INSERT INTO users (email, display_name, password_hash, locale, email_key, email_verified_at)
|
||||
VALUES ($1, $2, $3, $4, sqlc.arg(email_key), sqlc.narg(email_verified_at))
|
||||
RETURNING *;
|
||||
|
||||
-- name: MarkEmailVerified :one
|
||||
UPDATE users SET email_verified_at = coalesce(email_verified_at, now()) WHERE id = $1
|
||||
RETURNING *;
|
||||
|
||||
-- name: PurgeUnverifiedUsers :execrows
|
||||
-- Accounts never confirmed; they belong to no organization.
|
||||
DELETE FROM users u
|
||||
WHERE u.email_verified_at IS NULL AND u.created_at < $1
|
||||
AND NOT EXISTS (SELECT 1 FROM memberships m WHERE m.user_id = u.id);
|
||||
|
||||
-- name: CountOwnedOrgs :one
|
||||
SELECT count(*) FROM memberships WHERE user_id = $1 AND is_owner;
|
||||
|
||||
-- name: GetUser :one
|
||||
SELECT * FROM users WHERE id = $1;
|
||||
|
||||
@@ -31,3 +45,6 @@ UPDATE users SET is_admin = $2, updated_at = now() WHERE email = $1;
|
||||
|
||||
-- name: MakeAdmin :exec
|
||||
UPDATE users SET is_admin = true, updated_at = now() WHERE id = $1;
|
||||
|
||||
-- name: EmailKeyTaken :one
|
||||
SELECT EXISTS (SELECT 1 FROM users WHERE email_key = $1);
|
||||
Reference in new issue
Block a user