email confirm template, fix admin login, try fix translation error logs

This commit is contained in:
Dobromir Popov
2024-04-30 13:18:38 +03:00
parent 5135a95db7
commit f303ae193c
5 changed files with 106 additions and 43 deletions

View File

@ -697,30 +697,30 @@ exports.copyToClipboard = function (event, text) {
exports.getUser = async function (req) {
// Use req if provided (server-side), otherwise call getSession without args (client-side)
const session = req ? await getSession({ req }) : await getSession();
return session?.user;
}
// exports.getUser = async function (req) {
// // Use req if provided (server-side), otherwise call getSession without args (client-side)
// const session = req ? await getSession({ req }) : await getSession();
// return session?.user;
// }
exports.isUserInRole = async function (req, allowedRoles = []) {
const user = await exports.getUser(req);
// exports.isUserInRole = function (req, allowedRoles = []) {
// const user = exports.getUser(req);
// Check if the user is authenticated
if (!user) {
return false;
}
// // Check if the user is authenticated
// if (!user) {
// return false;
// }
// If no specific roles are required, return true as the user is authenticated
if (allowedRoles.length === 0) {
return true;
}
// // If no specific roles are required, return true as the user is authenticated
// if (allowedRoles.length === 0) {
// return true;
// }
// Check if the user's role is among the allowed roles
// Ensure role exists and is a valid UserRole
const userRole = user.role;
return allowedRoles.includes(userRole);
}
// // Check if the user's role is among the allowed roles
// // Ensure role exists and is a valid UserRole
// const userRole = user.role;
// return allowedRoles.includes(userRole);
// }
@ -762,6 +762,37 @@ exports.getInitials = function (names) {
exports.addMinutes = function (date, minutes) {
return new Date(date.getTime() + minutes * 60000); // 60000 milliseconds in a minute
}
/**
* Recursively converts all Date objects in an object to ISO strings.
* @param {Object} obj - The object to convert.
* @returns {Object} - The new object with all Date objects converted to ISO strings.
*/
exports.convertDatesToISOStrings = function (obj) {
if (obj === null || obj === undefined) {
return obj;
}
if (obj instanceof Date) {
return obj.toISOString();
}
if (Array.isArray(obj)) {
return obj.map(exports.convertDatesToISOStrings);
}
if (typeof obj === 'object') {
const keys = Object.keys(obj);
return keys.reduce((acc, key) => {
acc[key] = exports.convertDatesToISOStrings(obj[key]);
return acc;
}, {});
}
return obj;
}
// exports.getInitials = function (names) {
// const parts = names.split(' '); // Split the full name into parts
// if (parts.length === 0) {

View File

@ -0,0 +1,23 @@
{{!-- Subject: ССОМ: Нужен е заместник--}}
{{!-- Text: Plain text version of your email. If not provided, HTML tags will be stripped from the HTML version for the
text version. --}}
<section>
<h3>Добре дошъл</h3>
<p>Здравей, {{firstName}} {{lastName}}</p>
<p>
Моля, потвърди своя имейл адрес, като кликнеш на бутона по-долу.
</p>
<p style="text-align: center;">
<a href="{{resetUrl}}"
target="_blank"
style="background-color: #4CAF50; color: white; padding: 10px 20px; text-decoration: none; display: inline-block; border-radius: 5px;">
ОК
</a>
</p>
{{!-- <p>Thank you very much for considering my request.</p>
<p>Best regards,<br>{{name}}</p> --}}
</section>
<footer style="margin-top: 20px; text-align: center;">
<p>Изпратено на: {{sentDate}}</p>
</footer>