Template
mirror of
https://github.com/egmont11/ASP.Net-Core-MVC-Template.git
synced 2026-07-24 07:09:56 +02:00
Fixed up the database connection, added admin account and admin area
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TemplateWeb.Models.DbModels;
|
||||
|
||||
namespace TemplateWeb.Data;
|
||||
|
||||
public static class DataSeeder
|
||||
{
|
||||
public static async Task SeedAdminUser(AppDbContext context)
|
||||
{
|
||||
// Only run if no users exist
|
||||
if (await context.Users.AnyAsync())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var admin = new UserModel
|
||||
{
|
||||
UserName = "admin",
|
||||
Email = "admin@template.com",
|
||||
Password = BCrypt.Net.BCrypt.HashPassword("Admin123!"), // You should change this on first login
|
||||
Role = UserRole.Admin
|
||||
};
|
||||
|
||||
await context.Users.AddAsync(admin);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user