diff --git a/WebApp/Pages/Login.cshtml b/WebApp/Pages/Login.cshtml index 597f8be..d914310 100644 --- a/WebApp/Pages/Login.cshtml +++ b/WebApp/Pages/Login.cshtml @@ -1,9 +1,57 @@ @page @model WebApp.Pages.LoginModel -
- +@{ + ViewData["Title"] = "Log In"; +} +
+ +
+
+
+
- - +
+ +

Log in

+ +
+ + +
+ +
+ + +
+ +
+ +
+ +

Don't have an account? Register here

+
+ +
+ +
+
+ Login image +
+
+
+
\ No newline at end of file diff --git a/WebApp/Pages/Login.cshtml.cs b/WebApp/Pages/Login.cshtml.cs index ce8c5b7..4a53a79 100644 --- a/WebApp/Pages/Login.cshtml.cs +++ b/WebApp/Pages/Login.cshtml.cs @@ -11,18 +11,18 @@ namespace WebApp.Pages { } - public void OnPostAsync(string email, string password) + public IActionResult OnPostAsync(string email, string password) { var response = APIClient.PostRequest("user/login", new { email, password }); if (response is null || response is not string) { - return; + throw new Exception("Something wrong LOL!"); } - string token = (string)JsonConvert.DeserializeObject((string)response); - // - Response.Cookies.Append("21gunsthebest", token); - Redirect("/"); + + this.SetJWT((string)response); + + return RedirectToPage("Index"); } } } \ No newline at end of file diff --git a/WebApp/Pages/PageModelExtension.cs b/WebApp/Pages/PageModelExtension.cs new file mode 100644 index 0000000..8d8969d --- /dev/null +++ b/WebApp/Pages/PageModelExtension.cs @@ -0,0 +1,30 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; + +namespace WebApp.Pages +{ + public static class PageModelExtension + { + public static string? GetUserId(this PageModel pageModel) + { + if (pageModel.User.Identity.IsAuthenticated) + { + var userIdClaim = pageModel.User.Claims.FirstOrDefault(c => c.Type == "userId"); + return userIdClaim?.Value; + } + return null; + } + + public static void SetJWT(this PageModel pageModel, string jwt) + { + string token = (string)JsonConvert.DeserializeObject(jwt); + // Сохраняем в кукис токен + pageModel.Response.Cookies.Append("21gunsthebest", token); + } + + public static void DeleteJWT(this PageModel pageModel) + { + pageModel.Response.Cookies.Delete("21gunsthebest"); + } + } +} \ No newline at end of file diff --git a/WebApp/Pages/Shared/_Layout.cshtml b/WebApp/Pages/Shared/_Layout.cshtml index b103339..e7560e9 100644 --- a/WebApp/Pages/Shared/_Layout.cshtml +++ b/WebApp/Pages/Shared/_Layout.cshtml @@ -3,7 +3,7 @@ - @ViewData["Title"] - WebApp + @ViewData["Title"] - 21 GUNS @@ -12,7 +12,7 @@