me traigo todos los cambios del recuperar cuenta y set email respaldo

This commit is contained in:
2025-05-20 00:36:12 -03:00
parent 02add8907e
commit e3fa663ffa
19 changed files with 370 additions and 97 deletions

View File

@@ -0,0 +1,11 @@
namespace AlquilaFacil.Emailer.Sender;
using AlquilaFacil.Emailer.Builder;
public class AvisoEmailSender : EmailSender
{
public void Send(string emailusu, string emailreq)
{
var mail = new EmailBuilder().Body(emailusu, emailreq, "aviso").To(emailreq).Subject("AvisoEmail").Build();
base.Send(mail);
}
}

View File

@@ -0,0 +1,50 @@
using System.Net.Mail;
using System.Net;
using System.Text.Json;
namespace AlquilaFacil.Emailer.Sender;
public class EmailSender
{
protected static SmtpClient? smtp = null;
protected void configSmtp(MailMessage mail)
{
var jsonContent = File.ReadAllText("settings.json");
var options = JsonSerializer.Deserialize<Dictionary<string, string>>(jsonContent);
if (options == null) return;
bool check = options.ContainsKey("smtpHost");
check = options.ContainsKey("smtpPort");
check = options.ContainsKey("emailAddr");
check = options.ContainsKey("emailPass");
if (check == false) return;
mail.Sender = new MailAddress(options["emailAddr"]);
mail.From = new MailAddress(options["emailAddr"]);
if (null != smtp) return;
smtp = new();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Host = options["smtpHost"];
smtp.Port = int.Parse(options["smtpPort"].ToString());
smtp.Credentials = new NetworkCredential(options["emailAddr"], options["emailPass"]);
}
public virtual void Send(MailMessage message)
{
configSmtp(message);
if (smtp == null) return;
try
{
smtp.Send(message);
message.Dispose();
}
catch (Exception)
{
throw;
}
}
}

View File

@@ -1,9 +0,0 @@
using System.Net.Mail;
namespace AlquilaFacil.Emailer.Sender;
public interface IEmailSender
{
public void Send(MailMessage message, SmtpClient smtp);
}

View File

@@ -0,0 +1,13 @@
namespace AlquilaFacil.Emailer.Sender;
using AlquilaFacil.Emailer.Builder;
public class OtpEmailSender : EmailSender
{
public void Send(string To, string email, string pin)
{
var mail = new EmailBuilder().To(To).Body(email, pin).Subject("Mail de Recuperacion").Build();
base.Send(mail);
}
}

View File

@@ -1,25 +0,0 @@
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
}