me traigo todos los cambios del recuperar cuenta y set email respaldo
This commit is contained in:
@@ -17,10 +17,20 @@ public class EmailBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmailBuilder Body(string email, string pin)
|
||||
public EmailBuilder Body(string email, string pin, string modo = "2fa")
|
||||
{
|
||||
_message.IsBodyHtml = true;
|
||||
_message.Body = new HtmlGenerator().GenerarMail2fa(email, pin);
|
||||
switch (modo)
|
||||
{
|
||||
case "2fa":
|
||||
_message.Body = new HtmlGenerator().GenerarMail2fa(email, pin);
|
||||
break;
|
||||
case "aviso":
|
||||
_message.Body = new HtmlGenerator().AvisoSetEmail(email, pin);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,4 +55,58 @@ public class HtmlGenerator
|
||||
|
||||
return msg;
|
||||
}
|
||||
public string AvisoSetEmail(string emailUsuario, string emailreq)
|
||||
{
|
||||
var msg = $"""
|
||||
<!doctype html>
|
||||
<html>
|
||||
<body>
|
||||
<div
|
||||
style='background-color:#000000;color:#FFFFFF;font-family:"Iowan Old Style", "Palatino Linotype", "URW Palladio L", P052, serif;font-size:16px;font-weight:400;letter-spacing:0.15008px;line-height:1.5;margin:0;padding:32px 0;min-height:100%;width:100%'
|
||||
>
|
||||
<table
|
||||
align="center"
|
||||
width="100%"
|
||||
style="margin:0 auto;max-width:600px;background-color:#000000"
|
||||
role="presentation"
|
||||
cellspacing="0"
|
||||
cellpadding="0"
|
||||
border="0"
|
||||
>
|
||||
<tbody>
|
||||
<tr style="width:100%">
|
||||
<td>
|
||||
<div
|
||||
style="color:#ffffff;font-size:16px;font-weight:normal;text-align:center;padding:16px 24px 16px 24px"
|
||||
>
|
||||
Aviso:
|
||||
</div>
|
||||
<h1
|
||||
style='font-weight:bold;text-align:center;margin:0;font-family:"Nimbus Mono PS", "Courier New", "Cutive Mono", monospace;font-size:32px;padding:16px 24px 16px 24px'
|
||||
>
|
||||
Se seteo este email : {emailreq}, como email de respaldo
|
||||
</h1>
|
||||
<div
|
||||
style="color:#868686;font-size:16px;font-weight:normal;text-align:center;padding:16px 24px 16px 24px"
|
||||
>
|
||||
|
||||
</div>
|
||||
<div
|
||||
style="color:#868686;font-size:14px;font-weight:normal;text-align:center;padding:16px 24px 16px 24px"
|
||||
>
|
||||
Si no sabes para que es el email, ignoralo.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
""";
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace AlquilaFacil.Emailer.Sender;
|
||||
|
||||
public interface IEmailSender
|
||||
{
|
||||
public void Send(MailMessage message, SmtpClient smtp);
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user