alpha
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const express = require("express");
|
||||
const jwt = require("jsonwebtoken");
|
||||
const { OAuth2Client } = require("google-auth-library");
|
||||
const { User } = require("../models"); // Import from models/index.js to get models with associations
|
||||
const { User, AlphaInvitation } = require("../models"); // Import from models/index.js to get models with associations
|
||||
const logger = require("../utils/logger");
|
||||
const emailService = require("../services/emailService");
|
||||
const crypto = require("crypto");
|
||||
@@ -64,6 +64,35 @@ router.post(
|
||||
});
|
||||
}
|
||||
|
||||
// Alpha access validation
|
||||
let alphaInvitation = null;
|
||||
if (req.signedCookies && req.signedCookies.alphaAccessCode) {
|
||||
const { code } = req.signedCookies.alphaAccessCode;
|
||||
if (code) {
|
||||
alphaInvitation = await AlphaInvitation.findOne({
|
||||
where: { code },
|
||||
});
|
||||
|
||||
if (!alphaInvitation) {
|
||||
return res.status(403).json({
|
||||
error: "Invalid alpha access code",
|
||||
});
|
||||
}
|
||||
|
||||
if (alphaInvitation.status === "revoked") {
|
||||
return res.status(403).json({
|
||||
error: "This alpha access code is no longer valid",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!alphaInvitation) {
|
||||
return res.status(403).json({
|
||||
error: "Alpha access required. Please enter your invitation code first.",
|
||||
});
|
||||
}
|
||||
|
||||
const user = await User.create({
|
||||
username,
|
||||
email,
|
||||
@@ -73,6 +102,13 @@ router.post(
|
||||
phone,
|
||||
});
|
||||
|
||||
// Link alpha invitation to user
|
||||
await alphaInvitation.update({
|
||||
usedBy: user.id,
|
||||
usedAt: new Date(),
|
||||
status: "active",
|
||||
});
|
||||
|
||||
// Generate verification token and send email
|
||||
await user.generateVerificationToken();
|
||||
|
||||
@@ -318,6 +354,20 @@ router.post(
|
||||
isVerified: true,
|
||||
verifiedAt: new Date(),
|
||||
});
|
||||
|
||||
// Check if there's an alpha invitation for this email
|
||||
const alphaInvitation = await AlphaInvitation.findOne({
|
||||
where: { email: email.toLowerCase().trim() },
|
||||
});
|
||||
|
||||
if (alphaInvitation && !alphaInvitation.usedBy) {
|
||||
// Link invitation to new user
|
||||
await alphaInvitation.update({
|
||||
usedBy: user.id,
|
||||
usedAt: new Date(),
|
||||
status: "active",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Generate JWT tokens
|
||||
|
||||
Reference in New Issue
Block a user