From 7d08078681f6a949aa4eccebcb6d4d3eea71ed22 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 11 Jan 2024 14:51:02 +0100 Subject: [PATCH] Fix migration x ruoi e users --- MagMan.Data.Admin/MagMan.Data.Admin.csproj | 4 + .../20231222165912_CreateIdentitySchema.cs | 20 +- .../20240110191326_AddAdminUsers.cs | 108 -------- ...0240111134425_AddUserAndRoles.Designer.cs} | 121 ++++++--- .../20240111134425_AddUserAndRoles.cs | 238 ++++++++++++++++++ .../UserIdentityDbContextModelSnapshot.cs | 117 ++++++--- MagMan.Data.Admin/ModelBuilderExtensions.cs | 125 ++++----- MagMan.Data.Admin/UserAdminConfiguration.cs | 2 - MagMan.UI/Program.cs | 17 +- 9 files changed, 499 insertions(+), 253 deletions(-) delete mode 100644 MagMan.Data.Admin/Migrations/UserIdentityDb/20240110191326_AddAdminUsers.cs rename MagMan.Data.Admin/Migrations/UserIdentityDb/{20240110191326_AddAdminUsers.Designer.cs => 20240111134425_AddUserAndRoles.Designer.cs} (71%) create mode 100644 MagMan.Data.Admin/Migrations/UserIdentityDb/20240111134425_AddUserAndRoles.cs diff --git a/MagMan.Data.Admin/MagMan.Data.Admin.csproj b/MagMan.Data.Admin/MagMan.Data.Admin.csproj index ed44c6a..9f1f0f3 100644 --- a/MagMan.Data.Admin/MagMan.Data.Admin.csproj +++ b/MagMan.Data.Admin/MagMan.Data.Admin.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/MagMan.Data.Admin/Migrations/UserIdentityDb/20231222165912_CreateIdentitySchema.cs b/MagMan.Data.Admin/Migrations/UserIdentityDb/20231222165912_CreateIdentitySchema.cs index 6855671..43c489f 100644 --- a/MagMan.Data.Admin/Migrations/UserIdentityDb/20231222165912_CreateIdentitySchema.cs +++ b/MagMan.Data.Admin/Migrations/UserIdentityDb/20231222165912_CreateIdentitySchema.cs @@ -207,16 +207,16 @@ namespace MagMan.Data.Admin.Migrations.UserIdentityDb }) .Annotation("MySql:CharSet", "utf8mb4"); - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[,] - { - { "86a8f484-ca14-4e4d-a786-3eba35da6e06", "9dd579c3-bdfa-4c44-b6ca-6dd10d34debb", "Admin", "ADMIN" }, - { "ca44b425-5c7e-4812-a28a-047ec6aa2e68", "a1357889-6a23-49cb-9d33-6bc5ef6eb4e6", "User", "USER" }, - { "eebed9c1-7433-4716-a62f-df9829dc0f09", "4a1affe9-543f-4165-816a-2ed6d3f06c77", "Undef", "UNDEF" }, - { "f5bd74e5-df26-4c52-963e-2d87e858c4d6", "1d620875-05b0-490d-91d5-6f21a83844f1", "SuperAdmin", "SUPERADMIN" } - }); + //migrationBuilder.InsertData( + // table: "AspNetRoles", + // columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + // values: new object[,] + // { + // { "86a8f484-ca14-4e4d-a786-3eba35da6e06", "9dd579c3-bdfa-4c44-b6ca-6dd10d34debb", "Admin", "ADMIN" }, + // { "ca44b425-5c7e-4812-a28a-047ec6aa2e68", "a1357889-6a23-49cb-9d33-6bc5ef6eb4e6", "User", "USER" }, + // { "eebed9c1-7433-4716-a62f-df9829dc0f09", "4a1affe9-543f-4165-816a-2ed6d3f06c77", "Undef", "UNDEF" }, + // { "f5bd74e5-df26-4c52-963e-2d87e858c4d6", "1d620875-05b0-490d-91d5-6f21a83844f1", "SuperAdmin", "SUPERADMIN" } + // }); migrationBuilder.CreateIndex( name: "IX_AspNetRoleClaims_RoleId", diff --git a/MagMan.Data.Admin/Migrations/UserIdentityDb/20240110191326_AddAdminUsers.cs b/MagMan.Data.Admin/Migrations/UserIdentityDb/20240110191326_AddAdminUsers.cs deleted file mode 100644 index f21124d..0000000 --- a/MagMan.Data.Admin/Migrations/UserIdentityDb/20240110191326_AddAdminUsers.cs +++ /dev/null @@ -1,108 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace MagMan.Data.Admin.Migrations.UserIdentityDb -{ - public partial class AddAdminUsers : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "86a8f484-ca14-4e4d-a786-3eba35da6e06"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "ca44b425-5c7e-4812-a28a-047ec6aa2e68"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "eebed9c1-7433-4716-a62f-df9829dc0f09"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "f5bd74e5-df26-4c52-963e-2d87e858c4d6"); - - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[,] - { - { "1801b4d3-a3ab-436f-bbed-55f8c4b89983", "7aab1a8a-9e20-4efa-b834-9e0f838aacca", "SuperAdmin", "SUPERADMIN" }, - { "7c07039d-d3ff-43fe-984d-02ea05aeafc5", "cc48e427-2257-4e65-95d0-c38f0a25c709", "User", "USER" }, - { "9965697b-1037-4d89-a614-a65973e043d8", "bc772167-9a2a-4941-a50d-aad3cf078935", "Admin", "ADMIN" }, - { "fa0c3b99-c349-4bc8-ac1a-0b3a54836606", "4375c3da-178e-487c-b8b5-e9fa33cdb5a6", "Undef", "UNDEF" } - }); - - migrationBuilder.InsertData( - table: "AspNetUsers", - columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UserName" }, - values: new object[,] - { - { "0e44f66d-7732-4bfb-906f-8366a5c11c82", 0, "ab4e278a-56fe-4bb1-9bdc-de3301051fe5", "samuele.locatelli@egalware.com", true, false, null, "SAMUELE.LOCATELLI@EGALWARE.COM", "SAMUELE.LOCATELLI@EGALWARE.COM", "AQAAAAEAACcQAAAAEPlfw7DdLxpYGXaTaQRY+oX3SKYjwTEa9r5CbARq1j0/Lb/+bjQrdtwMacdESNSxNA==", null, false, "64fada2f-b4bc-4031-8e7f-af6dac79be2c", false, "samuele.locatelli@egalware.com" }, - { "7bd1ed01-d411-4d1c-a9ed-f6fd8a0d423f", 0, "116163f8-04f2-4cc8-b4c3-0d9cc724e70a", "emmanuele.sassi@egalware.com", true, false, null, "EMMANUELE.SASSI@EGALWARE.COM", "EMMANUELE.SASSI@EGALWARE.COM", "AQAAAAEAACcQAAAAEHPh2ecQ7KYFjcoZdKDBGzvnmRkRGhem1taRzemW+rHC82BbspjZSOPBLxo8Mv6PxA==", null, false, "e2057192-9382-4fa0-b46e-fba00a39c3e6", false, "emmanuele.sassi@egalware.com" }, - { "9cfe4df1-eba1-4c93-9080-3d38c0b0a531", 0, "6c340a92-3c67-465b-bead-5c9bbf28d0e3", "info@egalware.com", true, false, null, "INFO@EGALWARE.COM", "INFO@EGALWARE.COM", "AQAAAAEAACcQAAAAEKwaXyFs3L6ngAdhUBgYRs9uDx/+g6WGw/c65e1Kc2zpwAss3hnmor0QliVlX1nq4g==", null, false, "b461e7d1-fd3b-4f4f-943c-9d83f0f049fd", false, "info@egalware.com" }, - { "d6839d87-44a7-4a63-8b09-82f911beaf46", 0, "cdfc8ca8-41e9-41b0-8a00-57a2759aa229", "luca.mazzoleni@egalware.com", true, false, null, "LUCA.MAZZOLENI@EGALWARE.COM", "LUCA.MAZZOLENI@EGALWARE.COM", "AQAAAAEAACcQAAAAELbX3cLuZNm3QchPWc1CS0pogvDU366M8odvag0LqDQ98In9nR+NxTUx4bq0MzlGGg==", null, false, "564659e1-c707-4c4b-8b4c-802bda981209", false, "luca.mazzoleni@egalware.com" } - }); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "1801b4d3-a3ab-436f-bbed-55f8c4b89983"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "7c07039d-d3ff-43fe-984d-02ea05aeafc5"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "9965697b-1037-4d89-a614-a65973e043d8"); - - migrationBuilder.DeleteData( - table: "AspNetRoles", - keyColumn: "Id", - keyValue: "fa0c3b99-c349-4bc8-ac1a-0b3a54836606"); - - migrationBuilder.DeleteData( - table: "AspNetUsers", - keyColumn: "Id", - keyValue: "0e44f66d-7732-4bfb-906f-8366a5c11c82"); - - migrationBuilder.DeleteData( - table: "AspNetUsers", - keyColumn: "Id", - keyValue: "7bd1ed01-d411-4d1c-a9ed-f6fd8a0d423f"); - - migrationBuilder.DeleteData( - table: "AspNetUsers", - keyColumn: "Id", - keyValue: "9cfe4df1-eba1-4c93-9080-3d38c0b0a531"); - - migrationBuilder.DeleteData( - table: "AspNetUsers", - keyColumn: "Id", - keyValue: "d6839d87-44a7-4a63-8b09-82f911beaf46"); - - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[,] - { - { "86a8f484-ca14-4e4d-a786-3eba35da6e06", "9dd579c3-bdfa-4c44-b6ca-6dd10d34debb", "Admin", "ADMIN" }, - { "ca44b425-5c7e-4812-a28a-047ec6aa2e68", "a1357889-6a23-49cb-9d33-6bc5ef6eb4e6", "User", "USER" }, - { "eebed9c1-7433-4716-a62f-df9829dc0f09", "4a1affe9-543f-4165-816a-2ed6d3f06c77", "Undef", "UNDEF" }, - { "f5bd74e5-df26-4c52-963e-2d87e858c4d6", "1d620875-05b0-490d-91d5-6f21a83844f1", "SuperAdmin", "SUPERADMIN" } - }); - } - } -} diff --git a/MagMan.Data.Admin/Migrations/UserIdentityDb/20240110191326_AddAdminUsers.Designer.cs b/MagMan.Data.Admin/Migrations/UserIdentityDb/20240111134425_AddUserAndRoles.Designer.cs similarity index 71% rename from MagMan.Data.Admin/Migrations/UserIdentityDb/20240110191326_AddAdminUsers.Designer.cs rename to MagMan.Data.Admin/Migrations/UserIdentityDb/20240111134425_AddUserAndRoles.Designer.cs index 8af51a6..6130fde 100644 --- a/MagMan.Data.Admin/Migrations/UserIdentityDb/20240110191326_AddAdminUsers.Designer.cs +++ b/MagMan.Data.Admin/Migrations/UserIdentityDb/20240111134425_AddUserAndRoles.Designer.cs @@ -11,8 +11,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace MagMan.Data.Admin.Migrations.UserIdentityDb { [DbContext(typeof(UserIdentityDbContext))] - [Migration("20240110191326_AddAdminUsers")] - partial class AddAdminUsers + [Migration("20240111134425_AddUserAndRoles")] + partial class AddUserAndRoles { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -61,29 +61,29 @@ namespace MagMan.Data.Admin.Migrations.UserIdentityDb b.HasData( new { - Id = "fa0c3b99-c349-4bc8-ac1a-0b3a54836606", - ConcurrencyStamp = "4375c3da-178e-487c-b8b5-e9fa33cdb5a6", + Id = "82b54f2b-4da8-4e46-83bf-57ffc17cf8ed", + ConcurrencyStamp = "763dedf1-0868-424e-bc0a-1572a548c1d7", Name = "Undef", NormalizedName = "UNDEF" }, new { - Id = "7c07039d-d3ff-43fe-984d-02ea05aeafc5", - ConcurrencyStamp = "cc48e427-2257-4e65-95d0-c38f0a25c709", + Id = "34ae910e-acaf-46d1-aaa8-279a74c5bc61", + ConcurrencyStamp = "8b90b548-3d22-40c6-95ba-c3fb0ea032a7", Name = "User", NormalizedName = "USER" }, new { - Id = "9965697b-1037-4d89-a614-a65973e043d8", - ConcurrencyStamp = "bc772167-9a2a-4941-a50d-aad3cf078935", + Id = "8352aca0-c5e8-4a2d-be76-f6cde5f963a1", + ConcurrencyStamp = "63d84be1-17ac-4e8c-9bd7-35e0ed056533", Name = "Admin", NormalizedName = "ADMIN" }, new { - Id = "1801b4d3-a3ab-436f-bbed-55f8c4b89983", - ConcurrencyStamp = "7aab1a8a-9e20-4efa-b834-9e0f838aacca", + Id = "285df363-706d-498e-b1ad-4680e141ad01", + ConcurrencyStamp = "365f0dc5-81c1-4deb-945b-58dd8fc9d18a", Name = "SuperAdmin", NormalizedName = "SUPERADMIN" }); @@ -178,65 +178,65 @@ namespace MagMan.Data.Admin.Migrations.UserIdentityDb b.HasData( new { - Id = "0e44f66d-7732-4bfb-906f-8366a5c11c82", + Id = "3fac0523-697f-4b42-ac39-82026839ba2c", AccessFailedCount = 0, - ConcurrencyStamp = "ab4e278a-56fe-4bb1-9bdc-de3301051fe5", + ConcurrencyStamp = "b23608ab-d50a-464d-8db2-8274f088b0ad", Email = "samuele.locatelli@egalware.com", EmailConfirmed = true, LockoutEnabled = false, NormalizedEmail = "SAMUELE.LOCATELLI@EGALWARE.COM", NormalizedUserName = "SAMUELE.LOCATELLI@EGALWARE.COM", - PasswordHash = "AQAAAAEAACcQAAAAEPlfw7DdLxpYGXaTaQRY+oX3SKYjwTEa9r5CbARq1j0/Lb/+bjQrdtwMacdESNSxNA==", + PasswordHash = "AQAAAAEAACcQAAAAEAQsxwpx5DzxcFhzIhUciCtBEHZo/GLlB4HtG49I3gTh/WtXSg9VVl0e5KBmopG9VQ==", PhoneNumberConfirmed = false, - SecurityStamp = "64fada2f-b4bc-4031-8e7f-af6dac79be2c", + SecurityStamp = "8f4ecdd7-9078-4345-82bc-7c1570e71387", TwoFactorEnabled = false, UserName = "samuele.locatelli@egalware.com" }, new { - Id = "7bd1ed01-d411-4d1c-a9ed-f6fd8a0d423f", + Id = "238a34e8-7a80-4307-bfcc-41bdc4a39c1f", AccessFailedCount = 0, - ConcurrencyStamp = "116163f8-04f2-4cc8-b4c3-0d9cc724e70a", + ConcurrencyStamp = "f62ab486-c4e0-450a-8fb4-6905d2e3da64", Email = "emmanuele.sassi@egalware.com", EmailConfirmed = true, LockoutEnabled = false, NormalizedEmail = "EMMANUELE.SASSI@EGALWARE.COM", NormalizedUserName = "EMMANUELE.SASSI@EGALWARE.COM", - PasswordHash = "AQAAAAEAACcQAAAAEHPh2ecQ7KYFjcoZdKDBGzvnmRkRGhem1taRzemW+rHC82BbspjZSOPBLxo8Mv6PxA==", + PasswordHash = "AQAAAAEAACcQAAAAECZ2BzJe3VOrXIgdmjBrD+JP/HqsV/eFwMO4DaGzAmFPvHG+xxkRFbwRkI2sYoWt8Q==", PhoneNumberConfirmed = false, - SecurityStamp = "e2057192-9382-4fa0-b46e-fba00a39c3e6", + SecurityStamp = "1be739d4-3aed-4a9a-a5c0-80c45a1474a6", TwoFactorEnabled = false, UserName = "emmanuele.sassi@egalware.com" }, new { - Id = "d6839d87-44a7-4a63-8b09-82f911beaf46", + Id = "be261afb-580a-4cb6-a040-c4a335f9ff3a", AccessFailedCount = 0, - ConcurrencyStamp = "cdfc8ca8-41e9-41b0-8a00-57a2759aa229", + ConcurrencyStamp = "9c306ce8-ec94-49b9-ad24-87b3d9937188", Email = "luca.mazzoleni@egalware.com", EmailConfirmed = true, LockoutEnabled = false, NormalizedEmail = "LUCA.MAZZOLENI@EGALWARE.COM", NormalizedUserName = "LUCA.MAZZOLENI@EGALWARE.COM", - PasswordHash = "AQAAAAEAACcQAAAAELbX3cLuZNm3QchPWc1CS0pogvDU366M8odvag0LqDQ98In9nR+NxTUx4bq0MzlGGg==", + PasswordHash = "AQAAAAEAACcQAAAAEHdDRZVkzBW4qlCF+vvpURb/4bj/b2/kl4+HSEjhbHRAekqX5WMnfJfWMPuyjKrgUg==", PhoneNumberConfirmed = false, - SecurityStamp = "564659e1-c707-4c4b-8b4c-802bda981209", + SecurityStamp = "121bb662-adf9-4cba-bbc8-12bf1d2bc693", TwoFactorEnabled = false, UserName = "luca.mazzoleni@egalware.com" }, new { - Id = "9cfe4df1-eba1-4c93-9080-3d38c0b0a531", + Id = "3282b9f4-5240-4946-a8d0-5570df880642", AccessFailedCount = 0, - ConcurrencyStamp = "6c340a92-3c67-465b-bead-5c9bbf28d0e3", + ConcurrencyStamp = "20720e13-89b3-4660-8c6e-1f11e1e730b4", Email = "info@egalware.com", EmailConfirmed = true, LockoutEnabled = false, NormalizedEmail = "INFO@EGALWARE.COM", NormalizedUserName = "INFO@EGALWARE.COM", - PasswordHash = "AQAAAAEAACcQAAAAEKwaXyFs3L6ngAdhUBgYRs9uDx/+g6WGw/c65e1Kc2zpwAss3hnmor0QliVlX1nq4g==", + PasswordHash = "AQAAAAEAACcQAAAAEDEuPnbPPl/9vc6xg/mvOmyEfvirN5ZNDWu21im+PjvtNQcqvqfc9k3KQxtJKBs5EQ==", PhoneNumberConfirmed = false, - SecurityStamp = "b461e7d1-fd3b-4f4f-943c-9d83f0f049fd", + SecurityStamp = "3bd9e353-ab86-47b2-85da-d857e618f44e", TwoFactorEnabled = false, UserName = "info@egalware.com" }); @@ -268,10 +268,12 @@ namespace MagMan.Data.Admin.Migrations.UserIdentityDb modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("varchar(255)"); + .HasMaxLength(128) + .HasColumnType("varchar(128)"); b.Property("ProviderKey") - .HasColumnType("varchar(255)"); + .HasMaxLength(128) + .HasColumnType("varchar(128)"); b.Property("ProviderDisplayName") .HasColumnType("longtext"); @@ -300,6 +302,63 @@ namespace MagMan.Data.Admin.Migrations.UserIdentityDb b.HasIndex("RoleId"); b.ToTable("AspNetUserRoles", (string)null); + + b.HasData( + new + { + UserId = "3fac0523-697f-4b42-ac39-82026839ba2c", + RoleId = "34ae910e-acaf-46d1-aaa8-279a74c5bc61" + }, + new + { + UserId = "3fac0523-697f-4b42-ac39-82026839ba2c", + RoleId = "8352aca0-c5e8-4a2d-be76-f6cde5f963a1" + }, + new + { + UserId = "3fac0523-697f-4b42-ac39-82026839ba2c", + RoleId = "285df363-706d-498e-b1ad-4680e141ad01" + }, + new + { + UserId = "238a34e8-7a80-4307-bfcc-41bdc4a39c1f", + RoleId = "34ae910e-acaf-46d1-aaa8-279a74c5bc61" + }, + new + { + UserId = "238a34e8-7a80-4307-bfcc-41bdc4a39c1f", + RoleId = "8352aca0-c5e8-4a2d-be76-f6cde5f963a1" + }, + new + { + UserId = "238a34e8-7a80-4307-bfcc-41bdc4a39c1f", + RoleId = "285df363-706d-498e-b1ad-4680e141ad01" + }, + new + { + UserId = "be261afb-580a-4cb6-a040-c4a335f9ff3a", + RoleId = "34ae910e-acaf-46d1-aaa8-279a74c5bc61" + }, + new + { + UserId = "be261afb-580a-4cb6-a040-c4a335f9ff3a", + RoleId = "8352aca0-c5e8-4a2d-be76-f6cde5f963a1" + }, + new + { + UserId = "be261afb-580a-4cb6-a040-c4a335f9ff3a", + RoleId = "285df363-706d-498e-b1ad-4680e141ad01" + }, + new + { + UserId = "3282b9f4-5240-4946-a8d0-5570df880642", + RoleId = "34ae910e-acaf-46d1-aaa8-279a74c5bc61" + }, + new + { + UserId = "3282b9f4-5240-4946-a8d0-5570df880642", + RoleId = "8352aca0-c5e8-4a2d-be76-f6cde5f963a1" + }); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => @@ -308,10 +367,12 @@ namespace MagMan.Data.Admin.Migrations.UserIdentityDb .HasColumnType("varchar(255)"); b.Property("LoginProvider") - .HasColumnType("varchar(255)"); + .HasMaxLength(128) + .HasColumnType("varchar(128)"); b.Property("Name") - .HasColumnType("varchar(255)"); + .HasMaxLength(128) + .HasColumnType("varchar(128)"); b.Property("Value") .HasColumnType("longtext"); diff --git a/MagMan.Data.Admin/Migrations/UserIdentityDb/20240111134425_AddUserAndRoles.cs b/MagMan.Data.Admin/Migrations/UserIdentityDb/20240111134425_AddUserAndRoles.cs new file mode 100644 index 0000000..ddac416 --- /dev/null +++ b/MagMan.Data.Admin/Migrations/UserIdentityDb/20240111134425_AddUserAndRoles.cs @@ -0,0 +1,238 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace MagMan.Data.Admin.Migrations.UserIdentityDb +{ + public partial class AddUserAndRoles : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Name", + table: "AspNetUserTokens", + type: "varchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "varchar(255)") + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserTokens", + type: "varchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "varchar(255)") + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "ProviderKey", + table: "AspNetUserLogins", + type: "varchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "varchar(255)") + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserLogins", + type: "varchar(128)", + maxLength: 128, + nullable: false, + oldClrType: typeof(string), + oldType: "varchar(255)") + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.InsertData( + table: "AspNetRoles", + columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, + values: new object[,] + { + { "285df363-706d-498e-b1ad-4680e141ad01", "365f0dc5-81c1-4deb-945b-58dd8fc9d18a", "SuperAdmin", "SUPERADMIN" }, + { "34ae910e-acaf-46d1-aaa8-279a74c5bc61", "8b90b548-3d22-40c6-95ba-c3fb0ea032a7", "User", "USER" }, + { "82b54f2b-4da8-4e46-83bf-57ffc17cf8ed", "763dedf1-0868-424e-bc0a-1572a548c1d7", "Undef", "UNDEF" }, + { "8352aca0-c5e8-4a2d-be76-f6cde5f963a1", "63d84be1-17ac-4e8c-9bd7-35e0ed056533", "Admin", "ADMIN" } + }); + + migrationBuilder.InsertData( + table: "AspNetUsers", + columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UserName" }, + values: new object[,] + { + { "238a34e8-7a80-4307-bfcc-41bdc4a39c1f", 0, "f62ab486-c4e0-450a-8fb4-6905d2e3da64", "emmanuele.sassi@egalware.com", true, false, null, "EMMANUELE.SASSI@EGALWARE.COM", "EMMANUELE.SASSI@EGALWARE.COM", "AQAAAAEAACcQAAAAECZ2BzJe3VOrXIgdmjBrD+JP/HqsV/eFwMO4DaGzAmFPvHG+xxkRFbwRkI2sYoWt8Q==", null, false, "1be739d4-3aed-4a9a-a5c0-80c45a1474a6", false, "emmanuele.sassi@egalware.com" }, + { "3282b9f4-5240-4946-a8d0-5570df880642", 0, "20720e13-89b3-4660-8c6e-1f11e1e730b4", "info@egalware.com", true, false, null, "INFO@EGALWARE.COM", "INFO@EGALWARE.COM", "AQAAAAEAACcQAAAAEDEuPnbPPl/9vc6xg/mvOmyEfvirN5ZNDWu21im+PjvtNQcqvqfc9k3KQxtJKBs5EQ==", null, false, "3bd9e353-ab86-47b2-85da-d857e618f44e", false, "info@egalware.com" }, + { "3fac0523-697f-4b42-ac39-82026839ba2c", 0, "b23608ab-d50a-464d-8db2-8274f088b0ad", "samuele.locatelli@egalware.com", true, false, null, "SAMUELE.LOCATELLI@EGALWARE.COM", "SAMUELE.LOCATELLI@EGALWARE.COM", "AQAAAAEAACcQAAAAEAQsxwpx5DzxcFhzIhUciCtBEHZo/GLlB4HtG49I3gTh/WtXSg9VVl0e5KBmopG9VQ==", null, false, "8f4ecdd7-9078-4345-82bc-7c1570e71387", false, "samuele.locatelli@egalware.com" }, + { "be261afb-580a-4cb6-a040-c4a335f9ff3a", 0, "9c306ce8-ec94-49b9-ad24-87b3d9937188", "luca.mazzoleni@egalware.com", true, false, null, "LUCA.MAZZOLENI@EGALWARE.COM", "LUCA.MAZZOLENI@EGALWARE.COM", "AQAAAAEAACcQAAAAEHdDRZVkzBW4qlCF+vvpURb/4bj/b2/kl4+HSEjhbHRAekqX5WMnfJfWMPuyjKrgUg==", null, false, "121bb662-adf9-4cba-bbc8-12bf1d2bc693", false, "luca.mazzoleni@egalware.com" } + }); + + migrationBuilder.InsertData( + table: "AspNetUserRoles", + columns: new[] { "RoleId", "UserId" }, + values: new object[,] + { + { "285df363-706d-498e-b1ad-4680e141ad01", "238a34e8-7a80-4307-bfcc-41bdc4a39c1f" }, + { "34ae910e-acaf-46d1-aaa8-279a74c5bc61", "238a34e8-7a80-4307-bfcc-41bdc4a39c1f" }, + { "8352aca0-c5e8-4a2d-be76-f6cde5f963a1", "238a34e8-7a80-4307-bfcc-41bdc4a39c1f" }, + { "34ae910e-acaf-46d1-aaa8-279a74c5bc61", "3282b9f4-5240-4946-a8d0-5570df880642" }, + { "8352aca0-c5e8-4a2d-be76-f6cde5f963a1", "3282b9f4-5240-4946-a8d0-5570df880642" }, + { "285df363-706d-498e-b1ad-4680e141ad01", "3fac0523-697f-4b42-ac39-82026839ba2c" }, + { "34ae910e-acaf-46d1-aaa8-279a74c5bc61", "3fac0523-697f-4b42-ac39-82026839ba2c" }, + { "8352aca0-c5e8-4a2d-be76-f6cde5f963a1", "3fac0523-697f-4b42-ac39-82026839ba2c" }, + { "285df363-706d-498e-b1ad-4680e141ad01", "be261afb-580a-4cb6-a040-c4a335f9ff3a" }, + { "34ae910e-acaf-46d1-aaa8-279a74c5bc61", "be261afb-580a-4cb6-a040-c4a335f9ff3a" }, + { "8352aca0-c5e8-4a2d-be76-f6cde5f963a1", "be261afb-580a-4cb6-a040-c4a335f9ff3a" } + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "82b54f2b-4da8-4e46-83bf-57ffc17cf8ed"); + + migrationBuilder.DeleteData( + table: "AspNetUserRoles", + keyColumns: new[] { "RoleId", "UserId" }, + keyValues: new object[] { "285df363-706d-498e-b1ad-4680e141ad01", "238a34e8-7a80-4307-bfcc-41bdc4a39c1f" }); + + migrationBuilder.DeleteData( + table: "AspNetUserRoles", + keyColumns: new[] { "RoleId", "UserId" }, + keyValues: new object[] { "34ae910e-acaf-46d1-aaa8-279a74c5bc61", "238a34e8-7a80-4307-bfcc-41bdc4a39c1f" }); + + migrationBuilder.DeleteData( + table: "AspNetUserRoles", + keyColumns: new[] { "RoleId", "UserId" }, + keyValues: new object[] { "8352aca0-c5e8-4a2d-be76-f6cde5f963a1", "238a34e8-7a80-4307-bfcc-41bdc4a39c1f" }); + + migrationBuilder.DeleteData( + table: "AspNetUserRoles", + keyColumns: new[] { "RoleId", "UserId" }, + keyValues: new object[] { "34ae910e-acaf-46d1-aaa8-279a74c5bc61", "3282b9f4-5240-4946-a8d0-5570df880642" }); + + migrationBuilder.DeleteData( + table: "AspNetUserRoles", + keyColumns: new[] { "RoleId", "UserId" }, + keyValues: new object[] { "8352aca0-c5e8-4a2d-be76-f6cde5f963a1", "3282b9f4-5240-4946-a8d0-5570df880642" }); + + migrationBuilder.DeleteData( + table: "AspNetUserRoles", + keyColumns: new[] { "RoleId", "UserId" }, + keyValues: new object[] { "285df363-706d-498e-b1ad-4680e141ad01", "3fac0523-697f-4b42-ac39-82026839ba2c" }); + + migrationBuilder.DeleteData( + table: "AspNetUserRoles", + keyColumns: new[] { "RoleId", "UserId" }, + keyValues: new object[] { "34ae910e-acaf-46d1-aaa8-279a74c5bc61", "3fac0523-697f-4b42-ac39-82026839ba2c" }); + + migrationBuilder.DeleteData( + table: "AspNetUserRoles", + keyColumns: new[] { "RoleId", "UserId" }, + keyValues: new object[] { "8352aca0-c5e8-4a2d-be76-f6cde5f963a1", "3fac0523-697f-4b42-ac39-82026839ba2c" }); + + migrationBuilder.DeleteData( + table: "AspNetUserRoles", + keyColumns: new[] { "RoleId", "UserId" }, + keyValues: new object[] { "285df363-706d-498e-b1ad-4680e141ad01", "be261afb-580a-4cb6-a040-c4a335f9ff3a" }); + + migrationBuilder.DeleteData( + table: "AspNetUserRoles", + keyColumns: new[] { "RoleId", "UserId" }, + keyValues: new object[] { "34ae910e-acaf-46d1-aaa8-279a74c5bc61", "be261afb-580a-4cb6-a040-c4a335f9ff3a" }); + + migrationBuilder.DeleteData( + table: "AspNetUserRoles", + keyColumns: new[] { "RoleId", "UserId" }, + keyValues: new object[] { "8352aca0-c5e8-4a2d-be76-f6cde5f963a1", "be261afb-580a-4cb6-a040-c4a335f9ff3a" }); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "285df363-706d-498e-b1ad-4680e141ad01"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "34ae910e-acaf-46d1-aaa8-279a74c5bc61"); + + migrationBuilder.DeleteData( + table: "AspNetRoles", + keyColumn: "Id", + keyValue: "8352aca0-c5e8-4a2d-be76-f6cde5f963a1"); + + migrationBuilder.DeleteData( + table: "AspNetUsers", + keyColumn: "Id", + keyValue: "238a34e8-7a80-4307-bfcc-41bdc4a39c1f"); + + migrationBuilder.DeleteData( + table: "AspNetUsers", + keyColumn: "Id", + keyValue: "3282b9f4-5240-4946-a8d0-5570df880642"); + + migrationBuilder.DeleteData( + table: "AspNetUsers", + keyColumn: "Id", + keyValue: "3fac0523-697f-4b42-ac39-82026839ba2c"); + + migrationBuilder.DeleteData( + table: "AspNetUsers", + keyColumn: "Id", + keyValue: "be261afb-580a-4cb6-a040-c4a335f9ff3a"); + + migrationBuilder.AlterColumn( + name: "Name", + table: "AspNetUserTokens", + type: "varchar(255)", + nullable: false, + oldClrType: typeof(string), + oldType: "varchar(128)", + oldMaxLength: 128) + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserTokens", + type: "varchar(255)", + nullable: false, + oldClrType: typeof(string), + oldType: "varchar(128)", + oldMaxLength: 128) + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "ProviderKey", + table: "AspNetUserLogins", + type: "varchar(255)", + nullable: false, + oldClrType: typeof(string), + oldType: "varchar(128)", + oldMaxLength: 128) + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "LoginProvider", + table: "AspNetUserLogins", + type: "varchar(255)", + nullable: false, + oldClrType: typeof(string), + oldType: "varchar(128)", + oldMaxLength: 128) + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + } + } +} diff --git a/MagMan.Data.Admin/Migrations/UserIdentityDb/UserIdentityDbContextModelSnapshot.cs b/MagMan.Data.Admin/Migrations/UserIdentityDb/UserIdentityDbContextModelSnapshot.cs index bfa0cd0..25ed42d 100644 --- a/MagMan.Data.Admin/Migrations/UserIdentityDb/UserIdentityDbContextModelSnapshot.cs +++ b/MagMan.Data.Admin/Migrations/UserIdentityDb/UserIdentityDbContextModelSnapshot.cs @@ -59,29 +59,29 @@ namespace MagMan.Data.Admin.Migrations.UserIdentityDb b.HasData( new { - Id = "fa0c3b99-c349-4bc8-ac1a-0b3a54836606", - ConcurrencyStamp = "4375c3da-178e-487c-b8b5-e9fa33cdb5a6", + Id = "82b54f2b-4da8-4e46-83bf-57ffc17cf8ed", + ConcurrencyStamp = "763dedf1-0868-424e-bc0a-1572a548c1d7", Name = "Undef", NormalizedName = "UNDEF" }, new { - Id = "7c07039d-d3ff-43fe-984d-02ea05aeafc5", - ConcurrencyStamp = "cc48e427-2257-4e65-95d0-c38f0a25c709", + Id = "34ae910e-acaf-46d1-aaa8-279a74c5bc61", + ConcurrencyStamp = "8b90b548-3d22-40c6-95ba-c3fb0ea032a7", Name = "User", NormalizedName = "USER" }, new { - Id = "9965697b-1037-4d89-a614-a65973e043d8", - ConcurrencyStamp = "bc772167-9a2a-4941-a50d-aad3cf078935", + Id = "8352aca0-c5e8-4a2d-be76-f6cde5f963a1", + ConcurrencyStamp = "63d84be1-17ac-4e8c-9bd7-35e0ed056533", Name = "Admin", NormalizedName = "ADMIN" }, new { - Id = "1801b4d3-a3ab-436f-bbed-55f8c4b89983", - ConcurrencyStamp = "7aab1a8a-9e20-4efa-b834-9e0f838aacca", + Id = "285df363-706d-498e-b1ad-4680e141ad01", + ConcurrencyStamp = "365f0dc5-81c1-4deb-945b-58dd8fc9d18a", Name = "SuperAdmin", NormalizedName = "SUPERADMIN" }); @@ -176,65 +176,65 @@ namespace MagMan.Data.Admin.Migrations.UserIdentityDb b.HasData( new { - Id = "0e44f66d-7732-4bfb-906f-8366a5c11c82", + Id = "3fac0523-697f-4b42-ac39-82026839ba2c", AccessFailedCount = 0, - ConcurrencyStamp = "ab4e278a-56fe-4bb1-9bdc-de3301051fe5", + ConcurrencyStamp = "b23608ab-d50a-464d-8db2-8274f088b0ad", Email = "samuele.locatelli@egalware.com", EmailConfirmed = true, LockoutEnabled = false, NormalizedEmail = "SAMUELE.LOCATELLI@EGALWARE.COM", NormalizedUserName = "SAMUELE.LOCATELLI@EGALWARE.COM", - PasswordHash = "AQAAAAEAACcQAAAAEPlfw7DdLxpYGXaTaQRY+oX3SKYjwTEa9r5CbARq1j0/Lb/+bjQrdtwMacdESNSxNA==", + PasswordHash = "AQAAAAEAACcQAAAAEAQsxwpx5DzxcFhzIhUciCtBEHZo/GLlB4HtG49I3gTh/WtXSg9VVl0e5KBmopG9VQ==", PhoneNumberConfirmed = false, - SecurityStamp = "64fada2f-b4bc-4031-8e7f-af6dac79be2c", + SecurityStamp = "8f4ecdd7-9078-4345-82bc-7c1570e71387", TwoFactorEnabled = false, UserName = "samuele.locatelli@egalware.com" }, new { - Id = "7bd1ed01-d411-4d1c-a9ed-f6fd8a0d423f", + Id = "238a34e8-7a80-4307-bfcc-41bdc4a39c1f", AccessFailedCount = 0, - ConcurrencyStamp = "116163f8-04f2-4cc8-b4c3-0d9cc724e70a", + ConcurrencyStamp = "f62ab486-c4e0-450a-8fb4-6905d2e3da64", Email = "emmanuele.sassi@egalware.com", EmailConfirmed = true, LockoutEnabled = false, NormalizedEmail = "EMMANUELE.SASSI@EGALWARE.COM", NormalizedUserName = "EMMANUELE.SASSI@EGALWARE.COM", - PasswordHash = "AQAAAAEAACcQAAAAEHPh2ecQ7KYFjcoZdKDBGzvnmRkRGhem1taRzemW+rHC82BbspjZSOPBLxo8Mv6PxA==", + PasswordHash = "AQAAAAEAACcQAAAAECZ2BzJe3VOrXIgdmjBrD+JP/HqsV/eFwMO4DaGzAmFPvHG+xxkRFbwRkI2sYoWt8Q==", PhoneNumberConfirmed = false, - SecurityStamp = "e2057192-9382-4fa0-b46e-fba00a39c3e6", + SecurityStamp = "1be739d4-3aed-4a9a-a5c0-80c45a1474a6", TwoFactorEnabled = false, UserName = "emmanuele.sassi@egalware.com" }, new { - Id = "d6839d87-44a7-4a63-8b09-82f911beaf46", + Id = "be261afb-580a-4cb6-a040-c4a335f9ff3a", AccessFailedCount = 0, - ConcurrencyStamp = "cdfc8ca8-41e9-41b0-8a00-57a2759aa229", + ConcurrencyStamp = "9c306ce8-ec94-49b9-ad24-87b3d9937188", Email = "luca.mazzoleni@egalware.com", EmailConfirmed = true, LockoutEnabled = false, NormalizedEmail = "LUCA.MAZZOLENI@EGALWARE.COM", NormalizedUserName = "LUCA.MAZZOLENI@EGALWARE.COM", - PasswordHash = "AQAAAAEAACcQAAAAELbX3cLuZNm3QchPWc1CS0pogvDU366M8odvag0LqDQ98In9nR+NxTUx4bq0MzlGGg==", + PasswordHash = "AQAAAAEAACcQAAAAEHdDRZVkzBW4qlCF+vvpURb/4bj/b2/kl4+HSEjhbHRAekqX5WMnfJfWMPuyjKrgUg==", PhoneNumberConfirmed = false, - SecurityStamp = "564659e1-c707-4c4b-8b4c-802bda981209", + SecurityStamp = "121bb662-adf9-4cba-bbc8-12bf1d2bc693", TwoFactorEnabled = false, UserName = "luca.mazzoleni@egalware.com" }, new { - Id = "9cfe4df1-eba1-4c93-9080-3d38c0b0a531", + Id = "3282b9f4-5240-4946-a8d0-5570df880642", AccessFailedCount = 0, - ConcurrencyStamp = "6c340a92-3c67-465b-bead-5c9bbf28d0e3", + ConcurrencyStamp = "20720e13-89b3-4660-8c6e-1f11e1e730b4", Email = "info@egalware.com", EmailConfirmed = true, LockoutEnabled = false, NormalizedEmail = "INFO@EGALWARE.COM", NormalizedUserName = "INFO@EGALWARE.COM", - PasswordHash = "AQAAAAEAACcQAAAAEKwaXyFs3L6ngAdhUBgYRs9uDx/+g6WGw/c65e1Kc2zpwAss3hnmor0QliVlX1nq4g==", + PasswordHash = "AQAAAAEAACcQAAAAEDEuPnbPPl/9vc6xg/mvOmyEfvirN5ZNDWu21im+PjvtNQcqvqfc9k3KQxtJKBs5EQ==", PhoneNumberConfirmed = false, - SecurityStamp = "b461e7d1-fd3b-4f4f-943c-9d83f0f049fd", + SecurityStamp = "3bd9e353-ab86-47b2-85da-d857e618f44e", TwoFactorEnabled = false, UserName = "info@egalware.com" }); @@ -266,10 +266,12 @@ namespace MagMan.Data.Admin.Migrations.UserIdentityDb modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("varchar(255)"); + .HasMaxLength(128) + .HasColumnType("varchar(128)"); b.Property("ProviderKey") - .HasColumnType("varchar(255)"); + .HasMaxLength(128) + .HasColumnType("varchar(128)"); b.Property("ProviderDisplayName") .HasColumnType("longtext"); @@ -298,6 +300,63 @@ namespace MagMan.Data.Admin.Migrations.UserIdentityDb b.HasIndex("RoleId"); b.ToTable("AspNetUserRoles", (string)null); + + b.HasData( + new + { + UserId = "3fac0523-697f-4b42-ac39-82026839ba2c", + RoleId = "34ae910e-acaf-46d1-aaa8-279a74c5bc61" + }, + new + { + UserId = "3fac0523-697f-4b42-ac39-82026839ba2c", + RoleId = "8352aca0-c5e8-4a2d-be76-f6cde5f963a1" + }, + new + { + UserId = "3fac0523-697f-4b42-ac39-82026839ba2c", + RoleId = "285df363-706d-498e-b1ad-4680e141ad01" + }, + new + { + UserId = "238a34e8-7a80-4307-bfcc-41bdc4a39c1f", + RoleId = "34ae910e-acaf-46d1-aaa8-279a74c5bc61" + }, + new + { + UserId = "238a34e8-7a80-4307-bfcc-41bdc4a39c1f", + RoleId = "8352aca0-c5e8-4a2d-be76-f6cde5f963a1" + }, + new + { + UserId = "238a34e8-7a80-4307-bfcc-41bdc4a39c1f", + RoleId = "285df363-706d-498e-b1ad-4680e141ad01" + }, + new + { + UserId = "be261afb-580a-4cb6-a040-c4a335f9ff3a", + RoleId = "34ae910e-acaf-46d1-aaa8-279a74c5bc61" + }, + new + { + UserId = "be261afb-580a-4cb6-a040-c4a335f9ff3a", + RoleId = "8352aca0-c5e8-4a2d-be76-f6cde5f963a1" + }, + new + { + UserId = "be261afb-580a-4cb6-a040-c4a335f9ff3a", + RoleId = "285df363-706d-498e-b1ad-4680e141ad01" + }, + new + { + UserId = "3282b9f4-5240-4946-a8d0-5570df880642", + RoleId = "34ae910e-acaf-46d1-aaa8-279a74c5bc61" + }, + new + { + UserId = "3282b9f4-5240-4946-a8d0-5570df880642", + RoleId = "8352aca0-c5e8-4a2d-be76-f6cde5f963a1" + }); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => @@ -306,10 +365,12 @@ namespace MagMan.Data.Admin.Migrations.UserIdentityDb .HasColumnType("varchar(255)"); b.Property("LoginProvider") - .HasColumnType("varchar(255)"); + .HasMaxLength(128) + .HasColumnType("varchar(128)"); b.Property("Name") - .HasColumnType("varchar(255)"); + .HasMaxLength(128) + .HasColumnType("varchar(128)"); b.Property("Value") .HasColumnType("longtext"); diff --git a/MagMan.Data.Admin/ModelBuilderExtensions.cs b/MagMan.Data.Admin/ModelBuilderExtensions.cs index 5317520..a5d3ccd 100644 --- a/MagMan.Data.Admin/ModelBuilderExtensions.cs +++ b/MagMan.Data.Admin/ModelBuilderExtensions.cs @@ -1,9 +1,11 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using static StackExchange.Redis.Role; namespace MagMan.Data.Admin { @@ -17,73 +19,74 @@ namespace MagMan.Data.Admin /// public static void Seed(this ModelBuilder modelBuilder) { - // inizializzazione dei valori di default x USER -#if false - modelBuilder.Entity().HasData( - new UserModel { UserId = 1, AuthKey = "th1sIsTh3R1vrOfThNgt98", Livello = UserLevel.SuperAdmin, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 0, UserName = "samuele.locatelli", Email = "samuele@steamware.net", Firstname = "Samuele", Lastname = "Locatelli" }, - new UserModel { UserId = 2, AuthKey = "th1sIsTh3R1vrOfThNgt91", Livello = UserLevel.SuperAdmin, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 0, UserName = "giancarlo.rottoli", Email = "giancarlo@steamware.net", Firstname = "Giancarlo", Lastname = "Rottoli" }, - new UserModel { UserId = 3, AuthKey = "th1sIsTh3R1vrOfThNgt93", Livello = UserLevel.SuperAdmin, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 0, UserName = "steamw.admin", Email = "info@steamware.net", Firstname = "Steamware", Lastname = "Admin" }, - new UserModel { UserId = 4, AuthKey = "th1sIsTh3R1vrOfThNgt97", Livello = UserLevel.Admin, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 0, UserName = "angelo.pizzaferri", Email = "a.pizzaferri@pizzaferripetroli.it", Firstname = "Angelo", Lastname = "Pizzaferri" }, - new UserModel { UserId = 5, AuthKey = "th1sIsTh3R1vrOfThNgt99", Livello = UserLevel.Admin, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 0, UserName = "andrei.valeanu", Email = "andrei.valeanu@winnlab.it", Firstname = "Andrei", Lastname = "Valeanu" }, - new UserModel { UserId = 6, AuthKey = "th1sIsTh3R1vrOfThNgt92", Livello = UserLevel.UserExt, MaskPlantId = 0, MaskSupplierId = 1, MaskTranspId = 0, UserName = "liquigas.user01", Email = "info@steamware.net", Firstname = "User", Lastname = "LIQUIGAS" }, - new UserModel { UserId = 7, AuthKey = "th1sIsTh3R1vrOfThNgt94", Livello = UserLevel.UserExt, MaskPlantId = 0, MaskSupplierId = 2, MaskTranspId = 0, UserName = "vulkangas.user01", Email = "info@steamware.net", Firstname = "User", Lastname = "VULKANGAS" }, - new UserModel { UserId = 8, AuthKey = "th1sIsTh3R1vrOfThNgt95", Livello = UserLevel.UserExt, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 1, UserName = "levorato.user01", Email = "info@steamware.net", Firstname = "User", Lastname = "LEVORATO" }, - new UserModel { UserId = 9, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.UserExt, MaskPlantId = 0, MaskSupplierId = 0, MaskTranspId = 2, UserName = "traffik.user01", Email = "info@steamware.net", Firstname = "User", Lastname = "TRAFFIK" }, - new UserModel { UserId = 10, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.User, MaskPlantId = 1, MaskSupplierId = 0, MaskTranspId = 0, UserName = "piz03.user01", Email = "info@steamware.net", Firstname = "Stazione", Lastname = "Collecchio" }, - new UserModel { UserId = 11, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.User, MaskPlantId = 2, MaskSupplierId = 0, MaskTranspId = 0, UserName = "piz04.user01", Email = "info@steamware.net", Firstname = "Stazione", Lastname = "Noceto" }, - new UserModel { UserId = 12, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.User, MaskPlantId = 3, MaskSupplierId = 0, MaskTranspId = 0, UserName = "piz05.user01", Email = "info@steamware.net", Firstname = "Stazione", Lastname = "Baganzola" }, - new UserModel { UserId = 13, AuthKey = "th1sIsTh3R1vrOfThNgt96", Livello = UserLevel.User, MaskPlantId = 4, MaskSupplierId = 0, MaskTranspId = 0, UserName = "piz08.user01", Email = "info@steamware.net", Firstname = "Stazione", Lastname = "Pilastrello" } - ); -#endif + // seed ruoli + List roles = new List() + { + new IdentityRole { Name = "Undef", NormalizedName = "UNDEF" }, + new IdentityRole { Name = "User", NormalizedName = "USER" }, + new IdentityRole { Name = "Admin", NormalizedName = "ADMIN" }, + new IdentityRole { Name = "SuperAdmin", NormalizedName = "SUPERADMIN" } + }; + modelBuilder.Entity().HasData(roles); -#if false - // inizializzazione dei valori di default x Plant - modelBuilder.Entity().HasData( - new PlantDetailModel { PlantId = 1, PlantCode = "PIZ03", PlantDesc = "Collecchio", LevelMax = 26000, LevelReorder = 15000, OrderQtyStd = 18000 }, - new PlantDetailModel { PlantId = 2, PlantCode = "PIZ04", PlantDesc = "Noceto", LevelMax = 28000, LevelReorder = 15000, OrderQtyStd = 18000 }, - new PlantDetailModel { PlantId = 3, PlantCode = "PIZ05", PlantDesc = "Baganzola", LevelMax = 24000, LevelReorder = 15000, OrderQtyStd = 18000 }, - new PlantDetailModel { PlantId = 4, PlantCode = "PIZ08", PlantDesc = "Pilastrello", LevelMax = 26000, LevelReorder = 15000, OrderQtyStd = 18000 }, - new PlantDetailModel { PlantId = 5, PlantCode = "PIZ09", PlantDesc = "Guardamiglio", LevelMax = 26000, LevelReorder = 15000, OrderQtyStd = 18000 } - // new PlantDetailModel { PlantId = 1, PlantCode = "PIZ03", PlantDesc = "Collecchio", LevelMax = 26000, PressMax = 19, PressBHMax = 270, PressBLMax = 270 }, - //new PlantDetailModel { PlantId = 2, PlantCode = "PIZ04", PlantDesc = "Noceto", LevelMax = 28000, PressMax = 19, PressBHMax = 270, PressBLMax = 270 }, - //new PlantDetailModel { PlantId = 3, PlantCode = "PIZ05", PlantDesc = "Baganzola", LevelMax = 24000, PressMax = 19, PressBHMax = 270, PressBLMax = 270 }, - //new PlantDetailModel { PlantId = 4, PlantCode = "PIZ08", PlantDesc = "Pilastrello", LevelMax = 26000, PressMax = 19, PressBHMax = 270, PressBLMax = 270 } - ); -#endif + // seed utenti + List users = new List() + { + // SuperAdmins + getNewUser("samuele.locatelli@egalware.com", "th1sIsTh3R1vrOfThNgt202401"), + getNewUser("emmanuele.sassi@egalware.com", "th1sIsTh3R1vrOfThNgt202402"), + getNewUser("luca.mazzoleni@egalware.com", "th1sIsTh3R1vrOfThNgt202403"), + // Admin egalware base + getNewUser("info@egalware.com", "th1sIsTh3R1vrOfThNgt202404") + }; + modelBuilder.Entity().HasData(users); -#if false - // inizializzazione dei valori di default x Fornitori - modelBuilder.Entity().HasData( - new SupplierModel { SupplierId = 1, SupplierCode = "LIQUIGAS", SupplierDesc = "Liquigas" }, - new SupplierModel { SupplierId = 2, SupplierCode = "VULKANGAS", SupplierDesc = "Vulkangas" } - ); -#endif + List> userRoles = new List>(); -#if false - // inizializzazione dei valori di default x Trasportatori - modelBuilder.Entity().HasData( - new TransporterModel { TransporterId = 1, TransporterCode = "LEVO", TransporterDesc = "Levorato" }, - new TransporterModel { TransporterId = 2, TransporterCode = "TRAF", TransporterDesc = "Traffik" } - ); -#endif + for (int i = 0; i < users.Count; i++) + { + // aggiungo ruoli User ed Admin x tutti + userRoles.Add(new IdentityUserRole + { + UserId = users[i].Id, + RoleId = roles.First(q => q.Name == "User").Id + }); + userRoles.Add(new IdentityUserRole + { + UserId = users[i].Id, + RoleId = roles.First(q => q.Name == "Admin").Id + }); -#if false - // init consegne... - modelBuilder.Entity().HasData( - new WeekPlanModel { WeekPlanId = 1, DayNum = DayOfWeek.Monday, DeliveryHour = 20, Note = "18K", PlantId = 2, SupplierId = 1, TransporterId = 1 }, - new WeekPlanModel { WeekPlanId = 2, DayNum = DayOfWeek.Tuesday, DeliveryHour = 20, Note = "18K", PlantId = 2, SupplierId = 1, TransporterId = 1 }, - new WeekPlanModel { WeekPlanId = 3, DayNum = DayOfWeek.Wednesday, DeliveryHour = 20, Note = "18K", PlantId = 2, SupplierId = 1, TransporterId = 2 }, - new WeekPlanModel { WeekPlanId = 4, DayNum = DayOfWeek.Thursday, DeliveryHour = 15, Note = "9K", PlantId = 2, SupplierId = 1, TransporterId = 1 }, - new WeekPlanModel { WeekPlanId = 5, DayNum = DayOfWeek.Thursday, DeliveryHour = 20, Note = "18K", PlantId = 2, SupplierId = 1, TransporterId = 1 }, - new WeekPlanModel { WeekPlanId = 6, DayNum = DayOfWeek.Saturday, DeliveryHour = 20, Note = "18K", PlantId = 2, SupplierId = 1, TransporterId = 1 }, - new WeekPlanModel { WeekPlanId = 7, DayNum = DayOfWeek.Tuesday, DeliveryHour = 14, Note = "3K", PlantId = 3, SupplierId = 1, TransporterId = 1 }, - new WeekPlanModel { WeekPlanId = 8, DayNum = DayOfWeek.Tuesday, DeliveryHour = 15, Note = "15K", PlantId = 4, SupplierId = 1, TransporterId = 1 }, - new WeekPlanModel { WeekPlanId = 9, DayNum = DayOfWeek.Tuesday, DeliveryHour = 17, Note = "18K", PlantId = 1, SupplierId = 2, TransporterId = 2 } - ); -#endif + // se nei primi 3 aggiungo anche SuperAdmin + if (i < 3) + { + userRoles.Add(new IdentityUserRole + { + UserId = users[i].Id, + RoleId = roles.First(q => q.Name == "SuperAdmin").Id + }); + } + } + modelBuilder.Entity>().HasData(userRoles); } + private static IdentityUser getNewUser(string email, string passwd) + { + var newRec = new IdentityUser + { + UserName = email, + NormalizedUserName = email.ToUpper(), + Email = email, + NormalizedEmail = email.ToUpper(), + EmailConfirmed = true, + PasswordHash = hasher.HashPassword(null!, passwd), + }; + return newRec; + } + + private static PasswordHasher hasher = new PasswordHasher(); + #endregion Public Methods } } diff --git a/MagMan.Data.Admin/UserAdminConfiguration.cs b/MagMan.Data.Admin/UserAdminConfiguration.cs index 3e88be6..608efea 100644 --- a/MagMan.Data.Admin/UserAdminConfiguration.cs +++ b/MagMan.Data.Admin/UserAdminConfiguration.cs @@ -15,8 +15,6 @@ namespace MagMan.Data.Admin public void Configure(EntityTypeBuilder builder) { - PasswordHasher hasher = new PasswordHasher(); - // Default seeded users builder.HasData( // SuperAdmins diff --git a/MagMan.UI/Program.cs b/MagMan.UI/Program.cs index ea7009f..87c4514 100644 --- a/MagMan.UI/Program.cs +++ b/MagMan.UI/Program.cs @@ -20,12 +20,6 @@ using System.Globalization; var builder = WebApplication.CreateBuilder(args); -#if false -// gestione configurazione -var admConnStr = builder.Configuration.GetConnectionString("UserIdentityDbContextConnection") ?? throw new InvalidOperationException("Connection string 'UserIdentityDbContextConnection' not found."); -#endif - - // REDIS setup var redisConnString = builder.Configuration.GetConnectionString("Redis"); string redisSrvAddr = redisConnString.Substring(0, redisConnString.IndexOf(":")); @@ -41,22 +35,17 @@ string dbServerAddr = builder.Configuration["DbConfig:Server"]; string nKey = builder.Configuration["DbConfig:nKey"]; string sKey = builder.Configuration["DbConfig:sKey"]; MagMan.Data.Admin.DbConfig.InitDb(dbServerAddr, nKey, sKey); -#if false -//string admConnStr = MagMan.Data.Admin.DbConfig.ADMIN_CONNECTION_STRING; -#endif string admConnStr = MagMan.Data.Admin.DbConfig.CONNECTION_STRING; -#if false -MagMan.Data.Tenant.DbConfig.InitDb(dbServerAddr, nKey, sKey); -#endif - // inizializzo il DB e creo (se necessario) l'utente MagMan.Data.Admin.DbConfig.CheckUser(nKey, sKey); MagMan.Data.Admin.DbConfig.ExecMigrationIdentity(); string connStringDB = MagMan.Data.Admin.DbConfig.CONNECTION_STRING; + // spostare e fare in caso nelle chiamate custom #if false +MagMan.Data.Tenant.DbConfig.InitDb(dbServerAddr, nKey, sKey); // verifico se serve applicazione migrazioni MagMan.Data.Tenant.DbConfig.ExecMigrationMain(); #endif @@ -69,8 +58,8 @@ builder.Services.AddHealthChecks() .AddProcessAllocatedMemoryHealthCheck(512, "Max Process memory (<512MB)", failureStatus: HealthStatus.Degraded) // 512 MB max allocated memory .AddRedis(builder.Configuration.GetConnectionString("Redis"), "Redis", failureStatus: HealthStatus.Degraded) .AddAsyncCheck($"MySql Root User", () => MagMan.UI.Health.Checks.DbUserRoot("MySql")) + .AddAsyncCheck($"MySql Identity", () => MagMan.UI.Health.Checks.DbIdentity(MagMan.Data.Admin.DbConfig.DATABASE_NAME)) #if false - .AddAsyncCheck($"MySql Identity", () => MagMan.UI.Health.Checks.DbIdentity(DbConfig.DATABASE_NAME)) .AddAsyncCheck($"MySql PlantLog", () => MagMan.UI.Health.Checks.DbPlantTable(DbConfig.DATABASE_NAME)) #endif ;