Make all components

master
Araozu 2024-08-24 12:02:15 -05:00
parent e7e0ec6117
commit 87999ef7b7
11 changed files with 129 additions and 237 deletions

View File

@ -1,26 +0,0 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>

View File

@ -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<ErrorModel> _logger;
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}

View File

@ -1,5 +1,7 @@
@page @page
@model IndexModel @model IndexModel
@using Microsoft.AspNetCore.Mvc;
@using Microsoft.AspNetCore.Mvc.RazorPages;
@{ @{
ViewData["Title"] = "Home page"; ViewData["Title"] = "Home page";
} }
@ -21,3 +23,21 @@
@Html.Partial("./_Post.cshtml") @Html.Partial("./_Post.cshtml")
<div class="w-full h-16"></div> <div class="w-full h-16"></div>
</div> </div>
@functions {
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public void OnGet()
{
}
}
}

View File

@ -1,19 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace csharp.Pages;
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public void OnGet()
{
}
}

View File

@ -1,5 +1,11 @@
@page @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
<h1 class="text-3xl font-bold text-center my-4 fixed top-0 w-screen"> <h1 class="text-3xl font-bold text-center my-4 fixed top-0 w-screen">
Jerguero Jerguero
@ -9,30 +15,26 @@
<p class="my-4 p-2 rounded bg-c-bg-2 text-c-on-bg shadow shadow-zinc-500"> <p class="my-4 p-2 rounded bg-c-bg-2 text-c-on-bg shadow shadow-zinc-500">
¡Iniciá sesión para comenzar a crear definiciones! ¡Iniciá sesión para comenzar a crear definiciones!
</p> </p>
<form <form class="my-4 py-4 px-2 rounded bg-c-bg-2 text-c-on-bg shadow shadow-zinc-500" method="post">
class="my-4 py-4 px-2 rounded bg-c-bg-2 text-c-on-bg shadow shadow-zinc-500"
method="post"
>
<div asp-validation-summary="ModelOnly" class="text-red-400"></div> <div asp-validation-summary="ModelOnly" class="text-red-400"></div>
<input type="hidden" value="@Model.RedirectUrl"> <input type="hidden" value="@Model.RedirectUrl">
<div class="py-2"> <div class="py-2">
<label class="text-sm opacity-85" asp-for="LoginPerson.Email">Correo electronico:</label> <label class="text-sm opacity-85" asp-for="LoginPerson.Email">Correo electronico:</label>
<br /> <br />
<input asp-for="LoginPerson.Email" <input asp-for="LoginPerson.Email" class="inline-block w-full rounded bg-c-bg text-c-on-bg py-2 px-1
class="inline-block w-full rounded bg-c-bg text-c-on-bg py-2 px-1 disabled:cursor-not-allowed disabled:opacity-50 transition-opacity" type="email"
disabled:cursor-not-allowed disabled:opacity-50 transition-opacity" required />
type="email" required />
<span asp-validation-for="LoginPerson.Email" class="text-red-400"></span> <span asp-validation-for="LoginPerson.Email" class="text-red-400"></span>
</div> </div>
<div class="py-2"> <div class="py-2">
<label asp-for="LoginPerson.Password" class="text-sm opacity-85" for="login-password">Contraseña:</label> <label asp-for="LoginPerson.Password" class="text-sm opacity-85"
for="login-password">Contraseña:</label>
<br /> <br />
<input asp-for="LoginPerson.Password" <input asp-for="LoginPerson.Password" class="inline-block w-full rounded bg-c-bg text-c-on-bg py-2 px-1
class="inline-block w-full rounded bg-c-bg text-c-on-bg py-2 px-1 disabled:cursor-not-allowed disabled:opacity-50 transition-opacity" type="password"
disabled:cursor-not-allowed disabled:opacity-50 transition-opacity" pattern=".{8,}" required />
type="password" pattern=".{8,}" required />
<span asp-validation-for="LoginPerson.Password" class="text-red-400"></span> <span asp-validation-for="LoginPerson.Password" class="text-red-400"></span>
</div> </div>
@ -53,4 +55,76 @@
@section Scripts { @section Scripts {
<partial name="_ValidationScriptsPartial" /> <partial name="_ValidationScriptsPartial" />
} }
@functions {
public class LoginModel(ILogger<LoginModel> logger) : PageModel
{
private readonly ILogger<LoginModel> _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<IActionResult> 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<Claim>
{
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<bool> 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;
}
}
}
}

View File

@ -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<LoginModel> logger) : PageModel
{
private readonly ILogger<LoginModel> _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<IActionResult> 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<Claim>
{
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<bool> 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;
}
}
}

View File

@ -1,6 +1,23 @@
@page @page
@model Jerguero.Pages.NewDefinitionModel @model NewDefinitionModel
@using Microsoft.AspNetCore.Mvc;
@using Microsoft.AspNetCore.Mvc.RazorPages;
@{ @{
} }
<p>New definition :D</p> <p>New definition :D</p>
@functions {
public class NewDefinitionModel : PageModel
{
public IActionResult OnGet()
{
if (User.Identity?.IsAuthenticated != true)
{
return RedirectToPage($"/Login", new { redirect = "/New" });
}
return Page();
}
}
}

View File

@ -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();
}
}
}

View File

@ -7,7 +7,6 @@
<title>@ViewData["Title"] - Jerguero</title> <title>@ViewData["Title"] - Jerguero</title>
<link rel="stylesheet" href="~/css/tailwind-output.css" asp-append-version="true" /> <link rel="stylesheet" href="~/css/tailwind-output.css" asp-append-version="true" />
<link rel="preconnect" href="https://fonts.googleapis.com" /> <link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Radio+Canada+Big:ital,wght@0,400..700;1,400..700&display=swap" <link href="https://fonts.googleapis.com/css2?family=Radio+Canada+Big:ital,wght@0,400..700;1,400..700&display=swap"
@ -21,8 +20,6 @@
<body> <body>
@RenderBody() @RenderBody()
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false) @await RenderSectionAsync("Scripts", required: false)
</body> </body>

View File

@ -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;
}

View File

@ -1,2 +1,3 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script> <script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script> <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>