summaryrefslogtreecommitdiff
path: root/Models
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2022-11-17 22:42:00 -0600
committerHombreLaser <sebastian-440@live.com>2022-11-17 22:42:00 -0600
commita0a29f96b62a02b116006f07a66153e577b26150 (patch)
tree7f37f1e1e4c177ad6a03f28d0afb8fe993e3732c /Models
parentb80110ef61cac593320b5232c1f256a8797f8098 (diff)
Añadido seeding de la base de datos
Diffstat (limited to 'Models')
-rw-r--r--Models/ApplicationDbContext.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/Models/ApplicationDbContext.cs b/Models/ApplicationDbContext.cs
index a6a63a8..d2b8d26 100644
--- a/Models/ApplicationDbContext.cs
+++ b/Models/ApplicationDbContext.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
+using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
namespace BackendPIA.Models {
@@ -10,6 +11,21 @@ namespace BackendPIA.Models {
protected override void OnModelCreating(ModelBuilder builder) {
base.OnModelCreating(builder);
+ Guid user_id = Guid.NewGuid();
+ Guid role_id = Guid.NewGuid();
+ var hasher = new PasswordHasher<UserAccount>();
+ UserAccount user_seed = new UserAccount { Id = user_id.ToString(), UserName = "admin", Email = "admin@example.com",
+ NormalizedEmail = "ADMIN@EXAMPLE.COM", NormalizedUserName = "ADMIN" };
+ // TODO: save the seeded admin password in a user secret.
+ user_seed.PasswordHash = hasher.HashPassword(user_seed, "admin_password");
+ builder.Entity<UserAccount>().HasData(user_seed);
+ builder.Entity<IdentityRole>().HasData(new IdentityRole {
+ Name = "Administrator",
+ NormalizedName = "ADMINISTRATOR",
+ Id = role_id.ToString(),
+ ConcurrencyStamp = role_id.ToString()
+ });
+ builder.Entity<IdentityUserRole<string>>().HasData(new IdentityUserRole<string> { UserId = user_id.ToString(), RoleId = role_id.ToString() });
}
}
}