mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-11 12:05:33 +08:00
Add waitlist invitation sending from admin
This commit is contained in:
@@ -70,7 +70,10 @@ export default defineEventHandler(async (event) => {
|
||||
invitation.usedAt = now
|
||||
await invitation.save()
|
||||
|
||||
await WaitlistEntry.findOneAndUpdate({ email }, { activatedAt: now }).catch(() => undefined)
|
||||
await WaitlistEntry.findOneAndUpdate(
|
||||
{ email },
|
||||
{ activatedAt: now, invitationCode: invitation._id },
|
||||
).catch(() => undefined)
|
||||
|
||||
const tokens = await issueAuthTokens(event, user)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { randomBytes } from 'node:crypto'
|
||||
import { createError, readBody } from 'h3'
|
||||
import { InvitationCode } from '../../../models/InvitationCode'
|
||||
import { generateInvitationCode } from '../../../utils/invitations'
|
||||
|
||||
const CREATION_DEADLINE = new Date(process.env.BOOTSTRAP_INVITE_DEADLINE ?? '2025-10-01T00:00:00Z')
|
||||
|
||||
@@ -15,7 +15,7 @@ export default defineEventHandler(async (event) => {
|
||||
}
|
||||
|
||||
const body = await readBody<{ label?: string }>(event).catch(() => ({ label: undefined }))
|
||||
const code = randomBytes(4).toString('hex').toUpperCase()
|
||||
const code = generateInvitationCode()
|
||||
const expiresAt = CREATION_DEADLINE
|
||||
|
||||
await InvitationCode.create({
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto'
|
||||
import { createHmac, timingSafeEqual } from 'node:crypto'
|
||||
import { createError, readBody } from 'h3'
|
||||
import { useRuntimeConfig } from '#imports'
|
||||
import { InvitationCode } from '../../../models/InvitationCode'
|
||||
import { generateInvitationCode } from '../../../utils/invitations'
|
||||
|
||||
interface ManualInviteRequestBody {
|
||||
password?: string
|
||||
@@ -15,10 +16,6 @@ interface ManualInviteResponse {
|
||||
label: string | null
|
||||
}
|
||||
|
||||
function generateCode() {
|
||||
return randomBytes(4).toString('hex').toUpperCase()
|
||||
}
|
||||
|
||||
function safeComparePassword(provided: string, expected: string) {
|
||||
const key = 'opensquawk-manual-invite'
|
||||
const providedDigest = createHmac('sha256', key).update(provided).digest()
|
||||
@@ -42,7 +39,7 @@ export default defineEventHandler<ManualInviteResponse>(async (event) => {
|
||||
}
|
||||
|
||||
const now = new Date()
|
||||
const code = generateCode()
|
||||
const code = generateInvitationCode()
|
||||
const expiresAt = new Date(now.getTime() + 1000 * 60 * 60 * 24 * 30)
|
||||
const label = body.label?.trim() || undefined
|
||||
|
||||
|
||||
Reference in New Issue
Block a user