Begin migration to registration codes
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
8e0b928f27
commit
70c9aa2b1e
@ -1,14 +1,14 @@
|
|||||||
Complete your OwlBoard (Staff) Registration using the link below.
|
Complete your OwlBoard (Staff) Registration by entering your six digit code.
|
||||||
|
|
||||||
https://owlboard.info/more/reg/submit?key=>>ACCESSCODE<<
|
>>ACCESSCODE<<
|
||||||
|
|
||||||
Alternatively you can copy and paste the above link into your browser.
|
Use the same browser you wish to use OwlBoard with
|
||||||
|
|
||||||
You can also view a QR code to register on another device: https://barcodes.fjla.uk/generate?type=qr&text=https%3A%2F%2Fowlboard.info%2Fmore%2Freg%2Fsubmit%3Fkey%3D>>ACCESSCODE<<
|
Visit https://owlboard.info/more/reg/submit to enter your key
|
||||||
|
|
||||||
Watch support videos or leave a message on our Facebook page: https://facebook.com/owlboard.support
|
Watch support videos or leave a message on our Facebook page: https://facebook.com/owlboard.support
|
||||||
|
|
||||||
If you did not request to register to OwlBoard then you can safely ignore this email.
|
If you did not request to register to OwlBoard then you can safely ignore this email.
|
||||||
Your email address has not been stored by us and will not be required unless you wish to register again.
|
Your email address has not been stored by us and will not be required unless you wish to register again.
|
||||||
|
|
||||||
The link will expire after 4 hours.
|
The link will expire after 1 hour.
|
@ -6,7 +6,36 @@ const domains = require("../configs/domains.configs");
|
|||||||
const errors = require("../configs/errorCodes.configs");
|
const errors = require("../configs/errorCodes.configs");
|
||||||
|
|
||||||
import { logger } from "../utils/logger.utils";
|
import { logger } from "../utils/logger.utils";
|
||||||
|
import { getDomainFromEmail } from "../utils/sanitizer.utils";
|
||||||
|
import { valid as validDomains } from "../configs/domains.configs";
|
||||||
|
import { generateCode } from "../utils/auth.utils";
|
||||||
|
|
||||||
|
async function createRegKey(body) {
|
||||||
|
logger.debug("registerServices.createRegKey: Incoming request");
|
||||||
|
if (body.email) {
|
||||||
|
const domain = getDomainFromEmail(body.email);
|
||||||
|
logger.info(`registerServices: Registration request from: ${domain}`);
|
||||||
|
if (validDomains.includes(domain)) {
|
||||||
|
logger.debug(`registerServices.createRegKey: Key from valid: ${domain}`);
|
||||||
|
const key = generateCode()
|
||||||
|
const message = await auth.generateConfirmationEmail(body.email, key);
|
||||||
|
if (!message) {
|
||||||
|
const err = new Error("Message Generation Error");
|
||||||
|
logger.error(err, "registerServices.createRegKey: Error generating email");
|
||||||
|
return 500;
|
||||||
|
}
|
||||||
|
if ((await mail.send(message)) == true) {
|
||||||
|
return {status: 201, message: "email sent"};
|
||||||
|
}
|
||||||
|
return {status:500, errorCode:950, errorMsg: errors[950]}
|
||||||
|
}
|
||||||
|
return { status: 403, errorCode: 702, errorMsg: errors[702] };
|
||||||
|
} else {
|
||||||
|
return { status: 400, errorCode: 901, errorMsg: errors[902] };
|
||||||
|
}
|
||||||
|
} // NEXT-- UPDATE EMAIL TEMPLATE TO ACCEPT SIX DIGIT CODE RATHER THAN UUID - HTML TEMPLATE NEEDS COMPLETELY REDOING
|
||||||
|
|
||||||
|
/* OLD FUNCTION
|
||||||
async function createRegKey(body) {
|
async function createRegKey(body) {
|
||||||
logger.debug("registerServices.createRegKey: Incoming request");
|
logger.debug("registerServices.createRegKey: Incoming request");
|
||||||
if (body.email) {
|
if (body.email) {
|
||||||
@ -35,6 +64,7 @@ async function createRegKey(body) {
|
|||||||
return { status: 400, errorCode: 901, errorMsg: errors[902] };
|
return { status: 400, errorCode: 901, errorMsg: errors[902] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
async function regUser(req) {
|
async function regUser(req) {
|
||||||
// Add input validation
|
// Add input validation
|
||||||
|
@ -38,6 +38,12 @@ async function generateKey() {
|
|||||||
return crypt.randomUUID();
|
return crypt.randomUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function generateCode(): string {
|
||||||
|
const bytes = crypt.randomBytes(3);
|
||||||
|
const randomNumber = bytes.readUIntBE(0, 3) % 1000000;
|
||||||
|
return randomNumber.toString().padStart(6, '0');
|
||||||
|
}
|
||||||
|
|
||||||
async function generateConfirmationEmail(eml: string, uuid: string) {
|
async function generateConfirmationEmail(eml: string, uuid: string) {
|
||||||
try {
|
try {
|
||||||
const htmlTpl = await fs.readFile("mail-templates/register.html", "utf-8");
|
const htmlTpl = await fs.readFile("mail-templates/register.html", "utf-8");
|
||||||
|
Loading…
Reference in New Issue
Block a user