From 02add8907ef734c0c57f3ffbc59ab53ce1b053ca Mon Sep 17 00:00:00 2001 From: fede Date: Thu, 8 May 2025 01:00:34 -0300 Subject: [PATCH] Esta todo a medio hacerse pero quiero versionar esto ya para no perder nada --- Aspnet/Controllers/UsuarioController.cs | 10 + Aspnet/Emailer/Builder/EmailBuilder.cs | 28 +++ Aspnet/Emailer/Builder/EmailHtmlGenerator.cs | 58 +++++ Aspnet/Emailer/Decorator/IEmailerSender.cs | 9 + .../Decorator/OtpEmailSenderDecorator.cs | 25 +++ Aspnet/settings.json | 6 +- Entidades/EstadoPropiedad.cs | 13 ++ Entidades/LogDetalle.cs | 23 ++ Entidades/TipoPropiedad.cs | 13 ++ Front/src/Componentes/LoginPanel.svelte | 209 +++++++++++++----- Modelo/RepositorioUsuarios.cs | 12 + 11 files changed, 348 insertions(+), 58 deletions(-) create mode 100644 Aspnet/Emailer/Builder/EmailBuilder.cs create mode 100644 Aspnet/Emailer/Builder/EmailHtmlGenerator.cs create mode 100644 Aspnet/Emailer/Decorator/IEmailerSender.cs create mode 100644 Aspnet/Emailer/Decorator/OtpEmailSenderDecorator.cs create mode 100644 Entidades/EstadoPropiedad.cs create mode 100644 Entidades/LogDetalle.cs create mode 100644 Entidades/TipoPropiedad.cs diff --git a/Aspnet/Controllers/UsuarioController.cs b/Aspnet/Controllers/UsuarioController.cs index 11c6637..38ba1bf 100644 --- a/Aspnet/Controllers/UsuarioController.cs +++ b/Aspnet/Controllers/UsuarioController.cs @@ -54,4 +54,14 @@ public class UsuarioController : ControllerBase return ret ? Ok(new { message = "Email de recuperación actualizado con éxito" }) : BadRequest(new { message = "No se pudo actualizar el email de recuperación" }); } + public record recuperarusuario(string Email, string EmailRecuperacion); + [HttpPost("/api/recuperarUsuario")] + public IActionResult RecuperarUsuario([FromBody] recuperarusuario mails) + { + bool check = RepositorioUsuarios.Singleton.CheckEmailRecuperacion(mails.Email, mails.EmailRecuperacion); + if (check == false) return BadRequest(new { message = "El email no corresponde al email de recuperacion" }); + + //WIP hacer emailer + + } } diff --git a/Aspnet/Emailer/Builder/EmailBuilder.cs b/Aspnet/Emailer/Builder/EmailBuilder.cs new file mode 100644 index 0000000..34777c6 --- /dev/null +++ b/Aspnet/Emailer/Builder/EmailBuilder.cs @@ -0,0 +1,28 @@ +using System.Net.Mail; +namespace AlquilaFacil.Emailer.Builder; + +public class EmailBuilder +{ + private MailMessage _message = new(); + + public EmailBuilder To(string to) + { + _message.To.Add(to); + return this; + } + + public EmailBuilder Subject(string subject) + { + _message.Subject = subject; + return this; + } + + public EmailBuilder Body(string email, string pin) + { + _message.IsBodyHtml = true; + _message.Body = new HtmlGenerator().GenerarMail2fa(email, pin); + return this; + } + + public MailMessage Build() => _message; +} diff --git a/Aspnet/Emailer/Builder/EmailHtmlGenerator.cs b/Aspnet/Emailer/Builder/EmailHtmlGenerator.cs new file mode 100644 index 0000000..bb27711 --- /dev/null +++ b/Aspnet/Emailer/Builder/EmailHtmlGenerator.cs @@ -0,0 +1,58 @@ +namespace AlquilaFacil.Emailer.Builder; + +public class HtmlGenerator +{ + public string GenerarMail2fa(string emailUsuario, string pin) + { + var msg = $""" + + + +
+ + + + + + +
+
+ Aqui esta su codigo OTP: +
+

+ {pin} +

+
+ Este codigo es del usuario con email:{emailUsuario} +
+
+ Si no sabes para que es el email, ignoralo. +
+
+
+ + + + """; + + return msg; + } +} diff --git a/Aspnet/Emailer/Decorator/IEmailerSender.cs b/Aspnet/Emailer/Decorator/IEmailerSender.cs new file mode 100644 index 0000000..a5007a4 --- /dev/null +++ b/Aspnet/Emailer/Decorator/IEmailerSender.cs @@ -0,0 +1,9 @@ +using System.Net.Mail; + +namespace AlquilaFacil.Emailer.Sender; + +public interface IEmailSender +{ + public void Send(MailMessage message, SmtpClient smtp); + +} diff --git a/Aspnet/Emailer/Decorator/OtpEmailSenderDecorator.cs b/Aspnet/Emailer/Decorator/OtpEmailSenderDecorator.cs new file mode 100644 index 0000000..e6615f5 --- /dev/null +++ b/Aspnet/Emailer/Decorator/OtpEmailSenderDecorator.cs @@ -0,0 +1,25 @@ +namespace AlquilaFacil.Emailer.Sender; +using System.Net.Mail; +public class OtpEmailSender : IEmailSender +{ + private readonly int _codigoLength; + + public OtpEmailSenderDecorator(int codigoLength = 6) + { + _codigoLength = codigoLength; + } + + public void Send(MailMessage message, SmtpClient? smtp = null) + { + if (smtp == null) + { + smtp = new(); + //WIP + smtp.DeliveryMethod = SmtpDeliveryMethod.Network; + + } + + + // 4.2 Construir HTML de verificación + + } diff --git a/Aspnet/settings.json b/Aspnet/settings.json index f44d236..b3fc1c9 100644 --- a/Aspnet/settings.json +++ b/Aspnet/settings.json @@ -1,5 +1,9 @@ { "usr": "nwFNMLJcn5m0owbzeXMs", "scrt": "Mf9HxTir5mIGwWSBtQXd6DRK2k00V0EyXk7QTu70", - "connectiondb": "Server=127.0.0.1;Port=3306;Database=AlquilaFacil;Uid=AlquilaFacil;Pwd=.n@9c2ve*0,b1ETv].Kipa/~pR~V;Connection Timeout=5;SslMode=none" + "connectiondb": "Server=127.0.0.1;Port=3306;Database=AlquilaFacil;Uid=AlquilaFacil;Pwd=.n@9c2ve*0,b1ETv].Kipa/~pR~V;Connection Timeout=5;SslMode=none", + "smtpHost": "smtp.gmail.com", + "smtpPort": "587", + "emailAddr": "emailerpasillo@gmail.com", + "emailPass": "hgwa mznx xuff exws" } diff --git a/Entidades/EstadoPropiedad.cs b/Entidades/EstadoPropiedad.cs new file mode 100644 index 0000000..ed87dfa --- /dev/null +++ b/Entidades/EstadoPropiedad.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace Entidades; + +public partial class EstadoPropiedad +{ + public int Id { get; set; } + + public string Descripcion { get; set; } = null!; + + public virtual ICollection Propiedades { get; set; } = new List(); +} diff --git a/Entidades/LogDetalle.cs b/Entidades/LogDetalle.cs new file mode 100644 index 0000000..9b3b469 --- /dev/null +++ b/Entidades/LogDetalle.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; + +namespace Entidades; + +public partial class LogDetalle +{ + public DateTime Fecha { get; set; } + + public long Dniusuario { get; set; } + + public string NombreTabla { get; set; } = null!; + + public string Columna { get; set; } = null!; + + public string? ValorAnterior { get; set; } + + public string? ValorNuevo { get; set; } + + public int Id { get; set; } + + public virtual Log Log { get; set; } = null!; +} diff --git a/Entidades/TipoPropiedad.cs b/Entidades/TipoPropiedad.cs new file mode 100644 index 0000000..c842eec --- /dev/null +++ b/Entidades/TipoPropiedad.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace Entidades; + +public partial class TipoPropiedad +{ + public int Id { get; set; } + + public string Descripcion { get; set; } = null!; + + public virtual ICollection Propiedades { get; set; } = new List(); +} diff --git a/Front/src/Componentes/LoginPanel.svelte b/Front/src/Componentes/LoginPanel.svelte index 9de9755..b9a8769 100644 --- a/Front/src/Componentes/LoginPanel.svelte +++ b/Front/src/Componentes/LoginPanel.svelte @@ -1,66 +1,161 @@ - - - Iniciar Sesión - - -
- - - - - - - - - -
-{#if errorMessage} -