Removed unsued properties from user controller index
This commit is contained in:
@@ -20,7 +20,7 @@ namespace Data
|
|||||||
{
|
{
|
||||||
if (!optionsBuilder.IsConfigured)
|
if (!optionsBuilder.IsConfigured)
|
||||||
{
|
{
|
||||||
optionsBuilder.UseSqlServer("Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;");
|
optionsBuilder.UseSqlServer("Server=.;Database=RentACar;Integrated Security=true;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
namespace Data.Migrations
|
namespace Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(RentACarDbContext))]
|
[DbContext(typeof(RentACarDbContext))]
|
||||||
[Migration("20220406212949_migrena1")]
|
[Migration("20220407201957_migrena")]
|
||||||
partial class migrena1
|
partial class migrena
|
||||||
{
|
{
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
@@ -124,7 +124,7 @@ namespace Data.Migrations
|
|||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
b.Property<string>("PersonalNumber")
|
b.Property<string>("PersonalNumber")
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
b.Property<string>("PhoneNumber")
|
b.Property<string>("PhoneNumber")
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
@@ -152,20 +152,24 @@ namespace Data.Migrations
|
|||||||
.HasDatabaseName("UserNameIndex")
|
.HasDatabaseName("UserNameIndex")
|
||||||
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
||||||
|
|
||||||
|
b.HasIndex("PersonalNumber")
|
||||||
|
.IsUnique()
|
||||||
|
.HasFilter("[PersonalNumber] IS NOT NULL");
|
||||||
|
|
||||||
b.ToTable("AspNetUsers");
|
b.ToTable("AspNetUsers");
|
||||||
|
|
||||||
b.HasData(
|
b.HasData(
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = "8fb80b37-172b-4100-b499-cfa8b8bd225f",
|
Id = "387f2544-bfa8-44ed-9793-a5bd5eaafe57",
|
||||||
AccessFailedCount = 0,
|
AccessFailedCount = 0,
|
||||||
ConcurrencyStamp = "863ef77f-ca57-4cdc-8a69-2034d137775e",
|
ConcurrencyStamp = "6fa96ce1-7e47-4f44-bdeb-e13705729bdb",
|
||||||
Email = "admin@admin.admin",
|
Email = "admin@admin.admin",
|
||||||
EmailConfirmed = false,
|
EmailConfirmed = false,
|
||||||
LockoutEnabled = false,
|
LockoutEnabled = false,
|
||||||
PasswordHash = "AQAAAAEAACcQAAAAEA2HtcFcKoyTZ8qyX/ACxeWR3uxNREHn09A1/5s+c2wzkUUOThsWUqEiv7Rn3vmgJQ==",
|
PasswordHash = "AQAAAAEAACcQAAAAECdhgDXw9WdaYvos/Ef9zaSiSApNswFCna2iNk8tu8BsvXRVMQWvdPLE1L8sTdgjDQ==",
|
||||||
PhoneNumberConfirmed = false,
|
PhoneNumberConfirmed = false,
|
||||||
SecurityStamp = "670d518e-9966-41bb-ae76-3a8968513497",
|
SecurityStamp = "db1ac172-eb3b-4b93-9f31-3f748a1eda84",
|
||||||
TwoFactorEnabled = false,
|
TwoFactorEnabled = false,
|
||||||
UserName = "admin"
|
UserName = "admin"
|
||||||
});
|
});
|
||||||
@@ -200,14 +204,14 @@ namespace Data.Migrations
|
|||||||
b.HasData(
|
b.HasData(
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = "6d92895f-aab5-46b6-8650-0d8c1b566372",
|
Id = "fb054f77-3578-45ee-a3d6-e6fe706526b2",
|
||||||
ConcurrencyStamp = "372dca25-7ccc-4995-9b3f-32bfdebc1ff6",
|
ConcurrencyStamp = "4af0d06c-63be-448c-a1ee-7c369398dee5",
|
||||||
Name = "Admin"
|
Name = "Admin"
|
||||||
},
|
},
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = "b57865e0-539e-4f79-8215-103e22016c83",
|
Id = "d3aa27bb-2866-4a7d-9f0d-30498859ae94",
|
||||||
ConcurrencyStamp = "97e7c5da-d35b-475b-85cd-f5df914e5850",
|
ConcurrencyStamp = "64b281d1-f963-43ae-a25e-1f8f220b553d",
|
||||||
Name = "Employee"
|
Name = "Employee"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -299,13 +303,13 @@ namespace Data.Migrations
|
|||||||
b.HasData(
|
b.HasData(
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
UserId = "8fb80b37-172b-4100-b499-cfa8b8bd225f",
|
UserId = "387f2544-bfa8-44ed-9793-a5bd5eaafe57",
|
||||||
RoleId = "6d92895f-aab5-46b6-8650-0d8c1b566372"
|
RoleId = "fb054f77-3578-45ee-a3d6-e6fe706526b2"
|
||||||
},
|
},
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
UserId = "8fb80b37-172b-4100-b499-cfa8b8bd225f",
|
UserId = "387f2544-bfa8-44ed-9793-a5bd5eaafe57",
|
||||||
RoleId = "b57865e0-539e-4f79-8215-103e22016c83"
|
RoleId = "d3aa27bb-2866-4a7d-9f0d-30498859ae94"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
|||||||
|
|
||||||
namespace Data.Migrations
|
namespace Data.Migrations
|
||||||
{
|
{
|
||||||
public partial class migrena1 : Migration
|
public partial class migrena : Migration
|
||||||
{
|
{
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
@@ -28,7 +28,7 @@ namespace Data.Migrations
|
|||||||
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||||
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
LastName = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
LastName = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
PersonalNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
PersonalNumber = table.Column<string>(type: "nvarchar(450)", nullable: true),
|
||||||
UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||||
NormalizedUserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
NormalizedUserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||||
Email = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
Email = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
|
||||||
@@ -204,27 +204,27 @@ namespace Data.Migrations
|
|||||||
migrationBuilder.InsertData(
|
migrationBuilder.InsertData(
|
||||||
table: "AspNetRoles",
|
table: "AspNetRoles",
|
||||||
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||||
values: new object[] { "6d92895f-aab5-46b6-8650-0d8c1b566372", "372dca25-7ccc-4995-9b3f-32bfdebc1ff6", "Admin", null });
|
values: new object[] { "fb054f77-3578-45ee-a3d6-e6fe706526b2", "4af0d06c-63be-448c-a1ee-7c369398dee5", "Admin", null });
|
||||||
|
|
||||||
migrationBuilder.InsertData(
|
migrationBuilder.InsertData(
|
||||||
table: "AspNetRoles",
|
table: "AspNetRoles",
|
||||||
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" },
|
||||||
values: new object[] { "b57865e0-539e-4f79-8215-103e22016c83", "97e7c5da-d35b-475b-85cd-f5df914e5850", "Employee", null });
|
values: new object[] { "d3aa27bb-2866-4a7d-9f0d-30498859ae94", "64b281d1-f963-43ae-a25e-1f8f220b553d", "Employee", null });
|
||||||
|
|
||||||
migrationBuilder.InsertData(
|
migrationBuilder.InsertData(
|
||||||
table: "AspNetUsers",
|
table: "AspNetUsers",
|
||||||
columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "FirstName", "LastName", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PersonalNumber", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UserName" },
|
columns: new[] { "Id", "AccessFailedCount", "ConcurrencyStamp", "Email", "EmailConfirmed", "FirstName", "LastName", "LockoutEnabled", "LockoutEnd", "NormalizedEmail", "NormalizedUserName", "PasswordHash", "PersonalNumber", "PhoneNumber", "PhoneNumberConfirmed", "SecurityStamp", "TwoFactorEnabled", "UserName" },
|
||||||
values: new object[] { "8fb80b37-172b-4100-b499-cfa8b8bd225f", 0, "863ef77f-ca57-4cdc-8a69-2034d137775e", "admin@admin.admin", false, null, null, false, null, null, null, "AQAAAAEAACcQAAAAEA2HtcFcKoyTZ8qyX/ACxeWR3uxNREHn09A1/5s+c2wzkUUOThsWUqEiv7Rn3vmgJQ==", null, null, false, "670d518e-9966-41bb-ae76-3a8968513497", false, "admin" });
|
values: new object[] { "387f2544-bfa8-44ed-9793-a5bd5eaafe57", 0, "6fa96ce1-7e47-4f44-bdeb-e13705729bdb", "admin@admin.admin", false, null, null, false, null, null, null, "AQAAAAEAACcQAAAAECdhgDXw9WdaYvos/Ef9zaSiSApNswFCna2iNk8tu8BsvXRVMQWvdPLE1L8sTdgjDQ==", null, null, false, "db1ac172-eb3b-4b93-9f31-3f748a1eda84", false, "admin" });
|
||||||
|
|
||||||
migrationBuilder.InsertData(
|
migrationBuilder.InsertData(
|
||||||
table: "AspNetUserRoles",
|
table: "AspNetUserRoles",
|
||||||
columns: new[] { "RoleId", "UserId" },
|
columns: new[] { "RoleId", "UserId" },
|
||||||
values: new object[] { "6d92895f-aab5-46b6-8650-0d8c1b566372", "8fb80b37-172b-4100-b499-cfa8b8bd225f" });
|
values: new object[] { "fb054f77-3578-45ee-a3d6-e6fe706526b2", "387f2544-bfa8-44ed-9793-a5bd5eaafe57" });
|
||||||
|
|
||||||
migrationBuilder.InsertData(
|
migrationBuilder.InsertData(
|
||||||
table: "AspNetUserRoles",
|
table: "AspNetUserRoles",
|
||||||
columns: new[] { "RoleId", "UserId" },
|
columns: new[] { "RoleId", "UserId" },
|
||||||
values: new object[] { "b57865e0-539e-4f79-8215-103e22016c83", "8fb80b37-172b-4100-b499-cfa8b8bd225f" });
|
values: new object[] { "d3aa27bb-2866-4a7d-9f0d-30498859ae94", "387f2544-bfa8-44ed-9793-a5bd5eaafe57" });
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_AspNetRoleClaims_RoleId",
|
name: "IX_AspNetRoleClaims_RoleId",
|
||||||
@@ -258,6 +258,13 @@ namespace Data.Migrations
|
|||||||
table: "AspNetUsers",
|
table: "AspNetUsers",
|
||||||
column: "NormalizedEmail");
|
column: "NormalizedEmail");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_AspNetUsers_PersonalNumber",
|
||||||
|
table: "AspNetUsers",
|
||||||
|
column: "PersonalNumber",
|
||||||
|
unique: true,
|
||||||
|
filter: "[PersonalNumber] IS NOT NULL");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "UserNameIndex",
|
name: "UserNameIndex",
|
||||||
table: "AspNetUsers",
|
table: "AspNetUsers",
|
||||||
@@ -122,7 +122,7 @@ namespace Data.Migrations
|
|||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
b.Property<string>("PersonalNumber")
|
b.Property<string>("PersonalNumber")
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
b.Property<string>("PhoneNumber")
|
b.Property<string>("PhoneNumber")
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
@@ -150,20 +150,24 @@ namespace Data.Migrations
|
|||||||
.HasDatabaseName("UserNameIndex")
|
.HasDatabaseName("UserNameIndex")
|
||||||
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
.HasFilter("[NormalizedUserName] IS NOT NULL");
|
||||||
|
|
||||||
|
b.HasIndex("PersonalNumber")
|
||||||
|
.IsUnique()
|
||||||
|
.HasFilter("[PersonalNumber] IS NOT NULL");
|
||||||
|
|
||||||
b.ToTable("AspNetUsers");
|
b.ToTable("AspNetUsers");
|
||||||
|
|
||||||
b.HasData(
|
b.HasData(
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = "8fb80b37-172b-4100-b499-cfa8b8bd225f",
|
Id = "387f2544-bfa8-44ed-9793-a5bd5eaafe57",
|
||||||
AccessFailedCount = 0,
|
AccessFailedCount = 0,
|
||||||
ConcurrencyStamp = "863ef77f-ca57-4cdc-8a69-2034d137775e",
|
ConcurrencyStamp = "6fa96ce1-7e47-4f44-bdeb-e13705729bdb",
|
||||||
Email = "admin@admin.admin",
|
Email = "admin@admin.admin",
|
||||||
EmailConfirmed = false,
|
EmailConfirmed = false,
|
||||||
LockoutEnabled = false,
|
LockoutEnabled = false,
|
||||||
PasswordHash = "AQAAAAEAACcQAAAAEA2HtcFcKoyTZ8qyX/ACxeWR3uxNREHn09A1/5s+c2wzkUUOThsWUqEiv7Rn3vmgJQ==",
|
PasswordHash = "AQAAAAEAACcQAAAAECdhgDXw9WdaYvos/Ef9zaSiSApNswFCna2iNk8tu8BsvXRVMQWvdPLE1L8sTdgjDQ==",
|
||||||
PhoneNumberConfirmed = false,
|
PhoneNumberConfirmed = false,
|
||||||
SecurityStamp = "670d518e-9966-41bb-ae76-3a8968513497",
|
SecurityStamp = "db1ac172-eb3b-4b93-9f31-3f748a1eda84",
|
||||||
TwoFactorEnabled = false,
|
TwoFactorEnabled = false,
|
||||||
UserName = "admin"
|
UserName = "admin"
|
||||||
});
|
});
|
||||||
@@ -198,14 +202,14 @@ namespace Data.Migrations
|
|||||||
b.HasData(
|
b.HasData(
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = "6d92895f-aab5-46b6-8650-0d8c1b566372",
|
Id = "fb054f77-3578-45ee-a3d6-e6fe706526b2",
|
||||||
ConcurrencyStamp = "372dca25-7ccc-4995-9b3f-32bfdebc1ff6",
|
ConcurrencyStamp = "4af0d06c-63be-448c-a1ee-7c369398dee5",
|
||||||
Name = "Admin"
|
Name = "Admin"
|
||||||
},
|
},
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
Id = "b57865e0-539e-4f79-8215-103e22016c83",
|
Id = "d3aa27bb-2866-4a7d-9f0d-30498859ae94",
|
||||||
ConcurrencyStamp = "97e7c5da-d35b-475b-85cd-f5df914e5850",
|
ConcurrencyStamp = "64b281d1-f963-43ae-a25e-1f8f220b553d",
|
||||||
Name = "Employee"
|
Name = "Employee"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -297,13 +301,13 @@ namespace Data.Migrations
|
|||||||
b.HasData(
|
b.HasData(
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
UserId = "8fb80b37-172b-4100-b499-cfa8b8bd225f",
|
UserId = "387f2544-bfa8-44ed-9793-a5bd5eaafe57",
|
||||||
RoleId = "6d92895f-aab5-46b6-8650-0d8c1b566372"
|
RoleId = "fb054f77-3578-45ee-a3d6-e6fe706526b2"
|
||||||
},
|
},
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
UserId = "8fb80b37-172b-4100-b499-cfa8b8bd225f",
|
UserId = "387f2544-bfa8-44ed-9793-a5bd5eaafe57",
|
||||||
RoleId = "b57865e0-539e-4f79-8215-103e22016c83"
|
RoleId = "d3aa27bb-2866-4a7d-9f0d-30498859ae94"
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
using Microsoft.AspNetCore.WebUtilities;
|
using Microsoft.AspNetCore.WebUtilities;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace WebApp.Areas.Identity.Pages.Account
|
namespace WebApp.Areas.Identity.Pages.Account
|
||||||
{
|
{
|
||||||
@@ -23,16 +22,19 @@ namespace WebApp.Areas.Identity.Pages.Account
|
|||||||
{
|
{
|
||||||
private readonly SignInManager<User> _signInManager;
|
private readonly SignInManager<User> _signInManager;
|
||||||
private readonly UserManager<User> _userManager;
|
private readonly UserManager<User> _userManager;
|
||||||
|
private readonly RoleManager<IdentityRole> _roleManager;
|
||||||
private readonly ILogger<RegisterModel> _logger;
|
private readonly ILogger<RegisterModel> _logger;
|
||||||
private readonly IEmailSender _emailSender;
|
private readonly IEmailSender _emailSender;
|
||||||
|
|
||||||
public RegisterModel(
|
public RegisterModel(
|
||||||
UserManager<User> userManager,
|
UserManager<User> userManager,
|
||||||
SignInManager<User> signInManager,
|
SignInManager<User> signInManager,
|
||||||
|
RoleManager<IdentityRole> roleManager,
|
||||||
ILogger<RegisterModel> logger,
|
ILogger<RegisterModel> logger,
|
||||||
IEmailSender emailSender)
|
IEmailSender emailSender)
|
||||||
{
|
{
|
||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
|
_roleManager = roleManager;
|
||||||
_signInManager = signInManager;
|
_signInManager = signInManager;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_emailSender = emailSender;
|
_emailSender = emailSender;
|
||||||
@@ -57,13 +59,12 @@ namespace WebApp.Areas.Identity.Pages.Account
|
|||||||
[Display(Name = "Email")]
|
[Display(Name = "Email")]
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
|
|
||||||
[Display(Name = "First name")]
|
[Display(Name = "First Name")]
|
||||||
public string FirstName { get; set; }
|
public string FirstName { get; set; }
|
||||||
|
|
||||||
[Display(Name = "Last name")]
|
[Display(Name = "Last Name")]
|
||||||
public string LastName { get; set; }
|
public string LastName { get; set; }
|
||||||
|
|
||||||
[Phone]
|
|
||||||
[Display(Name = "Phone")]
|
[Display(Name = "Phone")]
|
||||||
public string PhoneNumber { get; set; }
|
public string PhoneNumber { get; set; }
|
||||||
|
|
||||||
@@ -98,6 +99,9 @@ namespace WebApp.Areas.Identity.Pages.Account
|
|||||||
var result = await _userManager.CreateAsync(user, Input.Password);
|
var result = await _userManager.CreateAsync(user, Input.Password);
|
||||||
if (result.Succeeded)
|
if (result.Succeeded)
|
||||||
{
|
{
|
||||||
|
var defaultrole = _roleManager.FindByIdAsync("d3aa27bb-2866-4a7d-9f0d-30498859ae94").Result;
|
||||||
|
|
||||||
|
await _userManager.AddToRoleAsync(user, defaultrole.Name);
|
||||||
_logger.LogInformation("User created a new account with password.");
|
_logger.LogInformation("User created a new account with password.");
|
||||||
|
|
||||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ namespace WebApp.Controllers
|
|||||||
|
|
||||||
// GET: Cars/Edit/5
|
// GET: Cars/Edit/5
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
public async Task<IActionResult> Edit(int? id)
|
public async Task<IActionResult> Edit(int? id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (id == null)
|
||||||
@@ -90,6 +91,7 @@ namespace WebApp.Controllers
|
|||||||
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
|
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
public async Task<IActionResult> Edit(int id, [Bind("Id, Brand, Model, Year, CountPassengerSeats, Description, PriceForDay")] Car car)
|
public async Task<IActionResult> Edit(int id, [Bind("Id, Brand, Model, Year, CountPassengerSeats, Description, PriceForDay")] Car car)
|
||||||
{
|
{
|
||||||
if (id != car.Id)
|
if (id != car.Id)
|
||||||
@@ -122,6 +124,7 @@ namespace WebApp.Controllers
|
|||||||
|
|
||||||
// GET: Cars/Delete/5
|
// GET: Cars/Delete/5
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
public async Task<IActionResult> Delete(int? id)
|
public async Task<IActionResult> Delete(int? id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (id == null)
|
||||||
|
|||||||
@@ -7,9 +7,21 @@ using Microsoft.AspNetCore.Mvc.Rendering;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Data;
|
using Data;
|
||||||
using Data.Entities;
|
using Data.Entities;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
namespace WebApp.Controllers
|
namespace WebApp.Controllers
|
||||||
{
|
{
|
||||||
|
public class UserWithRoles
|
||||||
|
{
|
||||||
|
public string UserName { get; set; }
|
||||||
|
public string FirstName { get; set; }
|
||||||
|
public string LastName { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
public string PersonalNumber { get; set; }
|
||||||
|
public string PhoneNumber { get; set; }
|
||||||
|
public string Role { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class UsersController : Controller
|
public class UsersController : Controller
|
||||||
{
|
{
|
||||||
private readonly RentACarDbContext _context;
|
private readonly RentACarDbContext _context;
|
||||||
@@ -20,52 +32,36 @@ namespace WebApp.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GET: Users
|
// GET: Users
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
public async Task<IActionResult> Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
return View(await _context.Users.ToListAsync());
|
ICollection<User> users = await _context.Users.ToListAsync();
|
||||||
}
|
|
||||||
|
|
||||||
// GET: Users/Details/5
|
ICollection<UserWithRoles> usersWithRole = new List<UserWithRoles>();
|
||||||
public async Task<IActionResult> Details(string id)
|
|
||||||
{
|
|
||||||
if (id == null)
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
var user = await _context.Users
|
//foreach (var item in users)
|
||||||
.FirstOrDefaultAsync(m => m.Id == id);
|
//{
|
||||||
if (user == null)
|
// var userRole = await _context.UserRoles.FirstOrDefaultAsync(userRoles => userRoles.UserId == item.Id);
|
||||||
{
|
// var role = await _context.Roles.FirstOrDefaultAsync(role => role.Id == userRole.RoleId);
|
||||||
return NotFound();
|
// usersWithRole.Add(
|
||||||
}
|
// new UserWithRoles()
|
||||||
|
// {
|
||||||
|
// UserName = item.UserName,
|
||||||
|
// FirstName = item.FirstName,
|
||||||
|
// LastName = item.LastName,
|
||||||
|
// Email = item.Email,
|
||||||
|
// PersonalNumber = item.PersonalNumber,
|
||||||
|
// PhoneNumber = item.PhoneNumber,
|
||||||
|
// Role = role.Name
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
//}
|
||||||
|
|
||||||
return View(user);
|
return View(users);
|
||||||
}
|
|
||||||
|
|
||||||
// GET: Users/Create
|
|
||||||
public IActionResult Create()
|
|
||||||
{
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: Users/Create
|
|
||||||
// To protect from overposting attacks, enable the specific properties you want to bind to.
|
|
||||||
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
||||||
[HttpPost]
|
|
||||||
[ValidateAntiForgeryToken]
|
|
||||||
public async Task<IActionResult> Create([Bind("FirstName,LastName,PersonalNumber,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] User user)
|
|
||||||
{
|
|
||||||
if (ModelState.IsValid)
|
|
||||||
{
|
|
||||||
_context.Add(user);
|
|
||||||
await _context.SaveChangesAsync();
|
|
||||||
return RedirectToAction(nameof(Index));
|
|
||||||
}
|
|
||||||
return View(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: Users/Edit/5
|
// GET: Users/Edit/5
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
public async Task<IActionResult> Edit(string id)
|
public async Task<IActionResult> Edit(string id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (id == null)
|
||||||
@@ -86,6 +82,7 @@ namespace WebApp.Controllers
|
|||||||
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
|
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
public async Task<IActionResult> Edit(string id, [Bind("FirstName,LastName,PersonalNumber,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] User user)
|
public async Task<IActionResult> Edit(string id, [Bind("FirstName,LastName,PersonalNumber,Id,UserName,NormalizedUserName,Email,NormalizedEmail,EmailConfirmed,PasswordHash,SecurityStamp,ConcurrencyStamp,PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEnd,LockoutEnabled,AccessFailedCount")] User user)
|
||||||
{
|
{
|
||||||
if (id != user.Id)
|
if (id != user.Id)
|
||||||
@@ -117,6 +114,7 @@ namespace WebApp.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GET: Users/Delete/5
|
// GET: Users/Delete/5
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
public async Task<IActionResult> Delete(string id)
|
public async Task<IActionResult> Delete(string id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
if (id == null)
|
||||||
@@ -137,6 +135,7 @@ namespace WebApp.Controllers
|
|||||||
// POST: Users/Delete/5
|
// POST: Users/Delete/5
|
||||||
[HttpPost, ActionName("Delete")]
|
[HttpPost, ActionName("Delete")]
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
|
[Authorize(Roles = "Admin")]
|
||||||
public async Task<IActionResult> DeleteConfirmed(string id)
|
public async Task<IActionResult> DeleteConfirmed(string id)
|
||||||
{
|
{
|
||||||
var user = await _context.Users.FindAsync(id);
|
var user = await _context.Users.FindAsync(id);
|
||||||
|
|||||||
@@ -24,9 +24,15 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Cars" asp-action="Index">Cars</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Cars" asp-action="Index">Cars</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Rents" asp-action="Index">Rents</a>
|
||||||
|
</li>
|
||||||
|
@if (this.User.IsInRole("Admin"))
|
||||||
|
{
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Rents" asp-action="Index">Rents</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Users" asp-action="Index">Users</a>
|
||||||
</li>
|
</li>
|
||||||
|
}
|
||||||
</ul>
|
</ul>
|
||||||
<partial name="_LoginPartial" />
|
<partial name="_LoginPartial" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
@model Data.Entities.User
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Create";
|
|
||||||
}
|
|
||||||
|
|
||||||
<h1>Create</h1>
|
|
||||||
|
|
||||||
<h4>User</h4>
|
|
||||||
<hr />
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<form asp-action="Create">
|
|
||||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="FirstName" class="control-label"></label>
|
|
||||||
<input asp-for="FirstName" class="form-control" />
|
|
||||||
<span asp-validation-for="FirstName" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="LastName" class="control-label"></label>
|
|
||||||
<input asp-for="LastName" class="form-control" />
|
|
||||||
<span asp-validation-for="LastName" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="PersonalNumber" class="control-label"></label>
|
|
||||||
<input asp-for="PersonalNumber" class="form-control" />
|
|
||||||
<span asp-validation-for="PersonalNumber" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Id" class="control-label"></label>
|
|
||||||
<input asp-for="Id" class="form-control" />
|
|
||||||
<span asp-validation-for="Id" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="UserName" class="control-label"></label>
|
|
||||||
<input asp-for="UserName" class="form-control" />
|
|
||||||
<span asp-validation-for="UserName" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="NormalizedUserName" class="control-label"></label>
|
|
||||||
<input asp-for="NormalizedUserName" class="form-control" />
|
|
||||||
<span asp-validation-for="NormalizedUserName" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="Email" class="control-label"></label>
|
|
||||||
<input asp-for="Email" class="form-control" />
|
|
||||||
<span asp-validation-for="Email" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="NormalizedEmail" class="control-label"></label>
|
|
||||||
<input asp-for="NormalizedEmail" class="form-control" />
|
|
||||||
<span asp-validation-for="NormalizedEmail" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group form-check">
|
|
||||||
<label class="form-check-label">
|
|
||||||
<input class="form-check-input" asp-for="EmailConfirmed" /> @Html.DisplayNameFor(model => model.EmailConfirmed)
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="PasswordHash" class="control-label"></label>
|
|
||||||
<input asp-for="PasswordHash" class="form-control" />
|
|
||||||
<span asp-validation-for="PasswordHash" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="SecurityStamp" class="control-label"></label>
|
|
||||||
<input asp-for="SecurityStamp" class="form-control" />
|
|
||||||
<span asp-validation-for="SecurityStamp" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="ConcurrencyStamp" class="control-label"></label>
|
|
||||||
<input asp-for="ConcurrencyStamp" class="form-control" />
|
|
||||||
<span asp-validation-for="ConcurrencyStamp" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="PhoneNumber" class="control-label"></label>
|
|
||||||
<input asp-for="PhoneNumber" class="form-control" />
|
|
||||||
<span asp-validation-for="PhoneNumber" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group form-check">
|
|
||||||
<label class="form-check-label">
|
|
||||||
<input class="form-check-input" asp-for="PhoneNumberConfirmed" /> @Html.DisplayNameFor(model => model.PhoneNumberConfirmed)
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="form-group form-check">
|
|
||||||
<label class="form-check-label">
|
|
||||||
<input class="form-check-input" asp-for="TwoFactorEnabled" /> @Html.DisplayNameFor(model => model.TwoFactorEnabled)
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="LockoutEnd" class="control-label"></label>
|
|
||||||
<input asp-for="LockoutEnd" class="form-control" />
|
|
||||||
<span asp-validation-for="LockoutEnd" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group form-check">
|
|
||||||
<label class="form-check-label">
|
|
||||||
<input class="form-check-input" asp-for="LockoutEnabled" /> @Html.DisplayNameFor(model => model.LockoutEnabled)
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label asp-for="AccessFailedCount" class="control-label"></label>
|
|
||||||
<input asp-for="AccessFailedCount" class="form-control" />
|
|
||||||
<span asp-validation-for="AccessFailedCount" class="text-danger"></span>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<input type="submit" value="Create" class="btn btn-primary" />
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<a asp-action="Index">Back to List</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@section Scripts {
|
|
||||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
|
||||||
}
|
|
||||||
@@ -6,9 +6,6 @@
|
|||||||
|
|
||||||
<h1>Index</h1>
|
<h1>Index</h1>
|
||||||
|
|
||||||
<p>
|
|
||||||
<a asp-action="Create">Create New</a>
|
|
||||||
</p>
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -24,45 +21,12 @@
|
|||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.UserName)
|
@Html.DisplayNameFor(model => model.UserName)
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.NormalizedUserName)
|
|
||||||
</th>
|
|
||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.Email)
|
@Html.DisplayNameFor(model => model.Email)
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.NormalizedEmail)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.EmailConfirmed)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.PasswordHash)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.SecurityStamp)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.ConcurrencyStamp)
|
|
||||||
</th>
|
|
||||||
<th>
|
<th>
|
||||||
@Html.DisplayNameFor(model => model.PhoneNumber)
|
@Html.DisplayNameFor(model => model.PhoneNumber)
|
||||||
</th>
|
</th>
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.PhoneNumberConfirmed)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.TwoFactorEnabled)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.LockoutEnd)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.LockoutEnabled)
|
|
||||||
</th>
|
|
||||||
<th>
|
|
||||||
@Html.DisplayNameFor(model => model.AccessFailedCount)
|
|
||||||
</th>
|
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -81,45 +45,12 @@
|
|||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.UserName)
|
@Html.DisplayFor(modelItem => item.UserName)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.NormalizedUserName)
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.Email)
|
@Html.DisplayFor(modelItem => item.Email)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.NormalizedEmail)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.EmailConfirmed)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.PasswordHash)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.SecurityStamp)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.ConcurrencyStamp)
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
@Html.DisplayFor(modelItem => item.PhoneNumber)
|
@Html.DisplayFor(modelItem => item.PhoneNumber)
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.PhoneNumberConfirmed)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.TwoFactorEnabled)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.LockoutEnd)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.LockoutEnabled)
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
@Html.DisplayFor(modelItem => item.AccessFailedCount)
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
|
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
|
||||||
<a asp-action="Details" asp-route-id="@item.Id">Details</a> |
|
<a asp-action="Details" asp-route-id="@item.Id">Details</a> |
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;"
|
"DefaultConnection": "Server=.;Database=RentACar;Integrated Security=true;"
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;"
|
"DefaultConnection": "Server=.;Database=RentACar;Integrated Security=true;"
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
|
|||||||
Reference in New Issue
Block a user