Browse Source

Move this site register count into the queue to lighten up the api handler.

master
Zed A. Shaw 1 week ago
parent
commit
8f394a862f
  1. 4
      api/register.js
  2. 4
      queues/mail.js

4
api/register.js

@ -7,7 +7,6 @@ const REGISTER_LIMIT = await Site.get("register_limit");
const REGISTER_LIMIT_ERROR = "Registration is currently closed. Try again later.";
export const post = async (req, res) => {
// TODO: this is kind of weird so find a way to validate but allow one or more fields
let count = await Site.get("registered_count");
if(REGISTER_LIMIT && count >= REGISTER_LIMIT) {
@ -23,10 +22,11 @@ export const post = async (req, res) => {
} else {
req.body.password_repeat = password_repeat;
// TODO: if we do the password here then we can move this into the queue later
let good = await User.register(req.body);
if(good) {
await Site.increment("registered_count", 1);
// remove the password to it's not in the queue
delete good.password;
queues.send_welcome(good);
return res.status(200).json({message: "OK"});

4
queues/mail.js

@ -1,7 +1,7 @@
import logging from '../lib/logging.js';
import { company } from '../emails/config.js';
import { send_email, load_templates, debug_templates } from '../lib/email.js';
import { User, RESET_CODE_SIZE } from "../lib/models.js";
import { User, Site, RESET_CODE_SIZE } from "../lib/models.js";
import assert from "assert";
import differenceInHours from 'date-fns/differenceInHours/index.js';
@ -21,6 +21,8 @@ export const registration = async (job) => {
await debug_templates({text, html}, "register_email");
await Site.increment("registered_count", 1);
// send both txt and html as attachments
send_email({
from: company.mail,

Loading…
Cancel
Save