checkemail end point notification

This commit is contained in:
2026-03-18 16:07:34 +01:00
parent a4407b3e40
commit 1a03e3a519
4 changed files with 436 additions and 0 deletions

View File

@@ -1,4 +1,6 @@
const express = require("express"); const express = require("express");
const fs = require("fs-extra");
const path = require("path");
// Classes // Classes
const Notifications = require("../models/Notifications.js"); const Notifications = require("../models/Notifications.js");
@@ -247,4 +249,56 @@ router.get("/contact", checkHeaders, isAuthenticated, (req, res) => {
res.status(200).json({ data: {} }); res.status(200).json({ data: {} });
}); });
router.get("/checkemail/:email/:digit6", checkHeaders, async (req, res) => {
const { email, digit6 } = req.params;
const tmpDir = path.join(__dirname, "../../../../tmp");
const tmpFile = path.join(tmpDir, email);
if (digit6 === "0") {
const code = Math.floor(100000 + Math.random() * 900000).toString();
fs.ensureDirSync(tmpDir);
fs.writeFileSync(tmpFile, code);
const sendresult = await Notifications.manageemail(
{
emailsto: [{ to: email, code }]
},
"checkemail",
"adminapi",
req.session.header.xlang || "fr",
1,
["anonymous"]
);
res.status(sendresult.status).json(sendresult);
} else {
if (!fs.existsSync(tmpFile)) {
return res.status(404).json({
status: 404,
ref: "Notifications",
msg: "codenotfound",
data: { email }
});
}
const storedCode = fs.readFileSync(tmpFile, "utf8").trim();
if (digit6 === storedCode) {
fs.removeSync(tmpFile);
res.status(200).json({
status: 200,
ref: "Notifications",
msg: "emailverified",
data: { email, verified: true }
});
} else {
res.status(400).json({
status: 400,
ref: "Notifications",
msg: "invalidcode",
data: { email }
});
}
}
});
module.exports = router; module.exports = router;

262
schema/contracts.json Normal file
View File

@@ -0,0 +1,262 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "/schema/contracts",
"title": "Contract",
"description": "Scheduled contracts that can trigger actions (email, push, blockchain, etc.) based on conditions",
"type": "object",
"properties": {
"contractid": {
"title": "Unique identification",
"description": "A unique uuid string identifying a contract",
"type": "string",
"format": "uuid"
},
"owner": {
"title": "Owner of this contract",
"description": "For accessright purpose this is always equal as alias, owner can read, update or cancel",
"type": "string"
},
"status": {
"title": "Contract status",
"description": "todo = pending execution, done = successfully executed, error = failed, cancelled = manually stopped",
"type": "string",
"enum": ["todo", "done", "error", "cancelled"]
},
"tribe": {
"title": "Tribe",
"description": "Tribe ID where this contract belongs and where the rule is defined",
"type": "string"
},
"action": {
"title": "Action to execute",
"description": "Name of the action function to execute (e.g., sendEmail, sendPush, webhook, blockchainWrite)",
"type": "string"
},
"payload": {
"title": "Action payload",
"description": "Data to pass to the action handler",
"type": "object"
},
"rule": {
"title": "Rule function name",
"description": "Name of the rule function in apxtri/Models/Rules.js to evaluate before execution",
"type": "string"
},
"ruleData": {
"title": "Rule data",
"description": "Data object passed to the rule function, which returns {result, error}",
"type": "object"
},
"ruleResult": {
"title": "Rule evaluation result",
"description": "Result returned by the rule function after evaluation",
"type": "object"
},
"ruleError": {
"title": "Rule evaluation error",
"description": "Error message if rule evaluation failed",
"type": "string"
},
"scheduledFor": {
"title": "Scheduled execution date",
"description": "Date and time when the contract should run (YYYYMMDD HH:mm:ss)",
"type": "string"
},
"scheduledDay": {
"title": "Scheduled day for cron filtering",
"description": "Day portion for efficient cron filtering (YYYYMMDD)",
"type": "string"
},
"maxRetries": {
"title": "Maximum retry attempts",
"description": "Number of times to retry on error",
"type": "integer",
"minimum": 0,
"maximum": 10,
"default": 0
},
"retryCount": {
"title": "Current retry count",
"description": "Number of times the contract has been retried",
"type": "integer",
"minimum": 0
},
"result": {
"title": "Execution result",
"description": "Result data after successful execution",
"type": "object"
},
"error": {
"title": "Error message",
"description": "Error message if execution failed",
"type": "string"
},
"datesRun": {
"title": "Execution timestamps",
"description": "Array of timestamps when the contract was executed",
"type": "array",
"items": {
"type": "string"
}
},
"blockchainTxHash": {
"title": "Blockchain transaction hash",
"description": "Transaction hash if action involved blockchain write",
"type": "string"
},
"dt_create": {
"title": "Creation date",
"type": "string",
"format": "date-time"
},
"dt_update": {
"type": "string",
"format": "date-time"
}
},
"required": [
"contractid",
"owner",
"tribe",
"status",
"action"
],
"additionalProperties": true,
"apxref": [],
"apxid": "contractid",
"apxuniquekey": [
"contractid"
],
"apxidx": [
{
"name": "lst_contractid",
"type": "array",
"keyval": "contractid"
},
{
"name": "lst_owner",
"type": "array",
"keyval": "owner"
},
{
"name": "lst_tribe",
"type": "array",
"keyval": "tribe"
},
{
"name": "contractid",
"type": "view",
"keyval": "contractid",
"objkey": [
"contractid",
"owner",
"tribe",
"status",
"action",
"payload",
"rule",
"ruleData",
"ruleResult",
"ruleError",
"scheduledFor",
"scheduledDay",
"maxRetries",
"retryCount",
"result",
"error",
"datesRun",
"blockchainTxHash",
"dt_create",
"dt_update"
],
"filter": ""
},
{
"name": "status_scheduledDay",
"type": "view",
"keyval": "contractid",
"objkey": [
"contractid",
"tribe",
"status",
"action",
"scheduledFor",
"scheduledDay",
"rule",
"ruleData",
"payload",
"owner"
],
"filter": "status=todo"
},
{
"name": "tribe_status",
"type": "distribution",
"keyval": "tribe",
"filter": "status"
},
{
"name": "status_contractid",
"type": "distribution",
"keyval": "status",
"filter": ""
}
],
"apxaccessrights": {
"owner": {
"C": [],
"D": [],
"R": [],
"U": [
"status",
"tribe",
"payload",
"rule",
"ruleData",
"ruleResult",
"ruleError",
"scheduledFor",
"scheduledDay",
"maxRetries",
"result",
"error",
"datesRun",
"blockchainTxHash"
]
},
"druid": {
"R": [
"contractid",
"owner",
"tribe",
"status",
"action",
"payload",
"rule",
"ruleData",
"ruleResult",
"ruleError",
"scheduledFor",
"scheduledDay",
"maxRetries",
"retryCount",
"result",
"error",
"datesRun",
"blockchainTxHash",
"dt_create",
"dt_update"
]
},
"anonymous": {
"R": [
"contractid",
"status",
"action",
"scheduledFor",
"scheduledDay",
"dt_create"
]
}
}
}

60
template/checkemail_en.js Normal file
View File

@@ -0,0 +1,60 @@
const tplemail = {};
tplemail.allowedprofils = ["anonymous", "druid"];
tplemail.subject = "Verification code - Email verification";
tplemail.html = `
<html>
<head>
<meta charset="utf-8">
<style>
body {background-color:#fff;}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0" align="center" style="width: 600px; border: none; padding: 0; background-color:#fff;" width="600">
<tr style="padding:20px 0 0 0; background-color:#fff;">
<td style="border-bottom:1px solid #0DC3FF;" >
<p style="padding:60px 0 10px 0;">
<img width="180px" src="https://smatchit.io/static/img/logo/logoBlackSimple.png" alt="smatchit" />
</p>
</td>
</tr>
<tr>
<td style="padding:20px 0 40px 0;">
<h1 style="font-size:15px;font-family:Monserrat;">Email verification</h1>
<p style="font-size:12px;font-family:Monserrat;">Hello,</p>
<p style="font-size:12px;font-family:Monserrat;">
You requested to verify your email address. Please use the following code to confirm your identity:
</p>
<p style="font-size:24px;font-family:Monserrat;font-weight:bold;text-align:center;padding:20px 0;">
{{code}}
</p>
<p style="font-size:12px;font-family:Monserrat;">
This code is valid for 10 minutes. If you did not request this, you can ignore this email.
</p>
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" align="center" style="width: 600px; border: none; padding: 0;" width="600">
<tr bgcolor="#161616">
<td bgcolor="#161616" align="center" style="padding:20px;">
<p style="text-align:center;">
<img width="250px"src="https://smatchit.io/static/img/logo/logoSignature.png" alt="smatchit">
</p>
</td>
</tr>
</table>
</body>
</html>
`;
tplemail.text = `
Email verification
Hello,
You requested to verify your email address. Please use the following code to confirm your identity:
{{code}}
This code is valid for 10 minutes. If you did not request this, you can ignore this email.
`;
module.exports = tplemail;

60
template/checkemail_fr.js Normal file
View File

@@ -0,0 +1,60 @@
const tplemail = {};
tplemail.allowedprofils = ["anonymous", "druid"];
tplemail.subject = "Code de vérification - Vérification de votre email";
tplemail.html = `
<html>
<head>
<meta charset="utf-8">
<style>
body {background-color:#fff;}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0" align="center" style="width: 600px; border: none; padding: 0; background-color:#fff;" width="600">
<tr style="padding:20px 0 0 0; background-color:#fff;">
<td style="border-bottom:1px solid #0DC3FF;" >
<p style="padding:60px 0 10px 0;">
<img width="180px" src="https://smatchit.io/static/img/logo/logoBlackSimple.png" alt="smatchit" />
</p>
</td>
</tr>
<tr>
<td style="padding:20px 0 40px 0;">
<h1 style="font-size:15px;font-family:Monserrat;">Vérification de votre adresse email</h1>
<p style="font-size:12px;font-family:Monserrat;">Bonjour,</p>
<p style="font-size:12px;font-family:Monserrat;">
Vous avez demandé à vérifier votre adresse email. Veuillez utiliser le code suivant pour confirmer votre identité :
</p>
<p style="font-size:24px;font-family:Monserrat;font-weight:bold;text-align:center;padding:20px 0;">
{{code}}
</p>
<p style="font-size:12px;font-family:Monserrat;">
Ce code est valable pendant 10 minutes. Si vous n'êtes pas à l'origine de cette demande, vous pouvez ignorer cet email.
</p>
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" align="center" style="width: 600px; border: none; padding: 0;" width="600">
<tr bgcolor="#161616">
<td bgcolor="#161616" align="center" style="padding:20px;">
<p style="text-align:center;">
<img width="250px"src="https://smatchit.io/static/img/logo/logoSignature.png" alt="smatchit">
</p>
</td>
</tr>
</table>
</body>
</html>
`;
tplemail.text = `
Vérification de votre adresse email
Bonjour,
Vous avez demandé à vérifier votre adresse email. Veuillez utiliser le code suivant pour confirmer votre identité :
{{code}}
Ce code est valable pendant 10 minutes. Si vous n'êtes pas à l'origine de cette demande, vous pouvez ignorer cet email.
`;
module.exports = tplemail;