Allow signing up forever without Brevo.

Also allow logins from local IPs (related to #5).
This commit is contained in:
Bruno Bernardino
2024-04-08 20:53:28 +01:00
parent 4f97609ebb
commit 5a85dd224e
8 changed files with 40 additions and 14 deletions

View File

@@ -152,7 +152,9 @@ export async function logoutUser(request: Request) {
name: COOKIE_NAME,
value: '',
expires: tomorrow,
domain: isRunningLocally(request) ? 'localhost' : baseUrl.replace('https://', ''),
domain: isRunningLocally(request)
? 'localhost'
: baseUrl.replace('https://', '').replace('http://', '').split(':')[0],
path: '/',
secure: isRunningLocally(request) ? false : true,
httpOnly: true,

View File

@@ -14,6 +14,18 @@ export async function isSignupAllowed() {
return false;
}
export function isEmailEnabled() {
const areEmailsAllowed = Deno.env.get('CONFIG_ENABLE_EMAILS') === 'true';
return areEmailsAllowed;
}
export function isForeverSignupEnabled() {
const areForeverAccountsEnabled = Deno.env.get('CONFIG_ENABLE_FOREVER_SIGNUP') === 'true';
return areForeverAccountsEnabled;
}
export function getFilesRootPath() {
const configRootPath = Deno.env.get('CONFIG_FILES_ROOT_PATH');

View File

@@ -1,6 +1,7 @@
import Database, { sql } from '/lib/interfaces/database.ts';
import { User, UserSession, VerificationCode } from '/lib/types.ts';
import { generateRandomCode } from '/lib/utils/misc.ts';
import { isEmailEnabled, isForeverSignupEnabled } from '/lib/config.ts';
const db = new Database();
@@ -32,7 +33,7 @@ export async function getUserById(id: string) {
}
export async function createUser(email: User['email'], hashedPassword: User['hashed_password']) {
const trialDays = 30;
const trialDays = isForeverSignupEnabled() ? 36_525 : 30;
const now = new Date();
const trialEndDate = new Date(new Date().setUTCDate(new Date().getUTCDate() + trialDays));
@@ -42,7 +43,7 @@ export async function createUser(email: User['email'], hashedPassword: User['has
updated_at: now.toISOString(),
};
const extra: User['extra'] = { is_email_verified: false };
const extra: User['extra'] = { is_email_verified: isEmailEnabled() ? false : true };
// First signup will be an admin "forever"
if (!(await isThereAnAdmin())) {
@@ -62,7 +63,7 @@ export async function createUser(email: User['email'], hashedPassword: User['has
[
email,
JSON.stringify(subscription),
extra.is_admin ? 'active' : 'trial',
extra.is_admin || isForeverSignupEnabled() ? 'active' : 'trial',
hashedPassword,
JSON.stringify(extra),
],