Removed unsued properties from user controller index
This commit is contained in:
@@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace WebApp.Areas.Identity.Pages.Account
|
||||
{
|
||||
@@ -23,16 +22,19 @@ namespace WebApp.Areas.Identity.Pages.Account
|
||||
{
|
||||
private readonly SignInManager<User> _signInManager;
|
||||
private readonly UserManager<User> _userManager;
|
||||
private readonly RoleManager<IdentityRole> _roleManager;
|
||||
private readonly ILogger<RegisterModel> _logger;
|
||||
private readonly IEmailSender _emailSender;
|
||||
|
||||
public RegisterModel(
|
||||
UserManager<User> userManager,
|
||||
SignInManager<User> signInManager,
|
||||
RoleManager<IdentityRole> roleManager,
|
||||
ILogger<RegisterModel> logger,
|
||||
IEmailSender emailSender)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_roleManager = roleManager;
|
||||
_signInManager = signInManager;
|
||||
_logger = logger;
|
||||
_emailSender = emailSender;
|
||||
@@ -57,13 +59,12 @@ namespace WebApp.Areas.Identity.Pages.Account
|
||||
[Display(Name = "Email")]
|
||||
public string Email { get; set; }
|
||||
|
||||
[Display(Name = "First name")]
|
||||
[Display(Name = "First Name")]
|
||||
public string FirstName { get; set; }
|
||||
|
||||
[Display(Name = "Last name")]
|
||||
[Display(Name = "Last Name")]
|
||||
public string LastName { get; set; }
|
||||
|
||||
[Phone]
|
||||
[Display(Name = "Phone")]
|
||||
public string PhoneNumber { get; set; }
|
||||
|
||||
@@ -98,6 +99,9 @@ namespace WebApp.Areas.Identity.Pages.Account
|
||||
var result = await _userManager.CreateAsync(user, Input.Password);
|
||||
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.");
|
||||
|
||||
var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
|
||||
|
||||
@@ -70,6 +70,7 @@ namespace WebApp.Controllers
|
||||
|
||||
// GET: Cars/Edit/5
|
||||
[HttpGet]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public async Task<IActionResult> Edit(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
@@ -90,6 +91,7 @@ namespace WebApp.Controllers
|
||||
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public async Task<IActionResult> Edit(int id, [Bind("Id, Brand, Model, Year, CountPassengerSeats, Description, PriceForDay")] Car car)
|
||||
{
|
||||
if (id != car.Id)
|
||||
@@ -122,6 +124,7 @@ namespace WebApp.Controllers
|
||||
|
||||
// GET: Cars/Delete/5
|
||||
[HttpGet]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public async Task<IActionResult> Delete(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
|
||||
@@ -7,9 +7,21 @@ using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Data;
|
||||
using Data.Entities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
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
|
||||
{
|
||||
private readonly RentACarDbContext _context;
|
||||
@@ -20,52 +32,36 @@ namespace WebApp.Controllers
|
||||
}
|
||||
|
||||
// GET: Users
|
||||
[Authorize(Roles = "Admin")]
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
return View(await _context.Users.ToListAsync());
|
||||
}
|
||||
ICollection<User> users = await _context.Users.ToListAsync();
|
||||
|
||||
// GET: Users/Details/5
|
||||
public async Task<IActionResult> Details(string id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
ICollection<UserWithRoles> usersWithRole = new List<UserWithRoles>();
|
||||
|
||||
var user = await _context.Users
|
||||
.FirstOrDefaultAsync(m => m.Id == id);
|
||||
if (user == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
//foreach (var item in users)
|
||||
//{
|
||||
// var userRole = await _context.UserRoles.FirstOrDefaultAsync(userRoles => userRoles.UserId == item.Id);
|
||||
// var role = await _context.Roles.FirstOrDefaultAsync(role => role.Id == userRole.RoleId);
|
||||
// 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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
return View(users);
|
||||
}
|
||||
|
||||
// GET: Users/Edit/5
|
||||
[Authorize(Roles = "Admin")]
|
||||
public async Task<IActionResult> Edit(string id)
|
||||
{
|
||||
if (id == null)
|
||||
@@ -86,6 +82,7 @@ namespace WebApp.Controllers
|
||||
// For more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[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)
|
||||
{
|
||||
if (id != user.Id)
|
||||
@@ -117,6 +114,7 @@ namespace WebApp.Controllers
|
||||
}
|
||||
|
||||
// GET: Users/Delete/5
|
||||
[Authorize(Roles = "Admin")]
|
||||
public async Task<IActionResult> Delete(string id)
|
||||
{
|
||||
if (id == null)
|
||||
@@ -137,6 +135,7 @@ namespace WebApp.Controllers
|
||||
// POST: Users/Delete/5
|
||||
[HttpPost, ActionName("Delete")]
|
||||
[ValidateAntiForgeryToken]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public async Task<IActionResult> DeleteConfirmed(string id)
|
||||
{
|
||||
var user = await _context.Users.FindAsync(id);
|
||||
|
||||
@@ -24,9 +24,15 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Cars" asp-action="Index">Cars</a>
|
||||
</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">
|
||||
<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>
|
||||
}
|
||||
</ul>
|
||||
<partial name="_LoginPartial" />
|
||||
</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>
|
||||
|
||||
<p>
|
||||
<a asp-action="Create">Create New</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -24,45 +21,12 @@
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.UserName)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.NormalizedUserName)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Email)
|
||||
</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>
|
||||
@Html.DisplayNameFor(model => model.PhoneNumber)
|
||||
</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>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -81,45 +45,12 @@
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.UserName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.NormalizedUserName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Email)
|
||||
</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>
|
||||
@Html.DisplayFor(modelItem => item.PhoneNumber)
|
||||
</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>
|
||||
<a asp-action="Edit" asp-route-id="@item.Id">Edit</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>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;"
|
||||
"DefaultConnection": "Server=.;Database=RentACar;Integrated Security=true;"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=.\\SQLEXPRESS;Database=RentACar;Integrated Security=true;"
|
||||
"DefaultConnection": "Server=.;Database=RentACar;Integrated Security=true;"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
||||
Reference in New Issue
Block a user