Compare commits
3 Commits
3e78e51f7c
...
08306f2f4d
Author | SHA1 | Date | |
---|---|---|---|
08306f2f4d | |||
f89a6e3db9 | |||
74dd85bd7e |
@ -1,10 +1,12 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using PolyclinicBusinessLogic.BusinessLogics;
|
||||
using PolyclinicBusinessLogic.OfficePackage;
|
||||
using PolyclinicContracts.BindingModels;
|
||||
using PolyclinicContracts.BusinessLogicsContracts;
|
||||
using PolyclinicContracts.SearchModels;
|
||||
using PolyclinicContracts.ViewModels;
|
||||
using PolyclinicDataModels.Enums;
|
||||
using PolyclinicDataModels.Models;
|
||||
using PolyclinicWebAppSuretor.Models;
|
||||
using System.Diagnostics;
|
||||
@ -51,6 +53,12 @@ namespace PolyclinicWebAppSuretor.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// USER
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpGet]
|
||||
[HttpPost]
|
||||
public IActionResult Register(RegisterModel model)
|
||||
@ -70,14 +78,112 @@ namespace PolyclinicWebAppSuretor.Controllers
|
||||
model.FIO = model.FIO;
|
||||
return View(model);
|
||||
}
|
||||
/*var user = new UserViewModel {
|
||||
Email
|
||||
};*/
|
||||
var user = new UserBindingModel
|
||||
{
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password,
|
||||
Role = UserRole.Ïîðó÷èòåëü
|
||||
};
|
||||
_userLogic.Create(user);
|
||||
return RedirectToAction("Login");
|
||||
}
|
||||
else
|
||||
{
|
||||
return View();
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpPost]
|
||||
public IActionResult Login(LoginModel model)
|
||||
{
|
||||
var errors = new List<string>();
|
||||
if (HttpContext.Request.Method == "POST")
|
||||
{
|
||||
var user = _userLogic.ReadElement(new UserSearchModel { Email = model.Email, Password = model.Password });
|
||||
if (user == null)
|
||||
{
|
||||
errors.Add("Íåâåðíûå ëîãèí èëè ïàðîëü");
|
||||
}
|
||||
else if (user.Role != UserRole.Ïîðó÷èòåëü)
|
||||
{
|
||||
errors.Add("Ïîëüçîâàòåëü èìååò íåðàçðåøåííóþ ðîëü");
|
||||
}
|
||||
if (errors.Count > 0)
|
||||
{
|
||||
model = new LoginModel
|
||||
{
|
||||
Errors = errors
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
LoginManager.LogginedUser = user;
|
||||
return RedirectToAction("", "Home");
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new();
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Logout()
|
||||
{
|
||||
LoginManager.LogginedUser = null;
|
||||
return RedirectToAction("Login");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[HttpPost]
|
||||
public IActionResult Privacy(UserPrivacyModel model)
|
||||
{
|
||||
var currentUser = LoginManager.LogginedUser;
|
||||
if (currentUser == null)
|
||||
{
|
||||
return RedirectToAction("Login");
|
||||
}
|
||||
if (HttpContext.Request.Method == "POST")
|
||||
{
|
||||
var errors = new List<string>();
|
||||
var checkedUser = _userLogic.ReadElement(new UserSearchModel { Email = model.Email });
|
||||
if (checkedUser != null && checkedUser.Id != LoginManager.LogginedUser.Id)
|
||||
{
|
||||
errors.Add("Ïîëüçîâàòåëü ñ òàêèì Email óæå åñòü");
|
||||
}
|
||||
if (model.Password != model.ConfirmPassword)
|
||||
{
|
||||
errors.Add("Ïàðîëè íå ñîâïàäàþò");
|
||||
}
|
||||
if (errors.Count > 0)
|
||||
{
|
||||
model.Errors = errors;
|
||||
model.Password = string.Empty;
|
||||
model.ConfirmPassword = string.Empty;
|
||||
return View(model);
|
||||
}
|
||||
var user = new UserBindingModel
|
||||
{
|
||||
Id = currentUser.Id,
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password.IsNullOrEmpty() ? LoginManager.LogginedUser.Password : model.Password,
|
||||
};
|
||||
_userLogic.Update(user);
|
||||
LoginManager.LogginedUser = _userLogic.ReadElement(new UserSearchModel { Id = model.Id });
|
||||
return RedirectToAction("Privacy");
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new()
|
||||
{
|
||||
Id = currentUser.Id,
|
||||
FIO = currentUser.FIO,
|
||||
Email = currentUser.Email,
|
||||
Role = currentUser.Role
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
|
||||
|
9
Polyclinic/PolyclinicWebAppSuretor/LoginManager.cs
Normal file
9
Polyclinic/PolyclinicWebAppSuretor/LoginManager.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using PolyclinicContracts.ViewModels;
|
||||
|
||||
namespace PolyclinicWebAppSuretor
|
||||
{
|
||||
public class LoginManager
|
||||
{
|
||||
public static UserViewModel? LogginedUser { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using PolyclinicDataModels.Enums;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace PolyclinicWebAppSuretor.Models
|
||||
{
|
||||
public class UserPrivacyModel : RegisterModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Роль")]
|
||||
public UserRole Role { get; set; }
|
||||
}
|
||||
}
|
12
Polyclinic/PolyclinicWebAppSuretor/RestrictionEnum.cs
Normal file
12
Polyclinic/PolyclinicWebAppSuretor/RestrictionEnum.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace PolyclinicWebAppSuretor
|
||||
{
|
||||
public class RestrictionEnum
|
||||
{
|
||||
public enum PageVisible
|
||||
{
|
||||
AllowAnyBody = 0,
|
||||
AllowOnlyAuthorized = 1,
|
||||
AllowOnlyNotAuthorized = 2,
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +1,23 @@
|
||||
namespace PolyclinicWebAppSuretor
|
||||
using static PolyclinicWebAppSuretor.RestrictionEnum;
|
||||
|
||||
namespace PolyclinicWebAppSuretor
|
||||
{
|
||||
public static class SiteMenuItems
|
||||
{
|
||||
public static (string Url, string Title) Index = ("", "Главная");
|
||||
public static (string Url, string Title) Medicaments = ("Medicaments", "Лекарства");
|
||||
public static (string Url, string Title) Procedures = ("Procedures", "Процедуры");
|
||||
public static (string Url, string Title) Recipes = ("Recipes", "Рецепты");
|
||||
public static (string Url, string Title) Login = ("Login", "Вход");
|
||||
public static (string Url, string Title) Register = ("Register", "Регистрация");
|
||||
public static (string Url, string Title) AddSymptomToMedicament = ("AddSymptomToMedicament", "Привязка симптома к лекарству");
|
||||
public static (string Url, string Title) ProceduresReport = ("ProceduresReport", "Отчет по процедурам");
|
||||
public static (string Url, string Title) ListCoursesByProcedures = ("ListCoursesByProcedures", "Список курсов приема препаратов");
|
||||
public static (string Url, string Title, PageVisible Visible) Index = ("", "Главная", PageVisible.AllowAnyBody);
|
||||
public static (string Url, string Title, PageVisible Visible) Medicaments = ("Medicaments", "Лекарства", PageVisible.AllowOnlyAuthorized);
|
||||
public static (string Url, string Title, PageVisible Visible) Procedures = ("Procedures", "Процедуры", PageVisible.AllowOnlyAuthorized);
|
||||
public static (string Url, string Title, PageVisible Visible) Recipes = ("Recipes", "Рецепты", PageVisible.AllowOnlyAuthorized);
|
||||
public static (string Url, string Title, PageVisible Visible) Login = ("Login", "Вход", PageVisible.AllowOnlyNotAuthorized);
|
||||
public static (string Url, string Title, PageVisible Visible) Register = ("Register", "Регистрация", PageVisible.AllowOnlyNotAuthorized);
|
||||
public static (string Url, string Title, PageVisible Visible) AddSymptomToMedicament = ("AddSymptomToMedicament", "Привязка симптома к лекарству", PageVisible.AllowOnlyAuthorized);
|
||||
public static (string Url, string Title, PageVisible Visible) ProceduresReport = ("ProceduresReport", "Отчет по процедурам", PageVisible.AllowOnlyAuthorized);
|
||||
public static (string Url, string Title, PageVisible Visible) ListCoursesByProcedures = ("ListCoursesByProcedures", "Список курсов приема препаратов", PageVisible.AllowOnlyAuthorized);
|
||||
public static (string Url, string Title, PageVisible Visible) Privacy = ("Privacy", "Личный кабинет", PageVisible.AllowOnlyAuthorized);
|
||||
|
||||
public static List<(string Url, string Title)> MenuItemsOrder = new List<(string Url, string Title)>
|
||||
public static List<(string Url, string Title, PageVisible Visible)> MenuItemsOrder = new List<(string Url, string Title, PageVisible Visible)>
|
||||
{
|
||||
Index, Medicaments, Procedures, Recipes, ListCoursesByProcedures, Login, Register, AddSymptomToMedicament, ProceduresReport
|
||||
Index, Medicaments, Procedures, Recipes, ListCoursesByProcedures, Login, Register, AddSymptomToMedicament, ProceduresReport, Privacy
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,16 @@
|
||||
@{
|
||||
@model LoginModel
|
||||
@{
|
||||
ViewBag.SelectedSiteMenuItem = SiteMenuItems.Login;
|
||||
}
|
||||
<div class="d-flex w-100 h-100 align-content-center justify-content-center align-items-center mt-5 pt-5">
|
||||
<form class="d-flex flex-column border border-primary border-3 rounded-3 p-5" id="loginForm" method="post">
|
||||
<h4>Вход</h4>
|
||||
@foreach (var item in Model.Errors)
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
@item
|
||||
</div>
|
||||
}
|
||||
<div class="mb-2 row">
|
||||
<label for="emailInput" class="col-4 ps-0">
|
||||
Email
|
||||
|
@ -1,6 +1,38 @@
|
||||
@{
|
||||
ViewData["Title"] = "Privacy Policy";
|
||||
@model UserPrivacyModel
|
||||
@{
|
||||
ViewBag.SelectedSiteMenuItem = SiteMenuItems.Privacy;
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
<h4>Личный кабинет</h4>
|
||||
@foreach (var item in Model.Errors)
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
@item
|
||||
</div>
|
||||
}
|
||||
<form method="post">
|
||||
<input hidden readonly asp-for="Id" />
|
||||
<div class="mb-3">
|
||||
<label asp-for="FIO"></label>
|
||||
<input required asp-for="FIO" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Email"></label>
|
||||
<input required asp-for="Email" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Role"></label>
|
||||
<input readonly asp-for="Role" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="Password"></label>
|
||||
<input type="password" asp-for="Password" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label asp-for="ConfirmPassword"></label>
|
||||
<input type="password" asp-for="ConfirmPassword" />
|
||||
</div>
|
||||
<button class="btn btn-secondary" type="submit">
|
||||
Применить
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p>Use this page to detail your site's privacy policy.</p>
|
||||
|
@ -1,8 +1,16 @@
|
||||
@model RegisterModel
|
||||
|
||||
@{
|
||||
ViewBag.SelectedSiteMenuItem = SiteMenuItems.Register;
|
||||
}
|
||||
<div class="d-flex w-100 h-100 align-content-center justify-content-center align-items-center mt-5 pt-5">
|
||||
<form class="d-flex flex-column border border-success border-3 rounded-3 p-5" id="loginForm" method="post">
|
||||
<h4>Регистрация</h4>
|
||||
@foreach (var item in Model.Errors)
|
||||
{
|
||||
<div class="alert alert-danger" role="alert">
|
||||
@item
|
||||
</div>
|
||||
}
|
||||
<div class="d-flex mb-3">
|
||||
<label for="fioInput" class="pe-3 w-25">
|
||||
ФИО
|
||||
|
@ -1,26 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
@using static PolyclinicWebAppSuretor.RestrictionEnum
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>
|
||||
@if (ViewData.ContainsKey("SelectedSiteMenuItem"))
|
||||
{
|
||||
@ViewBag.SelectedSiteMenuItem.Item2
|
||||
}
|
||||
else if (ViewData.ContainsKey("Title"))
|
||||
{
|
||||
@if (ViewData.ContainsKey("Title"))
|
||||
{
|
||||
<title>
|
||||
@ViewData["Title"]
|
||||
}
|
||||
</title>
|
||||
</title>
|
||||
}
|
||||
else
|
||||
{
|
||||
<title>Боликлиника</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="~/PolyclinicWebAppSuretor.styles.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/PolyclinicWebView.styles.css" asp-append-version="true" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<header class="sticky-top">
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="#">
|
||||
<img src="~/img/polyclinic_logo_mini.svg" height="30" alt="Logo" class="d-inline-block align-text-top">
|
||||
</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>
|
||||
@ -29,19 +33,33 @@
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
@foreach (var menuItem in SiteMenuItems.MenuItemsOrder)
|
||||
{
|
||||
<li class="menu-item">
|
||||
@Html.RouteLink(menuItem.Title, new
|
||||
{
|
||||
controller = "Home",
|
||||
action = menuItem.Url
|
||||
}, new
|
||||
{
|
||||
@class = "nav-link text-dark" + (menuItem.Equals(ViewBag.SelectedSiteMenuItem) ? " fw-bold" : "")
|
||||
}
|
||||
)
|
||||
</li>
|
||||
@if (menuItem.Visible == PageVisible.AllowAnyBody ||
|
||||
LoginManager.LogginedUser == null && menuItem.Visible == PageVisible.AllowOnlyNotAuthorized ||
|
||||
LoginManager.LogginedUser != null && menuItem.Visible == PageVisible.AllowOnlyAuthorized)
|
||||
{
|
||||
<li class="menu-item">
|
||||
@Html.RouteLink(menuItem.Title, new
|
||||
{
|
||||
controller = "Home",
|
||||
action = menuItem.Url
|
||||
}, new
|
||||
{
|
||||
@class = "nav-link text-dark" + (menuItem.Equals(ViewBag.SelectedSiteMenuItem) ? " fw-bold" : "")
|
||||
}
|
||||
)
|
||||
</li>
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
@if (LoginManager.LogginedUser != null)
|
||||
{
|
||||
<div class="d-flex align-items-center">
|
||||
@Html.RouteLink(LoginManager.LogginedUser.FIO, new { controller = "User", action = "Privacy" }, new { @title = "Личный кабинет" })
|
||||
<form class="ms-3" method="post" asp-action="Logout" asp-controller="User">
|
||||
<button class="btn btn-secondary" type="submit">Выйти</button>
|
||||
</form>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@ -52,9 +70,9 @@
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<footer class="border-top footer text-muted bg-light fixed-bottom">
|
||||
<div class="container">
|
||||
© 2024 - Поликлиника "Будьте больны" - <a asp-area="" asp-controller="Home" asp-action="Privacy">Политика конфедициальности</a>
|
||||
© 2024 - Поликлиника БудьтеБольны
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||
|
Loading…
Reference in New Issue
Block a user