diff --git a/csharp.csproj b/Jerguero.csproj similarity index 100% rename from csharp.csproj rename to Jerguero.csproj diff --git a/csharp.sln b/Jerguero.sln similarity index 88% rename from csharp.sln rename to Jerguero.sln index 95489b1..7d84f74 100644 --- a/csharp.sln +++ b/Jerguero.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.5.002.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "csharp", "csharp.csproj", "{912903B0-B6A9-4584-AE22-28FA74D26277}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jerguero", "Jerguero.csproj", "{912903B0-B6A9-4584-AE22-28FA74D26277}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Model/Person.cs b/Model/Person.cs new file mode 100644 index 0000000..8d17efa --- /dev/null +++ b/Model/Person.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace Jerguero.Model; + +public class Person +{ + public int Id { get; set; } + + [Required] + public required string Email { get; set; } + + [Required] + public required string Password { get; set; } +} diff --git a/Pages/Components/_Badge.cshtml b/Pages/Components/_Badge.cshtml index 923cc26..fa30c92 100644 --- a/Pages/Components/_Badge.cshtml +++ b/Pages/Components/_Badge.cshtml @@ -2,6 +2,6 @@ var text = ViewData["text"]; } - diff --git a/Pages/Index.cshtml b/Pages/Index.cshtml index 45c4889..5f5e9f2 100644 --- a/Pages/Index.cshtml +++ b/Pages/Index.cshtml @@ -11,7 +11,7 @@ Jerguero
- + Agregá una nueva definición
diff --git a/Pages/Login.cshtml b/Pages/Login.cshtml index ba5ac7d..26e141e 100644 --- a/Pages/Login.cshtml +++ b/Pages/Login.cshtml @@ -1,5 +1,56 @@ @page +@model Jerguero.Pages.LoginModel -

- :D (login) -

\ No newline at end of file +

+ Jerguero +

+
+
+

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

+
+
+ + +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ +
+
+
+ +
+
+ + +@section Scripts { + +} \ No newline at end of file diff --git a/Pages/Login.cshtml.cs b/Pages/Login.cshtml.cs new file mode 100644 index 0000000..5d5adad --- /dev/null +++ b/Pages/Login.cshtml.cs @@ -0,0 +1,79 @@ +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 new file mode 100644 index 0000000..972d3dd --- /dev/null +++ b/Pages/New.cshtml @@ -0,0 +1,6 @@ +@page +@model Jerguero.Pages.NewDefinitionModel +@{ +} + +

New definition :D

diff --git a/Pages/NewDefinition.cshtml.cs b/Pages/New.cshtml.cs similarity index 72% rename from Pages/NewDefinition.cshtml.cs rename to Pages/New.cshtml.cs index 7b274be..6ca51af 100644 --- a/Pages/NewDefinition.cshtml.cs +++ b/Pages/New.cshtml.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace JergueroCS.Pages +namespace Jerguero.Pages { public class NewDefinitionModel : PageModel { @@ -9,10 +9,9 @@ namespace JergueroCS.Pages { if (User.Identity?.IsAuthenticated != true) { - return RedirectToPage("/Login"); + return RedirectToPage($"/Login", new {redirect = "/New"}); } - System.Console.WriteLine(":D"); return Page(); } } diff --git a/Pages/NewDefinition.cshtml b/Pages/NewDefinition.cshtml deleted file mode 100644 index 8847b67..0000000 --- a/Pages/NewDefinition.cshtml +++ /dev/null @@ -1,51 +0,0 @@ -@page -@model JergueroCS.Pages.NewDefinitionModel -@{ -} - -

- Jerguero -

-
-
-

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

-
- - -
- -
- -
- -
- -
- -
- -
- -
- -
-
-
- -
-
diff --git a/Pages/Shared/_Layout.cshtml b/Pages/Shared/_Layout.cshtml index d93ec19..d754286 100644 --- a/Pages/Shared/_Layout.cshtml +++ b/Pages/Shared/_Layout.cshtml @@ -6,8 +6,6 @@ @ViewData["Title"] - Jerguero - - diff --git a/wwwroot/css/site.css b/wwwroot/css/site.css deleted file mode 100644 index f8d98fc..0000000 --- a/wwwroot/css/site.css +++ /dev/null @@ -1,22 +0,0 @@ -html { - font-size: 14px; -} - -@media (min-width: 768px) { - html { - font-size: 16px; - } -} - -.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus { - box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb; -} - -html { - position: relative; - min-height: 100%; -} - -body { - margin-bottom: 60px; -} \ No newline at end of file diff --git a/wwwroot/css/tailwind-input.css b/wwwroot/css/tailwind-input.css index 1078454..576a79d 100644 --- a/wwwroot/css/tailwind-input.css +++ b/wwwroot/css/tailwind-input.css @@ -5,8 +5,6 @@ :root { --c-primary: #0ea5e9; --c-on-primary: white; - - } :root {