asp.net/winforms login; uml managers, repositories pages edited

This commit is contained in:
Dimitar Byalkov
2023-03-31 01:01:20 +02:00
parent 78eba13712
commit 99e2b2a0cd
16 changed files with 322 additions and 20 deletions

View File

@@ -0,0 +1,12 @@
@page
@model WebApp.Pages.Error._401Model
@{
ViewData["Title"] = "401 Unauthorised";
}
<div class="text-center">
<h1 class="display-4">Error 401 Unauthorised</h1>
<img src="http://http.cat/401" />
<p>
You do not have rights to access this page!
</p>
</div>

View File

@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages.Error
{
public class _401Model : PageModel
{
public void OnGet()
{
}
}
}

View File

@@ -15,13 +15,6 @@
</div>
</div>
<div class="px-4 py-5 my-5 text-center">
<h2 class="display-5 fw-bold">Why choose our solution?</h2>
<div class="col-lg-6 mx-auto">
<p class="lead mb-4">Student House Dashboard helps tenants organise common household chores even if they don't know each other very well.</p>
</div>
</div>
<div class="px-4 py-5 my-5 text-center">
<h2 class="display-5 fw-bold">Is it difficult to use?</h2>
<div class="col-lg-6 mx-auto">

View File

@@ -1,7 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using StudentHouseDashboard.Models;
using StudentHouseDashboard.Managers;
using System.Security.Claims;
namespace WebApp.Pages
{
@@ -14,19 +17,33 @@ namespace WebApp.Pages
{
}
public void OnPost()
public IActionResult OnPost(string? returnUrl)
{
var userManager = new UserManager();
foreach (var item in userManager.GetAllUsers())
User? user = userManager.AuthenticatedUser(MyUser.Name, MyUser.Password);
if (user != null)
{
if (item.Name == MyUser.Name && BCrypt.Net.BCrypt.Verify(MyUser.Password, item.Password))
List<Claim> claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, user.Name));
claims.Add(new Claim("id", user.ID.ToString()));
claims.Add(new Claim(ClaimTypes.Role, user.Role.ToString()));
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
HttpContext.SignInAsync(new ClaimsPrincipal(claimsIdentity));
// ViewData["confirm"] = $"Welcome, {MyUser.Name}! {MyUser.ID}, {MyUser.Password}, {MyUser.Role}";
if (!String.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl))
{
MyUser = item;
ViewData["confirm"] = $"Welcome, {MyUser.Name}! {MyUser.ID}, {MyUser.Password}, {MyUser.Role}";
return Redirect(returnUrl);
}
else
{
return RedirectToPage("Announcements");
}
}
else
{
ModelState.AddModelError("InvalidCredentials", "The supplied username and/or password is invalid");
return Page();
}
}
}
}

View File

@@ -23,10 +23,7 @@
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Contact">Contact</a>
<a class="nav-link text-dark" asp-area="" asp-page="/Announcements">Announcements</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Login">Login</a>
@@ -44,7 +41,7 @@
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2023 - StudentHouseDashboard - <a asp-area="" asp-page="/Privacy">Privacy</a>
<p>StudentHouseDashboard &copy; 2023 <a asp-area="" asp-page="/Privacy">Privacy</a> <a asp-area="" asp-page="/Contact">Contact</a></p>
</div>
</footer>

View File

@@ -1,3 +1,5 @@
using Microsoft.AspNetCore.Authentication.Cookies;
namespace WebApp
{
public class Program
@@ -9,6 +11,11 @@ namespace WebApp
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => {
options.LoginPath = new PathString("/Login");
options.AccessDeniedPath = new PathString("/Error/401");
});
var app = builder.Build();
// Configure the HTTP request pipeline.