first commit: Complete phishing test management panel with Node.js backend and React frontend
This commit is contained in:
183
backend/seeders/001-seed-initial-data.js
Normal file
183
backend/seeders/001-seed-initial-data.js
Normal file
@@ -0,0 +1,183 @@
|
||||
const bcrypt = require('bcrypt');
|
||||
const { Company, AdminUser, MailTemplate } = require('../src/models');
|
||||
require('dotenv').config();
|
||||
|
||||
async function up() {
|
||||
try {
|
||||
console.log('🌱 Seeding initial data...');
|
||||
|
||||
// 1. Create admin user
|
||||
const hashedPassword = await bcrypt.hash(
|
||||
process.env.ADMIN_PASSWORD || 'admin123',
|
||||
10
|
||||
);
|
||||
|
||||
await AdminUser.findOrCreate({
|
||||
where: { id: 1 },
|
||||
defaults: {
|
||||
id: 1,
|
||||
username: process.env.ADMIN_USERNAME || 'admin',
|
||||
password_hash: hashedPassword,
|
||||
},
|
||||
});
|
||||
console.log('✅ Admin user created');
|
||||
|
||||
// 2. Create sample companies
|
||||
const companies = [
|
||||
{
|
||||
name: 'Türk Telekom',
|
||||
description: 'Telekomünikasyon şirketi test kampanyası',
|
||||
industry: 'Telecom',
|
||||
},
|
||||
{
|
||||
name: 'İş Bankası',
|
||||
description: 'Bankacılık sektörü test kampanyası',
|
||||
industry: 'Banking',
|
||||
},
|
||||
{
|
||||
name: 'PTT',
|
||||
description: 'Kargo ve posta test kampanyası',
|
||||
industry: 'Government',
|
||||
},
|
||||
];
|
||||
|
||||
for (const company of companies) {
|
||||
await Company.findOrCreate({
|
||||
where: { name: company.name },
|
||||
defaults: company,
|
||||
});
|
||||
}
|
||||
console.log('✅ Sample companies created');
|
||||
|
||||
// 3. Create mail templates
|
||||
const templates = [
|
||||
{
|
||||
name: 'Banka Güvenlik Bildirimi',
|
||||
template_type: 'bank',
|
||||
subject_template: '{{company_name}} - Acil Güvenlik Bildirimi',
|
||||
body_html: `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
|
||||
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
|
||||
.header { background: #003d7a; color: white; padding: 20px; text-align: center; }
|
||||
.content { padding: 30px; background: #f9f9f9; }
|
||||
.button { display: inline-block; padding: 15px 30px; background: #e31e24; color: white; text-decoration: none; border-radius: 5px; margin: 20px 0; }
|
||||
.footer { padding: 20px; text-align: center; font-size: 12px; color: #666; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>{{company_name}}</h1>
|
||||
<p>Güvenlik Bildirimi</p>
|
||||
</div>
|
||||
<div class="content">
|
||||
{{#if employee_name}}
|
||||
<p>Sayın {{employee_name}},</p>
|
||||
{{else}}
|
||||
<p>Sayın Müşterimiz,</p>
|
||||
{{/if}}
|
||||
|
||||
<p>Hesabınızda olağandışı bir aktivite tespit edildi. Güvenliğiniz için hesabınızı derhal doğrulamanız gerekmektedir.</p>
|
||||
|
||||
<p><strong>Tespit Edilen Sorun:</strong> Yetkisiz giriş denemesi</p>
|
||||
<p><strong>Tarih:</strong> {{current_date}}</p>
|
||||
|
||||
<p>Hesabınızı güvende tutmak için lütfen aşağıdaki butona tıklayarak kimliğinizi doğrulayın:</p>
|
||||
|
||||
<center>
|
||||
<a href="{{tracking_url}}" class="button">Hesabımı Doğrula</a>
|
||||
</center>
|
||||
|
||||
<p><strong>Uyarı:</strong> Bu işlemi 24 saat içinde tamamlamazsanız, hesabınız güvenlik nedeniyle geçici olarak askıya alınacaktır.</p>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<p>© {{current_year}} {{company_name}}. Tüm hakları saklıdır.</p>
|
||||
<p>Bu bir otomatik mesajdır, lütfen yanıtlamayınız.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`,
|
||||
description: 'Banka güvenlik bildirimi şablonu',
|
||||
},
|
||||
{
|
||||
name: 'E-Devlet Kimlik Doğrulama',
|
||||
template_type: 'edevlet',
|
||||
subject_template: 'E-Devlet - Kimlik Doğrulama Gerekli',
|
||||
body_html: `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
|
||||
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
|
||||
.header { background: #c00; color: white; padding: 20px; text-align: center; }
|
||||
.content { padding: 30px; background: #f9f9f9; }
|
||||
.button { display: inline-block; padding: 15px 30px; background: #c00; color: white; text-decoration: none; border-radius: 5px; margin: 20px 0; }
|
||||
.footer { padding: 20px; text-align: center; font-size: 12px; color: #666; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>🇹🇷 E-DEVLET KAPISI</h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
{{#if employee_name}}
|
||||
<p>Sayın {{employee_name}},</p>
|
||||
{{else}}
|
||||
<p>Sayın Vatandaşımız,</p>
|
||||
{{/if}}
|
||||
|
||||
<p>E-Devlet hesabınızla ilgili güvenlik güncellemesi yapılması gerekmektedir.</p>
|
||||
|
||||
<p><strong>Güncelleme Sebebi:</strong> Yeni güvenlik protokolü</p>
|
||||
<p><strong>Son Tarih:</strong> 48 saat</p>
|
||||
|
||||
<p>Hesabınızı aktif tutmak için lütfen kimliğinizi doğrulayın:</p>
|
||||
|
||||
<center>
|
||||
<a href="{{tracking_url}}" class="button">Kimliğimi Doğrula</a>
|
||||
</center>
|
||||
|
||||
<p>Bu işlemi tamamlamazsanız, bazı e-devlet hizmetlerine erişiminiz kısıtlanabilir.</p>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<p>© {{current_year}} T.C. Cumhurbaşkanlığı Dijital Dönüşüm Ofisi</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`,
|
||||
description: 'E-Devlet kimlik doğrulama şablonu',
|
||||
},
|
||||
];
|
||||
|
||||
for (const template of templates) {
|
||||
await MailTemplate.findOrCreate({
|
||||
where: { template_type: template.template_type },
|
||||
defaults: template,
|
||||
});
|
||||
}
|
||||
console.log('✅ Mail templates created');
|
||||
|
||||
console.log('\n✨ Seeding completed successfully!');
|
||||
} catch (error) {
|
||||
console.error('❌ Error seeding data:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function down() {
|
||||
// Not implemented - be careful!
|
||||
console.log('⚠️ Seed rollback not implemented');
|
||||
}
|
||||
|
||||
module.exports = { up, down };
|
||||
|
||||
Reference in New Issue
Block a user