user login, register, hashed passwords, announcements start
This commit is contained in:
4
StudentHouseDashboard/WebApp/Pages/Announcement.cshtml
Normal file
4
StudentHouseDashboard/WebApp/Pages/Announcement.cshtml
Normal file
@@ -0,0 +1,4 @@
|
||||
@page
|
||||
@model WebApp.Pages.AnnouncementModel
|
||||
@{
|
||||
}
|
12
StudentHouseDashboard/WebApp/Pages/Announcement.cshtml.cs
Normal file
12
StudentHouseDashboard/WebApp/Pages/Announcement.cshtml.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
public class AnnouncementModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
15
StudentHouseDashboard/WebApp/Pages/Announcements.cshtml
Normal file
15
StudentHouseDashboard/WebApp/Pages/Announcements.cshtml
Normal file
@@ -0,0 +1,15 @@
|
||||
@page
|
||||
@model WebApp.Pages.AnnouncementsModel
|
||||
@{
|
||||
ViewData["Title"] = "Announcements";
|
||||
}
|
||||
|
||||
<div class="card" style="width: 18rem;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Card title</h5>
|
||||
<h6 class="card-subtitle mb-2 text-muted">Card subtitle</h6>
|
||||
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
|
||||
<a href="#" class="card-link">Card link</a>
|
||||
<a href="#" class="card-link">Another link</a>
|
||||
</div>
|
||||
</div>
|
12
StudentHouseDashboard/WebApp/Pages/Announcements.cshtml.cs
Normal file
12
StudentHouseDashboard/WebApp/Pages/Announcements.cshtml.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
public class AnnouncementsModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
26
StudentHouseDashboard/WebApp/Pages/Login.cshtml
Normal file
26
StudentHouseDashboard/WebApp/Pages/Login.cshtml
Normal file
@@ -0,0 +1,26 @@
|
||||
@page
|
||||
@model WebApp.Pages.LoginModel
|
||||
@{
|
||||
ViewData["Title"] = "Login";
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
@if (ViewData["confirm"] != null)
|
||||
{
|
||||
<div class="alert alert-primary" role="alert">
|
||||
@ViewData["confirm"]
|
||||
</div>
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label asp-for="MyUser.Name" class="form-label">Name: </label>
|
||||
<input asp-for="MyUser.Name" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="MyUser.Password" class="form-label">Password: </label>
|
||||
<input asp-for="MyUser.Password" class="form-control" />
|
||||
</div>
|
||||
<input type="submit" value="Submit" class="btn btn-primary" />
|
||||
</form>
|
32
StudentHouseDashboard/WebApp/Pages/Login.cshtml.cs
Normal file
32
StudentHouseDashboard/WebApp/Pages/Login.cshtml.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using StudentHouseDashboard.Models;
|
||||
using StudentHouseDashboard.Managers;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
public class LoginModel : PageModel
|
||||
{
|
||||
[BindProperty]
|
||||
public User MyUser { get; set; }
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnPost()
|
||||
{
|
||||
var userManager = new UserManager();
|
||||
|
||||
foreach (var item in userManager.GetAllUsers())
|
||||
{
|
||||
if (item.Name == MyUser.Name && BCrypt.Net.BCrypt.Verify(MyUser.Password, item.Password))
|
||||
{
|
||||
MyUser = item;
|
||||
ViewData["confirm"] = $"Welcome, {MyUser.Name}! {MyUser.Id}, {MyUser.Password}, {MyUser.Role}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
30
StudentHouseDashboard/WebApp/Pages/Register.cshtml
Normal file
30
StudentHouseDashboard/WebApp/Pages/Register.cshtml
Normal file
@@ -0,0 +1,30 @@
|
||||
@page
|
||||
@model WebApp.Pages.RegisterModel
|
||||
@{
|
||||
ViewData["Title"] = "Register";
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
@if (ViewData["confirm"] != null)
|
||||
{
|
||||
<div class="alert alert-primary" role="alert">
|
||||
@ViewData["confirm"]
|
||||
</div>
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
<div class="mb-3">
|
||||
<label asp-for="MyUser.Role" class="form-label">Role: </label>
|
||||
<input asp-for="MyUser.Role" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="MyUser.Name" class="form-label">Name: </label>
|
||||
<input asp-for="MyUser.Name" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="MyUser.Password" class="form-label">Password: </label>
|
||||
<input asp-for="MyUser.Password" class="form-control" />
|
||||
</div>
|
||||
<input type="submit" value="Submit" class="btn btn-primary" />
|
||||
</form>
|
24
StudentHouseDashboard/WebApp/Pages/Register.cshtml.cs
Normal file
24
StudentHouseDashboard/WebApp/Pages/Register.cshtml.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using StudentHouseDashboard.Managers;
|
||||
using StudentHouseDashboard.Models;
|
||||
|
||||
namespace WebApp.Pages
|
||||
{
|
||||
public class RegisterModel : PageModel
|
||||
{
|
||||
[BindProperty]
|
||||
public User MyUser { get; set; }
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
public void OnPost()
|
||||
{
|
||||
var userManager = new UserManager();
|
||||
if (userManager.CreateUser(MyUser.Name, BCrypt.Net.BCrypt.HashPassword(MyUser.Password), MyUser.Role))
|
||||
{
|
||||
ViewData["confirm"] = $"Successfully registered {MyUser.Name}!";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - WebApp</title>
|
||||
<title>@ViewData["Title"] - StudentHouseDashboard</title>
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/WebApp.styles.css" asp-append-version="true" />
|
||||
@@ -12,7 +12,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-page="/Index">WebApp</a>
|
||||
<a class="navbar-brand" asp-area="" asp-page="/Index">StudentHouseDashboard</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
@@ -28,6 +28,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Contact">Contact</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-page="/Login">Login</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -41,7 +44,7 @@
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2023 - WebApp - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
© 2023 - StudentHouseDashboard - <a asp-area="" asp-page="/Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
@@ -25,4 +25,12 @@
|
||||
<_ContentIncludedByDefault Remove="Pages\Contact.cshtml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HouseData\StudentHouseDashboard.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user