diff --git a/Pages/Error.cshtml b/Pages/Error.cshtml deleted file mode 100644 index 6f92b95..0000000 --- a/Pages/Error.cshtml +++ /dev/null @@ -1,26 +0,0 @@ -@page -@model ErrorModel -@{ - ViewData["Title"] = "Error"; -} - -

Error.

-

An error occurred while processing your request.

- -@if (Model.ShowRequestId) -{ -

- Request ID: @Model.RequestId -

-} - -

Development Mode

-

- Swapping to the Development environment displays detailed information about the error that occurred. -

-

- The Development environment shouldn't be enabled for deployed applications. - It can result in displaying sensitive information from exceptions to end users. - For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development - and restarting the app. -

diff --git a/Pages/Error.cshtml.cs b/Pages/Error.cshtml.cs deleted file mode 100644 index 4f87bf2..0000000 --- a/Pages/Error.cshtml.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Diagnostics; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; - -namespace csharp.Pages; - -[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] -[IgnoreAntiforgeryToken] -public class ErrorModel : PageModel -{ - public string? RequestId { get; set; } - - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - - private readonly ILogger _logger; - - public ErrorModel(ILogger logger) - { - _logger = logger; - } - - public void OnGet() - { - RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; - } -} - diff --git a/Pages/Index.cshtml b/Pages/Index.cshtml index 5f5e9f2..0408cd1 100644 --- a/Pages/Index.cshtml +++ b/Pages/Index.cshtml @@ -1,5 +1,7 @@ @page @model IndexModel +@using Microsoft.AspNetCore.Mvc; +@using Microsoft.AspNetCore.Mvc.RazorPages; @{ ViewData["Title"] = "Home page"; } @@ -21,3 +23,21 @@ @Html.Partial("./_Post.cshtml")
+ + +@functions { + public class IndexModel : PageModel + { + private readonly ILogger _logger; + + public IndexModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + + } + } +} \ No newline at end of file diff --git a/Pages/Index.cshtml.cs b/Pages/Index.cshtml.cs deleted file mode 100644 index 55723a1..0000000 --- a/Pages/Index.cshtml.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; - -namespace csharp.Pages; - -public class IndexModel : PageModel -{ - private readonly ILogger _logger; - - public IndexModel(ILogger logger) - { - _logger = logger; - } - - public void OnGet() - { - - } -} diff --git a/Pages/Login.cshtml b/Pages/Login.cshtml index 26e141e..28d0f01 100644 --- a/Pages/Login.cshtml +++ b/Pages/Login.cshtml @@ -1,5 +1,11 @@ @page -@model Jerguero.Pages.LoginModel +@using System.Security.Claims; +@using Jerguero.Model; +@using Microsoft.AspNetCore.Authentication; +@using Microsoft.AspNetCore.Authentication.Cookies; +@using Microsoft.AspNetCore.Mvc; +@using Microsoft.AspNetCore.Mvc.RazorPages; +@model LoginModel

Jerguero @@ -9,30 +15,26 @@

¡Iniciá sesión para comenzar a crear definiciones!

-
+

- +
- +
- +
@@ -53,4 +55,76 @@ @section Scripts { -} \ No newline at end of file +} + +@functions { + public class LoginModel(ILogger logger) : PageModel + { + private readonly ILogger _logger = logger; + + [BindProperty] + public Person LoginPerson { get; set; } = default!; + + public string RedirectUrl = "/"; + + public IActionResult OnGet(string? redirect) + { + RedirectUrl = redirect ?? "/"; + if (User.Identity?.IsAuthenticated == true) + { + return LocalRedirect(redirect ?? "/"); + } + + return Page(); + } + + public async Task OnPostAsync(string? redirect) + { + _logger.LogInformation($"Got `{redirect}` as redirect param"); + if (!ModelState.IsValid || LoginPerson == null) + { + return Page(); + } + + // login + var loginCorrect = await AuthenticateUser(LoginPerson.Email, LoginPerson.Password); + if (!loginCorrect) + { + ModelState.AddModelError(string.Empty, "Credenciales inválidos"); + return Page(); + } + + var claims = new List + { + new(ClaimTypes.Name, LoginPerson.Email), + new(ClaimTypes.Role, "User"), + }; + + var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); + + await HttpContext.SignInAsync( + CookieAuthenticationDefaults.AuthenticationScheme, + new ClaimsPrincipal(claimsIdentity), + new AuthenticationProperties { } + ); + + return LocalRedirect(redirect ?? "/"); + } + + private async Task AuthenticateUser(string email, string password) + { + _logger.LogInformation("Authenticating: {}", new { Email = email, Password = password }); + + await Task.Delay(1000); + + if (email == "a@b.c") + { + return true; + } + else + { + return false; + } + } + } +} diff --git a/Pages/Login.cshtml.cs b/Pages/Login.cshtml.cs deleted file mode 100644 index 5d5adad..0000000 --- a/Pages/Login.cshtml.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System.Security.Claims; -using Jerguero.Model; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.Cookies; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; - -namespace Jerguero.Pages; - -public class LoginModel(ILogger logger) : PageModel -{ - private readonly ILogger _logger = logger; - - [BindProperty] - public Person LoginPerson { get; set; } = default!; - - public string RedirectUrl = "/"; - - public IActionResult OnGet(string? redirect) - { - RedirectUrl = redirect ?? "/"; - if (User.Identity?.IsAuthenticated == true) - { - return LocalRedirect(redirect ?? "/"); - } - - return Page(); - } - - public async Task OnPostAsync(string? redirect) - { - _logger.LogInformation($"Got `{redirect}` as redirect param"); - if (!ModelState.IsValid || LoginPerson == null) - { - return Page(); - } - - // login - var loginCorrect = await AuthenticateUser(LoginPerson.Email, LoginPerson.Password); - if (!loginCorrect) - { - ModelState.AddModelError(string.Empty, "Credenciales inválidos"); - return Page(); - } - - var claims = new List - { - new(ClaimTypes.Name, LoginPerson.Email), - new(ClaimTypes.Role, "User"), - }; - - var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); - - await HttpContext.SignInAsync( - CookieAuthenticationDefaults.AuthenticationScheme, - new ClaimsPrincipal(claimsIdentity), - new AuthenticationProperties { } - ); - - return LocalRedirect(redirect ?? "/"); - } - - private async Task AuthenticateUser(string email, string password) - { - _logger.LogInformation("Authenticating: {}", new { Email = email, Password = password }); - - await Task.Delay(1000); - - if (email == "a@b.c") - { - return true; - } - else - { - return false; - } - } -} - diff --git a/Pages/New.cshtml b/Pages/New.cshtml index 972d3dd..35162a1 100644 --- a/Pages/New.cshtml +++ b/Pages/New.cshtml @@ -1,6 +1,23 @@ @page -@model Jerguero.Pages.NewDefinitionModel +@model NewDefinitionModel +@using Microsoft.AspNetCore.Mvc; +@using Microsoft.AspNetCore.Mvc.RazorPages; @{ }

New definition :D

+ +@functions { + public class NewDefinitionModel : PageModel + { + public IActionResult OnGet() + { + if (User.Identity?.IsAuthenticated != true) + { + return RedirectToPage($"/Login", new { redirect = "/New" }); + } + + return Page(); + } + } +} diff --git a/Pages/New.cshtml.cs b/Pages/New.cshtml.cs deleted file mode 100644 index 6ca51af..0000000 --- a/Pages/New.cshtml.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.RazorPages; - -namespace Jerguero.Pages -{ - public class NewDefinitionModel : PageModel - { - public IActionResult OnGet() - { - if (User.Identity?.IsAuthenticated != true) - { - return RedirectToPage($"/Login", new {redirect = "/New"}); - } - - return Page(); - } - } -} diff --git a/Pages/Shared/_Layout.cshtml b/Pages/Shared/_Layout.cshtml index d754286..ea6630f 100644 --- a/Pages/Shared/_Layout.cshtml +++ b/Pages/Shared/_Layout.cshtml @@ -7,7 +7,6 @@ @ViewData["Title"] - Jerguero - @RenderBody() - - @await RenderSectionAsync("Scripts", required: false) diff --git a/Pages/Shared/_Layout.cshtml.css b/Pages/Shared/_Layout.cshtml.css deleted file mode 100644 index c187c02..0000000 --- a/Pages/Shared/_Layout.cshtml.css +++ /dev/null @@ -1,48 +0,0 @@ -/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification -for details on configuring this project to bundle and minify static web assets. */ - -a.navbar-brand { - white-space: normal; - text-align: center; - word-break: break-all; -} - -a { - color: #0077cc; -} - -.btn-primary { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; -} - -.nav-pills .nav-link.active, .nav-pills .show > .nav-link { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; -} - -.border-top { - border-top: 1px solid #e5e5e5; -} -.border-bottom { - border-bottom: 1px solid #e5e5e5; -} - -.box-shadow { - box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); -} - -button.accept-policy { - font-size: 1rem; - line-height: inherit; -} - -.footer { - position: absolute; - bottom: 0; - width: 100%; - white-space: nowrap; - line-height: 60px; -} diff --git a/Pages/Shared/_ValidationScriptsPartial.cshtml b/Pages/Shared/_ValidationScriptsPartial.cshtml index 5a16d80..e860905 100644 --- a/Pages/Shared/_ValidationScriptsPartial.cshtml +++ b/Pages/Shared/_ValidationScriptsPartial.cshtml @@ -1,2 +1,3 @@ - + +