add possibility to create account without email and token
This commit is contained in:
@@ -114,6 +114,7 @@
|
||||
"swf_thumb": "/s/img/swf.png",
|
||||
"open_registration": true,
|
||||
"open_registration_web_toggle": false,
|
||||
"open_registration_require_mail_andor_token": false,
|
||||
"private_society": false,
|
||||
"private_society_gate": "cloudflare",
|
||||
"paths": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import db from "../sql.mjs";
|
||||
import lib from "../lib.mjs";
|
||||
import security from "../security.mjs";
|
||||
import { getRegistrationOpen, getDefaultLayout } from "../settings.mjs";
|
||||
import { getRegistrationOpen, getRegistrationRequireMailAndorToken, getDefaultLayout } from "../settings.mjs";
|
||||
import { sendMail } from "../../lib/smtp.mjs";
|
||||
import cfg from "../config.mjs";
|
||||
import crypto from "crypto";
|
||||
@@ -92,22 +92,28 @@ export default (router, tpl) => {
|
||||
let activated = true;
|
||||
let activationToken = null;
|
||||
|
||||
if (!token && !getRegistrationOpen()) {
|
||||
const registrationOpen = getRegistrationOpen();
|
||||
const requireMailOrToken = getRegistrationRequireMailAndorToken();
|
||||
|
||||
if (!registrationOpen && !token) {
|
||||
// Closed registration — invite token is always required
|
||||
return renderError("Invite token is required for registration.");
|
||||
}
|
||||
|
||||
if (token) {
|
||||
// Invite token path — validate and activate immediately
|
||||
const tokenRow = await db`
|
||||
select * from invite_tokens where token = ${token} and is_used = false
|
||||
`;
|
||||
if (tokenRow.length === 0) return renderError("Invalid or used invite token");
|
||||
// Token used, so it will be activated by default
|
||||
} else {
|
||||
// No token, Open Registration
|
||||
if (!email || !email.includes('@')) return renderError("A valid email is required for no-token registration.");
|
||||
// Token is valid; account activated immediately
|
||||
} else if (requireMailOrToken) {
|
||||
// Open registration but email/token required — email path
|
||||
if (!email || !email.includes('@')) return renderError("A valid email is required for registration.");
|
||||
activated = false;
|
||||
activationToken = crypto.randomBytes(32).toString('hex');
|
||||
}
|
||||
// else: open registration, no mail/token required — just username+password, activated immediately
|
||||
|
||||
// Check user existence
|
||||
const existing = await db`
|
||||
|
||||
@@ -49,6 +49,11 @@ export const getRegistrationOpen = () => {
|
||||
};
|
||||
export const setRegistrationOpen = (val) => registration_open = !!val;
|
||||
|
||||
// When false (default): open_registration=true means anyone can register with just username+password, activated immediately.
|
||||
// When true: even in open registration, a valid email OR invite token is required.
|
||||
export const getRegistrationRequireMailAndorToken = () => !!cfg.websrv.open_registration_require_mail_andor_token;
|
||||
export const setRegistrationRequireMailAndorToken = (val) => {}; // No-op, strictly config-based
|
||||
|
||||
export const getTrustedUploads = () => trusted_uploads;
|
||||
export const setTrustedUploads = (val) => trusted_uploads = Math.max(0, parseInt(val) ?? 3);
|
||||
|
||||
|
||||
@@ -1075,6 +1075,7 @@ process.on('uncaughtException', err => {
|
||||
get min_tags() { return getMinTags(); },
|
||||
get registration_open() { return getRegistrationOpen(); },
|
||||
registration_web_toggle_enabled: cfg.websrv.open_registration_web_toggle !== false,
|
||||
registration_require_mail_andor_token: !!cfg.websrv.open_registration_require_mail_andor_token,
|
||||
get trusted_uploads() { return getTrustedUploads(); },
|
||||
get shitpost_mode() { return getShitpostMode(); },
|
||||
shitpost_require_rating: !!cfg.websrv.shitpost_require_rating,
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
<input type="text" name="username" placeholder="{{ t('auth.username_placeholder') }}" autocomplete="off" required />
|
||||
<input type="password" name="password" placeholder="{{ t('auth.password_placeholder') }}" autocomplete="off" required minlength="20" title="{{ t('auth.password_min_hint') }}" />
|
||||
<input type="password" name="password_confirm" placeholder="{{ t('auth.confirm_password') }}" autocomplete="off" required minlength="20" /><br>
|
||||
@if(registration_open)
|
||||
<input type="email" name="email" placeholder="{{ t('auth.email_placeholder') }}" autocomplete="off" required />
|
||||
@else
|
||||
@if(!registration_open)
|
||||
<input type="text" name="token" placeholder="{{ t('auth.invite_token') }}" autocomplete="off" value="{{ typeof token !== 'undefined' ? token : '' }}" required />
|
||||
@elseif(registration_require_mail_andor_token)
|
||||
<input type="email" name="email" placeholder="{{ t('auth.email_placeholder') }}" autocomplete="off" required />
|
||||
@endif
|
||||
<input type="text" name="email_confirm_field" style="display: none !important;" tabindex="-1" autocomplete="off" />
|
||||
<p style="text-align: left; font-size: 0.9em; margin: 10px 0; color: #fff;">
|
||||
|
||||
@@ -338,10 +338,10 @@
|
||||
<input type="password" name="password" placeholder="{{ t('auth.password_placeholder') }}" autocomplete="off" required minlength="20"
|
||||
title="Must be at least 20 characters long." />
|
||||
<input type="password" name="password_confirm" placeholder="{{ t('auth.confirm_password') }}" autocomplete="off" required minlength="20" />
|
||||
@if(registration_open)
|
||||
<input type="email" name="email" placeholder="{{ t('auth.email_placeholder') }}" autocomplete="off" required />
|
||||
@else
|
||||
@if(!registration_open)
|
||||
<input type="text" name="token" placeholder="{{ t('auth.invite_token') }}" autocomplete="off" required />
|
||||
@elseif(registration_require_mail_andor_token)
|
||||
<input type="email" name="email" placeholder="{{ t('auth.email_placeholder') }}" autocomplete="off" required />
|
||||
@endif
|
||||
<input type="text" name="email_confirm_field" style="display: none !important;" tabindex="-1" autocomplete="off" />
|
||||
<p style="text-align: left; font-size: 0.9em; margin: 0; color: #fff;">
|
||||
|
||||
Reference in New Issue
Block a user