Registration and activation
This commit is contained in:
16
backend/utils/crypto.js
Normal file
16
backend/utils/crypto.js
Normal 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
22
backend/utils/i18n.js
Normal 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;
|
||||
10
backend/utils/initializeTypes.js
Normal file
10
backend/utils/initializeTypes.js
Normal 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;
|
||||
7
backend/utils/locales/de.json
Normal file
7
backend/utils/locales/de.json
Normal 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!"
|
||||
}
|
||||
7
backend/utils/locales/en.json
Normal file
7
backend/utils/locales/en.json
Normal 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!"
|
||||
}
|
||||
26
backend/utils/sequelize.js
Normal file
26
backend/utils/sequelize.js
Normal 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 };
|
||||
14
backend/utils/syncDatabase.js
Normal file
14
backend/utils/syncDatabase.js
Normal 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 };
|
||||
Reference in New Issue
Block a user