email confirm template, fix admin login, try fix translation error logs
This commit is contained in:
@ -117,16 +117,16 @@ export default function App({ Component, pageProps: { session, ...pageProps }, }
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build time localization. Is it working for _app.tsx?d
|
// build time localization. Is it working for _app.tsx?d
|
||||||
// export async function getStaticProps(context) {
|
export async function getStaticProps(context) {
|
||||||
// const messages = (await import(`../content/i18n/${locale}.json`)).default;
|
const messages = (await import(`../content/i18n/${context.locale}.json`)).default;
|
||||||
// console.log("Loaded messages for locale:", locale, messages);
|
console.log("Loaded messages for locale:", context.locale, messages);
|
||||||
// return {
|
return {
|
||||||
// props: {
|
props: {
|
||||||
// // You can get the messages from anywhere you like. The recommended
|
// You can get the messages from anywhere you like. The recommended
|
||||||
// // pattern is to put them in JSON files separated by locale and read
|
// pattern is to put them in JSON files separated by locale and read
|
||||||
// // the desired one based on the `locale` received from Next.js.
|
// the desired one based on the `locale` received from Next.js.
|
||||||
// // messages: (await import(`../content/i18n/${context.locale}.json`)).default
|
// messages: (await import(`../content/i18n/${context.locale}.json`)).default
|
||||||
// messages
|
messages
|
||||||
// }
|
}
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
@ -65,7 +65,7 @@ export default function SignIn({ csrfToken }) {
|
|||||||
<label htmlFor="email" className="block text-sm font-medium text-gray-700">имейл</label>
|
<label htmlFor="email" className="block text-sm font-medium text-gray-700">имейл</label>
|
||||||
<input
|
<input
|
||||||
id="email"
|
id="email"
|
||||||
type="email"
|
type="text" // allow non-email addresses for username (admins)
|
||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
|
className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import axiosServer from '../../../../src/axiosServer';
|
import axiosServer from '../../../../src/axiosServer';
|
||||||
import NewPubPage from "../new";
|
import NewPubPage from "../new";
|
||||||
|
const common = require('../../../../src/helpers/common');
|
||||||
export default NewPubPage;
|
export default NewPubPage;
|
||||||
|
|
||||||
import { Assignment, Shift, UserRole, AvailabilityType } from "prisma/prisma-client";
|
import { Assignment, Shift, UserRole, AvailabilityType } from "prisma/prisma-client";
|
||||||
@ -40,6 +41,8 @@ function getShiftGroups(shifts: [Shift]) {
|
|||||||
export const getServerSideProps = async (context) => {
|
export const getServerSideProps = async (context) => {
|
||||||
const axios = await axiosServer(context);
|
const axios = await axiosServer(context);
|
||||||
|
|
||||||
|
const prisma = common.getPrismaClient();
|
||||||
|
|
||||||
// const isAdmin = await ProtectedRoute.IsInRole(UserRole.ADMIN); does not work on server side
|
// const isAdmin = await ProtectedRoute.IsInRole(UserRole.ADMIN); does not work on server side
|
||||||
context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate");
|
context.res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate");
|
||||||
if (!context.query || !context.query.id) {
|
if (!context.query || !context.query.id) {
|
||||||
@ -47,13 +50,20 @@ export const getServerSideProps = async (context) => {
|
|||||||
props: {}
|
props: {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var url = process.env.NEXT_PUBLIC_PUBLIC_URL + "/api/data/publishers/" + context.query.id + "?include=availabilities,assignments,assignments.shift";
|
const item = await prisma.publisher.findUnique({
|
||||||
console.log("GET PUBLISHER FROM:" + url)
|
where: {
|
||||||
try {
|
id: context.query.id
|
||||||
const { data: item } = await axios.get(url);
|
},
|
||||||
} catch (error) {
|
include: {
|
||||||
console.log("error fetching publisher: " + error);
|
availabilities: true,
|
||||||
//redirect to message page with message "no account found". get user from session
|
assignments: {
|
||||||
|
include: {
|
||||||
|
shift: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!item) {
|
||||||
const user = context.req.session.user;
|
const user = context.req.session.user;
|
||||||
return {
|
return {
|
||||||
redirect: {
|
redirect: {
|
||||||
@ -62,7 +72,6 @@ export const getServerSideProps = async (context) => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// item.allShifts = item.assignments.map((a: Assignment[]) => a.shift);
|
// item.allShifts = item.assignments.map((a: Assignment[]) => a.shift);
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
@ -113,7 +122,7 @@ export const getServerSideProps = async (context) => {
|
|||||||
// console.dir(item, { depth: null });
|
// console.dir(item, { depth: null });
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
item: item
|
item: common.convertDatesToISOStrings(item),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -697,30 +697,30 @@ exports.copyToClipboard = function (event, text) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports.getUser = async function (req) {
|
// exports.getUser = async function (req) {
|
||||||
// Use req if provided (server-side), otherwise call getSession without args (client-side)
|
// // Use req if provided (server-side), otherwise call getSession without args (client-side)
|
||||||
const session = req ? await getSession({ req }) : await getSession();
|
// const session = req ? await getSession({ req }) : await getSession();
|
||||||
return session?.user;
|
// return session?.user;
|
||||||
}
|
// }
|
||||||
|
|
||||||
exports.isUserInRole = async function (req, allowedRoles = []) {
|
// exports.isUserInRole = function (req, allowedRoles = []) {
|
||||||
const user = await exports.getUser(req);
|
// const user = exports.getUser(req);
|
||||||
|
|
||||||
// Check if the user is authenticated
|
// // Check if the user is authenticated
|
||||||
if (!user) {
|
// if (!user) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// If no specific roles are required, return true as the user is authenticated
|
// // If no specific roles are required, return true as the user is authenticated
|
||||||
if (allowedRoles.length === 0) {
|
// if (allowedRoles.length === 0) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Check if the user's role is among the allowed roles
|
// // Check if the user's role is among the allowed roles
|
||||||
// Ensure role exists and is a valid UserRole
|
// // Ensure role exists and is a valid UserRole
|
||||||
const userRole = user.role;
|
// const userRole = user.role;
|
||||||
return allowedRoles.includes(userRole);
|
// return allowedRoles.includes(userRole);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -762,6 +762,37 @@ exports.getInitials = function (names) {
|
|||||||
exports.addMinutes = function (date, minutes) {
|
exports.addMinutes = function (date, minutes) {
|
||||||
return new Date(date.getTime() + minutes * 60000); // 60000 milliseconds in a minute
|
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) {
|
// exports.getInitials = function (names) {
|
||||||
// const parts = names.split(' '); // Split the full name into parts
|
// const parts = names.split(' '); // Split the full name into parts
|
||||||
// if (parts.length === 0) {
|
// if (parts.length === 0) {
|
||||||
|
23
src/templates/emails/emailConfirm.hbs
Normal file
23
src/templates/emails/emailConfirm.hbs
Normal 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>
|
Reference in New Issue
Block a user