Сделана регистрация + вход + отображение личных данных для воркера

This commit is contained in:
DyCTaTOR 2024-05-27 00:50:40 +04:00
parent d7753b4c27
commit 9d7db7a41b
14 changed files with 296 additions and 82 deletions

View File

@ -15,7 +15,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityRestApi", "Univer
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityClientAppStorekeeper", "UniversityClientApp\UniversityClientAppStorekeeper.csproj", "{65698622-8424-4D8E-BFC9-721BB5252F22}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityClientAppStorekeeper", "UniversityClientApp\UniversityClientAppStorekeeper.csproj", "{65698622-8424-4D8E-BFC9-721BB5252F22}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversityClientAppWorker", "UniversityClientAppWorker\UniversityClientAppWorker.csproj", "{11E2609A-BD4A-4D03-8B71-4EC0DF1CDC88}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniversityClientAppWorker", "UniversityClientAppWorker\UniversityClientAppWorker.csproj", "{11E2609A-BD4A-4D03-8B71-4EC0DF1CDC88}"
ProjectSection(ProjectDependencies) = postProject
{4F0BB8C6-2BA8-4212-BC86-4E66C1C03816} = {4F0BB8C6-2BA8-4212-BC86-4E66C1C03816}
EndProjectSection
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -0,0 +1,45 @@
using Newtonsoft.Json;
using UniversityContracts.ViewModels;
using System.Net.Http.Headers;
using System.Text;
namespace PlumbingRepairClientApp
{
public class APIClient
{
private static readonly HttpClient _client = new();
public static UserViewModel? User { get; set; } = null;
public static void Connect(IConfiguration configuration)
{
_client.BaseAddress = new Uri(configuration["IPAddress"]);
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
public static T? GetRequest<T>(string requestUrl)
{
var response = _client.GetAsync(requestUrl);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (response.Result.IsSuccessStatusCode)
{
return JsonConvert.DeserializeObject<T>(result);
}
else
{
throw new Exception(result);
}
}
public static void PostRequest<T>(string requestUrl, T model)
{
var json = JsonConvert.SerializeObject(model);
var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = _client.PostAsync(requestUrl, data);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (!response.Result.IsSuccessStatusCode)
{
throw new Exception(result);
}
}
}
}

View File

@ -1,6 +1,9 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PlumbingRepairClientApp;
using System.Diagnostics; using System.Diagnostics;
using UniversityClientAppWorker.Models; using UniversityClientAppWorker.Models;
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityDataModels.Enums; using UniversityDataModels.Enums;
namespace UniversityClientAppWorker.Controllers namespace UniversityClientAppWorker.Controllers
@ -13,29 +16,93 @@ namespace UniversityClientAppWorker.Controllers
{ {
_logger = logger; _logger = logger;
} }
[HttpGet]
public IActionResult Index()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<PlanOfStudyViewModel>>($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}"));
}
[HttpPost]
public void CreatePlanOfStudy(string profile, string formOfStudy)
{
if (APIClient.User == null)
{
throw new Exception("Âõîä òîëüêî àâòîðèçîâàííûì ïîëüçîâàòåëÿì");
}
if (string.IsNullOrEmpty(formOfStudy) || string.IsNullOrEmpty(profile))
{
throw new Exception("Ââåäèòå äàííûå ïðîôèëÿ è ôîðìû îáó÷åíèÿ");
}
APIClient.PostRequest("api/planofstudys/createplanofstudy", new PlanOfStudyBindingModel
{
Profile = profile,
FormOfStudy = formOfStudy,
UserId = APIClient.User.Id
});
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Privacy()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.User);
}
[HttpPost]
public void Privacy(string login, string password, string email)
{
if (APIClient.User == null)
{
throw new Exception("Âõîä òîëüêî àâòîðèçîâàííûì ïîëüçîâàòåëÿì");
}
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
{
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ïî÷òó");
}
APIClient.PostRequest("api/user/updatedata", new UserViewModel
{
Id = APIClient.User.Id,
Email = email,
Login = login,
Password = password
});
public IActionResult Index() APIClient.User.Login = login;
APIClient.User.Email = email;
APIClient.User.Password = password;
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Attestations()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast<AttestationScore>();
return View();
}
[HttpGet]
public IActionResult Students()
{
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpGet]
public IActionResult Enter()
{ {
return View(); return View();
} }
[HttpGet]
public IActionResult Privacy() public IActionResult Register()
{
return View();
}
public IActionResult Attestations()
{
ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast<AttestationScore>();
return View();
}
public IActionResult Students()
{
return View();
}
public IActionResult PlanOfStudys()
{ {
return View(); return View();
} }
@ -45,5 +112,35 @@ namespace UniversityClientAppWorker.Controllers
{ {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
} }
} [HttpPost]
public void Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{
throw new Exception("Ââåäèòå ëîãèí è ïàðîëü");
}
APIClient.User = APIClient.GetRequest<UserViewModel>($"api/user/loginworker?login={login}&password={password}");
if (APIClient.User == null)
{
throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü");
}
Response.Redirect("Index");
}
[HttpPost]
public void Register(string login, string password, string email)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(email))
{
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ïî÷òó");
}
APIClient.PostRequest("api/user/registerworker", new UserBindingModel
{
Email = email,
Login = login,
Password = password
});
Response.Redirect("Enter");
return;
}
}
} }

View File

@ -1,3 +1,5 @@
using PlumbingRepairClientApp;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
@ -5,6 +7,7 @@ builder.Services.AddControllersWithViews();
var app = builder.Build(); var app = builder.Build();
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())
{ {

View File

@ -11,6 +11,7 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -5,16 +5,16 @@
<h2 class="display-4">Вход в приложение</h2> <h2 class="display-4">Вход в приложение</h2>
</div> </div>
<form method="post"> <form method="post">
<div class="row"> <div class="row">
<div class="col-4">Логин:</div> <div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="login" /></div> <div class="col-8"><input type="text" name="login" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Пароль:</div> <div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" /></div> <div class="col-8"><input type="password" name="password" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"><input type="submit" value="Вход" class="btn btnprimary" /></div> <div class="col-4"><input type="submit" value="Вход" class="btn btndanger" /></div>
</div> </div>
</form> </form>

View File

@ -1,15 +1,59 @@
@{ @using UniversityContracts.ViewModels
ViewData["Title"] = "Home Page"; @model List<PlanOfStudyViewModel>
@{
ViewData["Title"] = "Управление планами обучений";
} }
<div class="text-center"> <div class="text-center">
<h2 class="display-4">@ViewData["Title"]</h2>
<div class="menu">
<a href="/Home/Students">Студенты</a>
<a href="/Home/PlanOfStudys">Планы обучения</a>
<a href="/Home/Attestations">Аттестации</a>
</div>
<div class="header">
<img src="" alt="Logo" class="logo">
</div>
</div> </div>
<form asp-action="CreatePlanOfStudy" method="post">
<div class="row">
<div class="col-4">Профиль:</div>
<div class="col-8">
<input type="text" name="profile" id="profile" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-4">Форма обучения:</div>
<div class="col-8">
<input name="formOfStudy" id="formOfStudy" class="form-control" multiple asp-items="ViewBag.PlanOfStudys"></input>
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4 mt-2">
<input type="submit" value="Создать план обучения" class="btn btn-danger" />
</div>
</div>
</form>
<table class="table">
<thead>
<tr>
<th>Profile</th>
<th>FormOfStudy</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var planOfStudy in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => planOfStudy.Id)
</td>
<td>@planOfStudy.FormOfStudy</td>
<td>
</td>
<td>
<a asp-action="Edit" asp-route-id="@planOfStudy.Id" class="btn btn-warning">Edit</a>
<a asp-action="Details" asp-route-id="@planOfStudy.Id" class="btn btn-info">Details</a>
<a asp-action="Delete" asp-route-id="@planOfStudy.Id" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>

View File

@ -1,6 +1,26 @@
@{ @using UniversityContracts.ViewModels
@model UserViewModel
@{
ViewData["Title"] = "Privacy Policy"; ViewData["Title"] = "Privacy Policy";
} }
<h1>@ViewData["Title"]</h1> <div class="text-center">
<h2 class="display-4">Личные данные</h2>
<p>Use this page to detail your site's privacy policy.</p> </div>
<form method="post">
<div class="row">
<div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="login" value="@Model.Login" /></div>
</div>
<div class="row">
<div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" value="@Model.Password" /></div>
</div>
<div class="row">
<div class="col-4">E-mail:</div>
<div class="col-8"><input type="text" name="email" value="@Model.Email" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-danger" /></div>
</div>
</form>

View File

@ -5,33 +5,21 @@
<h2 class="display-4">Регистрация</h2> <h2 class="display-4">Регистрация</h2>
</div> </div>
<form method="post"> <form method="post">
<div class="row">
<div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="email" /></div>
</div>
<div class="row">
<div class="col-4">Пароль:</div>
<div class="col-8"><input type="password" name="password" /></div>
</div>
<div class="row">
<div class="col-4">Фамилия:</div>
<div class="col-8"><input type="text" name="lastName" /></div>
</div>
<div class="row"> <div class="row">
<div class="col-4">Имя:</div> <div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="firstName" /></div> <div class="col-8"><input type="text" name="login" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Отчество:</div> <div class="col-4">Почта:</div>
<div class="col-8"><input type="text" name="midleName" /></div> <div class="col-8"><input type="text" name="email" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Телефон:</div> <div class="col-4">Пароль:</div>
<div class="col-8"><input type="text" name="phoneNumber" /></div> <div class="col-8"><input type="password" name="password" /></div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Регистрация"
class="btn btn-primary" /></div>
</div> </div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Регистрация"
class="btn btn-primary" /></div>
</div>
</form> </form>

View File

@ -20,10 +20,22 @@
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between"> <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1"> <ul class="navbar-nav flex-grow-1">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Планы обучения</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Students">Студенты</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Attestations">Аттестация</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -5,5 +5,7 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*",
"IPAddress": "http://localhost:5032/"
} }

View File

@ -12,7 +12,6 @@ namespace UniversityContracts.ViewModels
{ {
public int Id { get; set; } public int Id { get; set; }
public int UserId { get; set; } public int UserId { get; set; }
public int WorkerId { get; set; }
[DisplayName("Профиль")] [DisplayName("Профиль")]
public string Profile { get; set; } = string.Empty; public string Profile { get; set; } = string.Empty;
[DisplayName("Форма обучения")] [DisplayName("Форма обучения")]

View File

@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
//Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -22,7 +22,7 @@ namespace UniversityRestApi.Controllers
{ {
try try
{ {
return _logic.ReadList(new PlanOfStudySearchModel { UserId = userId }); return _logic.ReadList(new PlanOfStudySearchModel { });
} }
catch (Exception ex) catch (Exception ex)
{ {