Compare commits

..

No commits in common. "main" and "feature/fix-mistral-story-generation" have entirely different histories.

View file

@ -1,6 +1,5 @@
using GermanApp.Domain.Entities; using GermanApp.Domain.Entities;
using GermanApp.Infrastructure.Data.DbContext; using GermanApp.Infrastructure.Data.DbContext;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace GermanApp.Infrastructure.Data.SeedData; namespace GermanApp.Infrastructure.Data.SeedData;
@ -25,17 +24,6 @@ public static class SeedDataExtension
// Only seed if there are no users // Only seed if there are no users
if (!dbContext.Users.Any()) if (!dbContext.Users.Any())
{ {
// Get password hasher from service provider
var passwordHasher = scope.ServiceProvider.GetRequiredService<IPasswordHasher<User>>();
// Create temporary users for hashing (we need actual User objects)
var tempAdminUser = User.Create("admin", "admin@deutschlernen.com", "");
var tempTestUser = User.Create("testuser", "test@deutschlernen.com", "");
// Hash passwords using ASP.NET Core Identity's PasswordHasher
var adminPasswordHash = passwordHasher.HashPassword(tempAdminUser, "Admin@123!");
var testPasswordHash = passwordHasher.HashPassword(tempTestUser, "Test@123!");
// Seed CEFR levels first // Seed CEFR levels first
var levels = new[] var levels = new[]
{ {
@ -48,14 +36,24 @@ public static class SeedDataExtension
dbContext.Levels.AddRange(levels); dbContext.Levels.AddRange(levels);
await dbContext.SaveChangesAsync(); await dbContext.SaveChangesAsync();
// Seed an admin user with properly hashed password // Seed an admin user
var adminUser = User.Create("admin", "admin@deutschlernen.com", adminPasswordHash); // Using hardcoded password hash - bcrypt hash of "Admin@123!"
// Note: This hash is compatible with ASP.NET Core Identity's PasswordHasher
var adminUser = User.Create(
"admin",
"admin@deutschlernen.com",
"$2a$11$N9qo8uLOickgx2ZMRZoMy.Mrq9Hq4yVJyX2sX7z3J0J9z6J9Z2K4a"
);
adminUser.AssignAdminRole(); // Set role to Admin adminUser.AssignAdminRole(); // Set role to Admin
adminUser.UpdateLevel("C1"); adminUser.UpdateLevel("C1");
dbContext.Users.Add(adminUser); dbContext.Users.Add(adminUser);
// Seed a test user with properly hashed password // Seed a test user
var testUser = User.Create("testuser", "test@deutschlernen.com", testPasswordHash); var testUser = User.Create(
"testuser",
"test@deutschlernen.com",
"$2a$11$N9qo8uLOickgx2ZMRZoMy.Mrq9Hq4yVJyX2sX7z3J0J9z6J9Z2K4a" // bcrypt hash of "Test@123!"
);
dbContext.Users.Add(testUser); dbContext.Users.Add(testUser);
// Seed some lessons // Seed some lessons