diff --git a/Hcs.WebApp/Components/Pages/Account/Login.razor b/Hcs.WebApp/Components/Pages/Account/Login.razor
new file mode 100644
index 0000000..dd5f11d
--- /dev/null
+++ b/Hcs.WebApp/Components/Pages/Account/Login.razor
@@ -0,0 +1,71 @@
+@page "/account/login"
+
+@inject NotificationService NotificationService
+
+Вход в систему
+
+
+
+
+ Вход
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+@code {
+ sealed class InputModel
+ {
+ public string UserName { get; set; } = "";
+
+ public string Password { get; set; } = "";
+ }
+
+ [SupplyParameterFromForm]
+ InputModel Input { get; set; } = new();
+
+ [SupplyParameterFromQuery]
+ string? Status { get; set; }
+
+ [SupplyParameterFromQuery]
+ string? ReturnUrl { get; set; }
+
+ protected override void OnAfterRender(bool firstRender)
+ {
+ base.OnAfterRender(firstRender);
+
+ if (firstRender)
+ {
+ if (Status == "failed")
+ {
+ NotificationService.Notify(new NotificationMessage()
+ {
+ Severity = NotificationSeverity.Error,
+ Summary = "Ошибка",
+ Detail = "Неверный логин или пароль",
+ Duration = -1d
+ });
+ }
+ }
+ }
+}
diff --git a/Hcs.WebApp/Components/Pages/Account/Register.razor b/Hcs.WebApp/Components/Pages/Account/Register.razor
index dd03f9d..f4eaee1 100644
--- a/Hcs.WebApp/Components/Pages/Account/Register.razor
+++ b/Hcs.WebApp/Components/Pages/Account/Register.razor
@@ -56,7 +56,7 @@
InputModel Input { get; set; } = new();
[SupplyParameterFromQuery]
- string? Errors { get; set; }
+ string? Error { get; set; }
[SupplyParameterFromQuery]
string? ReturnUrl { get; set; }
@@ -67,13 +67,13 @@
if (firstRender)
{
- if (!string.IsNullOrEmpty(Errors))
+ if (!string.IsNullOrEmpty(Error))
{
NotificationService.Notify(new NotificationMessage()
{
Severity = NotificationSeverity.Error,
Summary = "Ошибка",
- Detail = Errors,
+ Detail = Error,
Duration = -1d
});
}
diff --git a/Hcs.WebApp/Controllers/IdentityController.cs b/Hcs.WebApp/Controllers/IdentityController.cs
index 25f1ca1..5711677 100644
--- a/Hcs.WebApp/Controllers/IdentityController.cs
+++ b/Hcs.WebApp/Controllers/IdentityController.cs
@@ -24,14 +24,14 @@ namespace Hcs.WebApp.Controllers
var result = await userManager.CreateAsync(user, password);
if (!result.Succeeded)
{
- var errors = string.Join(", ", result.Errors.Select(error => error.Description));
+ var error = string.Join(", ", result.Errors.Select(error => error.Description));
if (!string.IsNullOrEmpty(returnUrl))
{
- return Redirect($"/account/register?errors={errors}&returnUrl={Uri.EscapeDataString(returnUrl)}");
+ return Redirect($"/account/register?error={error}&returnUrl={Uri.EscapeDataString(returnUrl)}");
}
else
{
- return Redirect($"/account/register?errors={errors}");
+ return Redirect($"/account/register?error={error}");
}
}
@@ -45,6 +45,30 @@ namespace Hcs.WebApp.Controllers
return Redirect(returnUrl);
}
+ [HttpPost]
+ public async Task Login(string userName, string password, string returnUrl)
+ {
+ var result = await signInManager.PasswordSignInAsync(userName, password, false, false);
+ if (!result.Succeeded)
+ {
+ if (!string.IsNullOrEmpty(returnUrl))
+ {
+ return Redirect($"/account/login?status=failed&returnUrl={Uri.EscapeDataString(returnUrl)}");
+ }
+ else
+ {
+ return Redirect($"/account/login?status=failed");
+ }
+ }
+
+ if (string.IsNullOrEmpty(returnUrl))
+ {
+ Redirect("/");
+ }
+
+ return Redirect(returnUrl);
+ }
+
public async Task Logout()
{
await signInManager.SignOutAsync();