Fixed Seed User Login
This commit is contained in:
@@ -24,30 +24,8 @@ namespace Data
|
||||
}
|
||||
}
|
||||
|
||||
protected override async void OnModelCreating(ModelBuilder modelBuilder)
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
//string[] roles = { "Admin", "Employee" };
|
||||
|
||||
//foreach (string role in roles)
|
||||
//{
|
||||
// IdentityRole roleToCheck = await this.Roles.FirstOrDefaultAsync(roleToCheck => roleToCheck.Name == role);
|
||||
// if (roleToCheck == null)
|
||||
// {
|
||||
// //this.Roles.Add(new IdentityRole(role));
|
||||
// modelBuilder.Entity<IdentityRole>().HasData(new IdentityRole(role));
|
||||
// }
|
||||
//}
|
||||
|
||||
//PasswordHasher<User> passwordHasher = new PasswordHasher<User>();
|
||||
|
||||
//User initialUser = new User();
|
||||
//initialUser.Id = Guid.NewGuid().ToString();
|
||||
//initialUser.UserName = "admin";
|
||||
//initialUser.PasswordHash = passwordHasher.HashPassword(initialUser, "admin");
|
||||
|
||||
|
||||
//if (this.Users.FirstOrDefaultAsync() != null)
|
||||
//{
|
||||
|
||||
@@ -56,15 +34,35 @@ namespace Data
|
||||
// modelBuilder.Entity<IdentityUserRole<string>>().HasData(new IdentityUserRole<string> {RoleId = adminRole.Id, UserId = initialUser.Id});
|
||||
//}
|
||||
|
||||
PasswordHasher<User> passwordHasher = new PasswordHasher<User>();
|
||||
|
||||
User initialUser = new User()
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
UserName = "admin",
|
||||
Email = "admin@admin.admin",
|
||||
SecurityStamp = Guid.NewGuid().ToString()
|
||||
};
|
||||
initialUser.PasswordHash = passwordHasher.HashPassword(initialUser, "admin123");
|
||||
|
||||
modelBuilder.Entity<User>().HasData(initialUser);
|
||||
string[] roles = { "Admin", "Employee" };
|
||||
|
||||
foreach (string role in roles)
|
||||
{
|
||||
IdentityRole newRole = new IdentityRole(role);
|
||||
newRole.Id = Guid.NewGuid().ToString();
|
||||
modelBuilder.Entity<IdentityRole>().HasData(newRole);
|
||||
IdentityUserRole<string> userRole = new IdentityUserRole<string>();
|
||||
userRole.UserId = initialUser.Id;
|
||||
userRole.RoleId = newRole.Id;
|
||||
modelBuilder.Entity<IdentityUserRole<string>>().HasData(userRole);
|
||||
}
|
||||
|
||||
modelBuilder.Entity<Rents>().HasOne(rents => rents.User);
|
||||
modelBuilder.Entity<Rents>().HasOne(rents => rents.Car);
|
||||
|
||||
modelBuilder.Entity<Car>().HasData(new Car()
|
||||
{
|
||||
Id = 1,
|
||||
Brand = "Trabant"
|
||||
}) ;
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(RentACarDbContext))]
|
||||
[Migration("20220404172708_Changes")]
|
||||
partial class Changes
|
||||
[Migration("20220405155900_Migrena")]
|
||||
partial class Migrena
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
@@ -151,6 +151,21 @@ namespace Data.Migrations
|
||||
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetUsers");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = "5ff048ba-cb37-4966-a7dd-f7b0aa96d730",
|
||||
AccessFailedCount = 0,
|
||||
ConcurrencyStamp = "bd3f3137-a505-4c21-9392-8cc07b1eac1e",
|
||||
Email = "admin@admin.admin",
|
||||
EmailConfirmed = false,
|
||||
LockoutEnabled = false,
|
||||
PasswordHash = "AQAAAAEAACcQAAAAEPi0dTNwbpnqCBmfVPUqx8rvTNgAcDNC+66x774qyxx0uJUru0hXcxozgjaFx/7MRw==",
|
||||
PhoneNumberConfirmed = false,
|
||||
TwoFactorEnabled = false,
|
||||
UserName = "admin"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||
@@ -178,6 +193,20 @@ namespace Data.Migrations
|
||||
.HasFilter("[NormalizedName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetRoles");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = "43cf6ddd-13bc-4680-9e88-21d5bb059012",
|
||||
ConcurrencyStamp = "4add9b33-0dd3-4301-a5bf-c22d1f6be04d",
|
||||
Name = "Admin"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = "58aee2c2-eab0-4448-afde-440707d99128",
|
||||
ConcurrencyStamp = "091ef9fa-ecf1-4195-b3a3-9d1989cdbc50",
|
||||
Name = "Employee"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||
@@ -263,6 +292,18 @@ namespace Data.Migrations
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetUserRoles");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
UserId = "5ff048ba-cb37-4966-a7dd-f7b0aa96d730",
|
||||
RoleId = "43cf6ddd-13bc-4680-9e88-21d5bb059012"
|
||||
},
|
||||
new
|
||||
{
|
||||
UserId = "5ff048ba-cb37-4966-a7dd-f7b0aa96d730",
|
||||
RoleId = "58aee2c2-eab0-4448-afde-440707d99128"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||
@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace Data.Migrations
|
||||
{
|
||||
public partial class Changes : Migration
|
||||
public partial class Migrena : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
@@ -201,6 +201,31 @@ namespace Data.Migrations
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetRoles",
|
||||
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||
values: new object[] { "43cf6ddd-13bc-4680-9e88-21d5bb059012", "4add9b33-0dd3-4301-a5bf-c22d1f6be04d", "Admin", null });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetRoles",
|
||||
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||
values: new object[] { "58aee2c2-eab0-4448-afde-440707d99128", "091ef9fa-ecf1-4195-b3a3-9d1989cdbc50", "Employee", null });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetUsers",
|
||||
columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "FirstName", "LastName", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PersonalNumber", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UserName" },
|
||||
values: new object[] { "5ff048ba-cb37-4966-a7dd-f7b0aa96d730", 0, "bd3f3137-a505-4c21-9392-8cc07b1eac1e", "admin@admin.admin", false, null, null, false, null, null, null, "AQAAAAEAACcQAAAAEPi0dTNwbpnqCBmfVPUqx8rvTNgAcDNC+66x774qyxx0uJUru0hXcxozgjaFx/7MRw==", null, null, false, null, false, "admin" });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetUserRoles",
|
||||
columns: new[] { "RoleId", "UserId" },
|
||||
values: new object[] { "43cf6ddd-13bc-4680-9e88-21d5bb059012", "5ff048ba-cb37-4966-a7dd-f7b0aa96d730" });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetUserRoles",
|
||||
columns: new[] { "RoleId", "UserId" },
|
||||
values: new object[] { "58aee2c2-eab0-4448-afde-440707d99128", "5ff048ba-cb37-4966-a7dd-f7b0aa96d730" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_AspNetRoleClaims_RoleId",
|
||||
table: "AspNetRoleClaims",
|
||||
399
RentACar/Data/Migrations/20220405162441_Migrena1.Designer.cs
generated
Normal file
399
RentACar/Data/Migrations/20220405162441_Migrena1.Designer.cs
generated
Normal file
@@ -0,0 +1,399 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(RentACarDbContext))]
|
||||
[Migration("20220405162441_Migrena1")]
|
||||
partial class Migrena1
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("ProductVersion", "5.0.15")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("Data.Entities.Car", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("Brand")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("CountPassengerSeats")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Model")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<decimal>("PriceForDay")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<int>("Year")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Cars");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Data.Entities.Rents", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<int>("CarId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("EndDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime>("StartDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("CarId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Rents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Data.Entities.User", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<int>("AccessFailedCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<bool>("EmailConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("LockoutEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||
.HasColumnType("datetimeoffset");
|
||||
|
||||
b.Property<string>("NormalizedEmail")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("NormalizedUserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PersonalNumber")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("PhoneNumber")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("PhoneNumberConfirmed")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("SecurityStamp")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<bool>("TwoFactorEnabled")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("UserName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedEmail")
|
||||
.HasDatabaseName("EmailIndex");
|
||||
|
||||
b.HasIndex("NormalizedUserName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("UserNameIndex")
|
||||
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetUsers");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = "b482663b-78bc-4b6a-81a6-75d52d87bbb1",
|
||||
AccessFailedCount = 0,
|
||||
ConcurrencyStamp = "87ad6f7e-0c13-418e-85bd-de8f713571df",
|
||||
Email = "admin@admin.admin",
|
||||
EmailConfirmed = false,
|
||||
LockoutEnabled = false,
|
||||
PasswordHash = "AQAAAAEAACcQAAAAEDziS8oqC1HTCljBTahrcu4r2yG6Jx9UQwSqWbxyBm2tmq5aKXSnajXslwuEc2AF4Q==",
|
||||
PhoneNumberConfirmed = false,
|
||||
SecurityStamp = "4323b9d9-b92f-4ef3-94b1-77050d61341a",
|
||||
TwoFactorEnabled = false,
|
||||
UserName = "admin"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||
{
|
||||
b.Property<string>("Id")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("ConcurrencyStamp")
|
||||
.IsConcurrencyToken()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.Property<string>("NormalizedName")
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("nvarchar(256)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("NormalizedName")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("RoleNameIndex")
|
||||
.HasFilter("[NormalizedName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetRoles");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = "0387a4dd-4a2a-4119-b7c9-5d5e7c16b0ed",
|
||||
ConcurrencyStamp = "cb148526-d897-4dfa-966f-b67b73e16be5",
|
||||
Name = "Admin"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = "b0aacbe6-4603-4b03-b4e7-b521491bef85",
|
||||
ConcurrencyStamp = "ef05edac-cedf-488c-9e99-569b0d434c10",
|
||||
Name = "Employee"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("RoleId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetRoleClaims");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("ClaimType")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("ClaimValue")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserClaims");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||
{
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("ProviderKey")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("ProviderDisplayName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("UserId")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("LoginProvider", "ProviderKey");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("AspNetUserLogins");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||
{
|
||||
b.Property<string>("UserId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("RoleId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.HasKey("UserId", "RoleId");
|
||||
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetUserRoles");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
UserId = "b482663b-78bc-4b6a-81a6-75d52d87bbb1",
|
||||
RoleId = "0387a4dd-4a2a-4119-b7c9-5d5e7c16b0ed"
|
||||
},
|
||||
new
|
||||
{
|
||||
UserId = "b482663b-78bc-4b6a-81a6-75d52d87bbb1",
|
||||
RoleId = "b0aacbe6-4603-4b03-b4e7-b521491bef85"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||
{
|
||||
b.Property<string>("UserId")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("LoginProvider")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("UserId", "LoginProvider", "Name");
|
||||
|
||||
b.ToTable("AspNetUserTokens");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Data.Entities.Rents", b =>
|
||||
{
|
||||
b.HasOne("Data.Entities.Car", "Car")
|
||||
.WithMany()
|
||||
.HasForeignKey("CarId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Data.Entities.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId");
|
||||
|
||||
b.Navigation("Car");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||
{
|
||||
b.HasOne("Data.Entities.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||
{
|
||||
b.HasOne("Data.Entities.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||
{
|
||||
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("RoleId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Data.Entities.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||
{
|
||||
b.HasOne("Data.Entities.User", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
113
RentACar/Data/Migrations/20220405162441_Migrena1.cs
Normal file
113
RentACar/Data/Migrations/20220405162441_Migrena1.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace Data.Migrations
|
||||
{
|
||||
public partial class Migrena1 : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DeleteData(
|
||||
table: "AspNetUserRoles",
|
||||
keyColumns: new[] { "RoleId", "UserId" },
|
||||
keyValues: new object[] { "43cf6ddd-13bc-4680-9e88-21d5bb059012", "5ff048ba-cb37-4966-a7dd-f7b0aa96d730" });
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "AspNetUserRoles",
|
||||
keyColumns: new[] { "RoleId", "UserId" },
|
||||
keyValues: new object[] { "58aee2c2-eab0-4448-afde-440707d99128", "5ff048ba-cb37-4966-a7dd-f7b0aa96d730" });
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "AspNetRoles",
|
||||
keyColumn: "Id",
|
||||
keyValue: "43cf6ddd-13bc-4680-9e88-21d5bb059012");
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "AspNetRoles",
|
||||
keyColumn: "Id",
|
||||
keyValue: "58aee2c2-eab0-4448-afde-440707d99128");
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "AspNetUsers",
|
||||
keyColumn: "Id",
|
||||
keyValue: "5ff048ba-cb37-4966-a7dd-f7b0aa96d730");
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetRoles",
|
||||
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||
values: new object[] { "0387a4dd-4a2a-4119-b7c9-5d5e7c16b0ed", "cb148526-d897-4dfa-966f-b67b73e16be5", "Admin", null });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetRoles",
|
||||
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||
values: new object[] { "b0aacbe6-4603-4b03-b4e7-b521491bef85", "ef05edac-cedf-488c-9e99-569b0d434c10", "Employee", null });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetUsers",
|
||||
columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "FirstName", "LastName", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PersonalNumber", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UserName" },
|
||||
values: new object[] { "b482663b-78bc-4b6a-81a6-75d52d87bbb1", 0, "87ad6f7e-0c13-418e-85bd-de8f713571df", "admin@admin.admin", false, null, null, false, null, null, null, "AQAAAAEAACcQAAAAEDziS8oqC1HTCljBTahrcu4r2yG6Jx9UQwSqWbxyBm2tmq5aKXSnajXslwuEc2AF4Q==", null, null, false, "4323b9d9-b92f-4ef3-94b1-77050d61341a", false, "admin" });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetUserRoles",
|
||||
columns: new[] { "RoleId", "UserId" },
|
||||
values: new object[] { "0387a4dd-4a2a-4119-b7c9-5d5e7c16b0ed", "b482663b-78bc-4b6a-81a6-75d52d87bbb1" });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetUserRoles",
|
||||
columns: new[] { "RoleId", "UserId" },
|
||||
values: new object[] { "b0aacbe6-4603-4b03-b4e7-b521491bef85", "b482663b-78bc-4b6a-81a6-75d52d87bbb1" });
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DeleteData(
|
||||
table: "AspNetUserRoles",
|
||||
keyColumns: new[] { "RoleId", "UserId" },
|
||||
keyValues: new object[] { "0387a4dd-4a2a-4119-b7c9-5d5e7c16b0ed", "b482663b-78bc-4b6a-81a6-75d52d87bbb1" });
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "AspNetUserRoles",
|
||||
keyColumns: new[] { "RoleId", "UserId" },
|
||||
keyValues: new object[] { "b0aacbe6-4603-4b03-b4e7-b521491bef85", "b482663b-78bc-4b6a-81a6-75d52d87bbb1" });
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "AspNetRoles",
|
||||
keyColumn: "Id",
|
||||
keyValue: "0387a4dd-4a2a-4119-b7c9-5d5e7c16b0ed");
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "AspNetRoles",
|
||||
keyColumn: "Id",
|
||||
keyValue: "b0aacbe6-4603-4b03-b4e7-b521491bef85");
|
||||
|
||||
migrationBuilder.DeleteData(
|
||||
table: "AspNetUsers",
|
||||
keyColumn: "Id",
|
||||
keyValue: "b482663b-78bc-4b6a-81a6-75d52d87bbb1");
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetRoles",
|
||||
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||
values: new object[] { "43cf6ddd-13bc-4680-9e88-21d5bb059012", "4add9b33-0dd3-4301-a5bf-c22d1f6be04d", "Admin", null });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetRoles",
|
||||
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||
values: new object[] { "58aee2c2-eab0-4448-afde-440707d99128", "091ef9fa-ecf1-4195-b3a3-9d1989cdbc50", "Employee", null });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetUsers",
|
||||
columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "FirstName", "LastName", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PersonalNumber", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UserName" },
|
||||
values: new object[] { "5ff048ba-cb37-4966-a7dd-f7b0aa96d730", 0, "bd3f3137-a505-4c21-9392-8cc07b1eac1e", "admin@admin.admin", false, null, null, false, null, null, null, "AQAAAAEAACcQAAAAEPi0dTNwbpnqCBmfVPUqx8rvTNgAcDNC+66x774qyxx0uJUru0hXcxozgjaFx/7MRw==", null, null, false, null, false, "admin" });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetUserRoles",
|
||||
columns: new[] { "RoleId", "UserId" },
|
||||
values: new object[] { "43cf6ddd-13bc-4680-9e88-21d5bb059012", "5ff048ba-cb37-4966-a7dd-f7b0aa96d730" });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "AspNetUserRoles",
|
||||
columns: new[] { "RoleId", "UserId" },
|
||||
values: new object[] { "58aee2c2-eab0-4448-afde-440707d99128", "5ff048ba-cb37-4966-a7dd-f7b0aa96d730" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -149,6 +149,22 @@ namespace Data.Migrations
|
||||
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetUsers");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = "b482663b-78bc-4b6a-81a6-75d52d87bbb1",
|
||||
AccessFailedCount = 0,
|
||||
ConcurrencyStamp = "87ad6f7e-0c13-418e-85bd-de8f713571df",
|
||||
Email = "admin@admin.admin",
|
||||
EmailConfirmed = false,
|
||||
LockoutEnabled = false,
|
||||
PasswordHash = "AQAAAAEAACcQAAAAEDziS8oqC1HTCljBTahrcu4r2yG6Jx9UQwSqWbxyBm2tmq5aKXSnajXslwuEc2AF4Q==",
|
||||
PhoneNumberConfirmed = false,
|
||||
SecurityStamp = "4323b9d9-b92f-4ef3-94b1-77050d61341a",
|
||||
TwoFactorEnabled = false,
|
||||
UserName = "admin"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||
@@ -176,6 +192,20 @@ namespace Data.Migrations
|
||||
.HasFilter("[NormalizedName] IS NOT NULL");
|
||||
|
||||
b.ToTable("AspNetRoles");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
Id = "0387a4dd-4a2a-4119-b7c9-5d5e7c16b0ed",
|
||||
ConcurrencyStamp = "cb148526-d897-4dfa-966f-b67b73e16be5",
|
||||
Name = "Admin"
|
||||
},
|
||||
new
|
||||
{
|
||||
Id = "b0aacbe6-4603-4b03-b4e7-b521491bef85",
|
||||
ConcurrencyStamp = "ef05edac-cedf-488c-9e99-569b0d434c10",
|
||||
Name = "Employee"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||
@@ -261,6 +291,18 @@ namespace Data.Migrations
|
||||
b.HasIndex("RoleId");
|
||||
|
||||
b.ToTable("AspNetUserRoles");
|
||||
|
||||
b.HasData(
|
||||
new
|
||||
{
|
||||
UserId = "b482663b-78bc-4b6a-81a6-75d52d87bbb1",
|
||||
RoleId = "0387a4dd-4a2a-4119-b7c9-5d5e7c16b0ed"
|
||||
},
|
||||
new
|
||||
{
|
||||
UserId = "b482663b-78bc-4b6a-81a6-75d52d87bbb1",
|
||||
RoleId = "b0aacbe6-4603-4b03-b4e7-b521491bef85"
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
<hr />
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.Email"></label>
|
||||
<input asp-for="Input.Email" class="form-control" />
|
||||
<span asp-validation-for="Input.Email" class="text-danger"></span>
|
||||
<label asp-for="Input.Username"></label>
|
||||
<input asp-for="Input.Username" class="form-control" />
|
||||
<span asp-validation-for="Input.Username" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.Password"></label>
|
||||
|
||||
@@ -12,23 +12,27 @@ using Microsoft.AspNetCore.Identity.UI.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Data;
|
||||
|
||||
namespace WebApp.Areas.Identity.Pages.Account
|
||||
{
|
||||
[AllowAnonymous]
|
||||
public class LoginModel : PageModel
|
||||
{
|
||||
private readonly RentACarDbContext rentACarDbContext;
|
||||
private readonly UserManager<User> _userManager;
|
||||
private readonly SignInManager<User> _signInManager;
|
||||
private readonly ILogger<LoginModel> _logger;
|
||||
|
||||
public LoginModel(SignInManager<User> signInManager,
|
||||
public LoginModel(RentACarDbContext dbContext,
|
||||
SignInManager<User> signInManager,
|
||||
ILogger<LoginModel> logger,
|
||||
UserManager<User> userManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_signInManager = signInManager;
|
||||
_logger = logger;
|
||||
rentACarDbContext = dbContext;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
@@ -44,8 +48,8 @@ namespace WebApp.Areas.Identity.Pages.Account
|
||||
public class InputModel
|
||||
{
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
public string Email { get; set; }
|
||||
[Display(Name = "Username")]
|
||||
public string Username { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataType(DataType.Password)]
|
||||
@@ -82,7 +86,7 @@ namespace WebApp.Areas.Identity.Pages.Account
|
||||
{
|
||||
// This doesn't count login failures towards account lockout
|
||||
// To enable password failures to trigger account lockout, set lockoutOnFailure: true
|
||||
var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
|
||||
var result = await _signInManager.PasswordSignInAsync(rentACarDbContext.Users.FirstOrDefault(user => user.UserName == Input.Username), Input.Password, Input.RememberMe, lockoutOnFailure: false);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
_logger.LogInformation("User logged in.");
|
||||
|
||||
@@ -12,15 +12,30 @@
|
||||
<h4>Create a new account.</h4>
|
||||
<hr />
|
||||
<div asp-validation-summary="All" class="text-danger"></div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.Username"></label>
|
||||
<input asp-for="Input.Username" class="form-control" />
|
||||
<span asp-validation-for="Input" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.Email"></label>
|
||||
<input asp-for="Input.Email" class="form-control" />
|
||||
<span asp-validation-for="Input.Email" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Input">Username</label>
|
||||
<input asp-for="Input" class="form-control" />
|
||||
<span asp-validation-for="Input" class="text-danger"></span>
|
||||
<label asp-for="Input.FirstName"></label>
|
||||
<input asp-for="Input.FirstName" class="form-control" />
|
||||
<span asp-validation-for="Input.FirstName" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.LastName"></label>
|
||||
<input asp-for="Input.LastName" class="form-control" />
|
||||
<span asp-validation-for="Input.LastName" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.PhoneNumber"></label>
|
||||
<input asp-for="Input.PhoneNumber" class="form-control" />
|
||||
<span asp-validation-for="Input.PhoneNumber" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Input.Password"></label>
|
||||
|
||||
@@ -46,11 +46,25 @@ namespace WebApp.Areas.Identity.Pages.Account
|
||||
|
||||
public class InputModel
|
||||
{
|
||||
[Required]
|
||||
[StringLength(50, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||
[Display(Name = "Username")]
|
||||
public string Username { get; set; }
|
||||
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
[Display(Name = "Email")]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Display(Name = "First Name")]
|
||||
public string FirstName { get; set; }
|
||||
|
||||
[Display(Name = "Last Name")]
|
||||
public string LastName { get; set; }
|
||||
|
||||
[Display(Name = "Phone")]
|
||||
public string PhoneNumber { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
|
||||
[DataType(DataType.Password)]
|
||||
@@ -75,7 +89,7 @@ namespace WebApp.Areas.Identity.Pages.Account
|
||||
ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var user = new User { Id = Guid.NewGuid().ToString(), UserName = Input.Email, Email = Input.Email };
|
||||
var user = new User { Id = Guid.NewGuid().ToString(), UserName = Input.Username, Email = Input.Email, FirstName = Input.FirstName, LastName = Input.LastName, PhoneNumber = Input.PhoneNumber };
|
||||
var result = await _userManager.CreateAsync(user, Input.Password);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace API.Controllers
|
||||
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
|
||||
if(!this.User.Identity.IsAuthenticated)
|
||||
{
|
||||
return Redirect("");
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - API</title>
|
||||
<title>@ViewData["Title"] - LuminousRent</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" />
|
||||
</head>
|
||||
@@ -11,7 +11,7 @@
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">API</a>
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">LuminousRent - Rent-A-Car Service</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2022 - API - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
© 2022 - LuminousRent - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
@if (SignInManager.IsSignedIn(User))
|
||||
{
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Manage/Index" title="Manage">Hello @User.Identity.Name!</a>
|
||||
<a class="nav-link text-dark" asp-area="Identity" asp-page="/Account/Manage/Index" title="Manage">Hello @User.Identity.Name</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<form class="form-inline" asp-area="Identity" asp-page="/Account/Logout" asp-route-returnUrl="@Url.Action("Index", "Home", new { area = "" })">
|
||||
|
||||
Reference in New Issue
Block a user