Documentation & code cleanup

This commit is contained in:
Dimitar Byalkov
2023-06-09 11:51:42 +02:00
parent 0ac97bd31a
commit 1832e111e3
61 changed files with 140 additions and 325 deletions

View File

@@ -1,5 +1,4 @@
using Logic;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Models;

View File

@@ -1,9 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Logic;
using Models;
using Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{

View File

@@ -1,9 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Logic;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Models;
using System.Security.Claims;
namespace WebApp.Pages
{

View File

@@ -1,9 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Logic;
using Models;
using Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{

View File

@@ -1,8 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Logic;
using Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Security.Claims;
namespace WebApp.Pages

View File

@@ -24,7 +24,7 @@ namespace WebApp.Pages
if (id != null)
{
Announcement announcement = announcementManager.GetAnnouncementById(id);
if (announcement.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN") )
if (announcement.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN"))
{
ViewData["announcement"] = announcement;
}

View File

@@ -26,7 +26,7 @@ namespace WebApp.Pages
if (id != null)
{
Event @event = eventManager.GetEventById(id.Value);
if (@event.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN") )
if (@event.Author.ID == int.Parse(User.FindFirstValue("id")) || User.IsInRole("ADMIN"))
{
ViewData["event"] = @event;
}
@@ -46,7 +46,7 @@ namespace WebApp.Pages
EventManager eventManager = new EventManager(_eventRepository);
eventManager.UpdateEvent(Event.ID, Event.Title, Event.Description, Event.StartDate, Event.EndDate);
}
return RedirectToPage("Events");
}
}

View File

@@ -1,4 +1,3 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages.Error

View File

@@ -1,4 +1,3 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages.Error

View File

@@ -1,9 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Logic;
using Models;
using Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{

View File

@@ -1,10 +1,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Logic;
using Models;
using System.Security.Claims;
using System.Dynamic;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{

View File

@@ -1,6 +1,4 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{

View File

@@ -1,11 +1,11 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Data;
using Logic;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Models;
using Logic;
using System.Security.Claims;
using Data;
namespace WebApp.Pages
{

View File

@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApp.Pages
{

View File

@@ -1,8 +1,8 @@
using Data;
using Logic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Logic;
using Models;
using Data;
namespace WebApp.Pages
{
@@ -16,9 +16,21 @@ namespace WebApp.Pages
public void OnPost()
{
var userManager = new UserManager(new UserRepository());
if (userManager.CreateUser(MyUser.Name, BCrypt.Net.BCrypt.HashPassword(MyUser.Password), MyUser.Role) != null)
User? result = null;
try
{
ViewData["confirm"] = $"Successfully registered {MyUser.Name}!";
result = userManager.CreateUser(MyUser.Name, BCrypt.Net.BCrypt.HashPassword(MyUser.Password), MyUser.Role);
}
catch (ArgumentException)
{
ViewData["confirm"] = "An error has occurred. Try a different username.";
}
finally
{
if (result != null)
{
ViewData["confirm"] = $"Successfully registered {MyUser.Name}!";
}
}
}
}

View File

@@ -13,7 +13,8 @@ namespace WebApp
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => {
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
{
options.LoginPath = new PathString("/Login");
options.AccessDeniedPath = new PathString("/Error/401");
});