Registration and activation

This commit is contained in:
Torsten Schulz
2024-07-20 20:43:18 +02:00
parent 3880a265eb
commit bbf4a2deb3
51 changed files with 3016 additions and 69 deletions

16
backend/utils/crypto.js Normal file
View File

@@ -0,0 +1,16 @@
import crypto from 'crypto';
const algorithm = 'aes-256-ctr';
const secretKey = process.env.SECRET_KEY;
export const encrypt = (text) => {
const cipher = crypto.createCipheriv(algorithm, secretKey, Buffer.alloc(16, 0));
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
return encrypted.toString('hex');
};
export const decrypt = (hash) => {
const decipher = crypto.createDecipheriv(algorithm, secretKey, Buffer.alloc(16, 0));
const decrpyted = Buffer.concat([decipher.update(Buffer.from(hash, 'hex')), decipher.final()]);
return decrpyted.toString();
};

22
backend/utils/i18n.js Normal file
View File

@@ -0,0 +1,22 @@
import i18n from 'i18n';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
i18n.configure({
locales: ['en', 'de'],
directory: path.join(__dirname, '../locales'),
defaultLocale: 'de',
register: global,
autoReload: true,
syncFiles: true,
cookie: 'lang',
api: {
'__': 'translate',
'__n': 'translateN'
}
});
export default i18n;

View File

@@ -0,0 +1,10 @@
import UserParamType from '../models/type/user_param.js';
const initializeTypes = async () => {
await UserParamType.findOrCreate({
where: { description: 'language' },
defaults: { description: 'language' }
});
};
export default initializeTypes;

View File

@@ -0,0 +1,7 @@
{
"Password Reset": "Passwort zurücksetzen",
"Please click the following link to reset your password: {{resetLink}}": "Bitte klicken Sie auf den folgenden Link, um Ihr Passwort zurückzusetzen: {{resetLink}}",
"Account Activation": "Kontoaktivierung",
"Please click the following link to activate your account: {{activationLink}}": "Bitte klicken Sie auf den folgenden Link, um Ihr Konto zu aktivieren: {{activationLink}}",
"welcome": "Willkommen!"
}

View File

@@ -0,0 +1,7 @@
{
"Password Reset": "Password Reset",
"Please click the following link to reset your password: {{resetLink}}": "Please click the following link to reset your password: {{resetLink}}",
"Account Activation": "Account Activation",
"Please click the following link to activate your account: {{activationLink}}": "Please click the following link to activate your account: {{activationLink}}",
"welcome": "Welcome!"
}

View File

@@ -0,0 +1,26 @@
import { Sequelize } from 'sequelize';
import dotenv from 'dotenv';
dotenv.config();
const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, {
host: process.env.DB_HOST,
dialect: 'postgres',
define: {
timestamps: false
}
});
const createSchemas = async () => {
await sequelize.query('CREATE SCHEMA IF NOT EXISTS community');
await sequelize.query('CREATE SCHEMA IF NOT EXISTS logs');
await sequelize.query('CREATE SCHEMA IF NOT EXISTS type');
};
const initializeDatabase = async () => {
await createSchemas();
const models = await import('../models/index.js');
await sequelize.sync({ alter: true });
};
export { sequelize, initializeDatabase };

View File

@@ -0,0 +1,14 @@
import { initializeDatabase } from './sequelize.js';
import initializeTypes from './initializeTypes.js';
const syncDatabase = async () => {
try {
await initializeDatabase();
await initializeTypes();
console.log('All models were synchronized successfully.');
} catch (error) {
console.error('Unable to synchronize the database:', error);
}
};
export { syncDatabase };