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

@@ -2,6 +2,7 @@ using AlquilaFacil.Builder;
using Microsoft.AspNetCore.Mvc;
using Modelo;
using Entidades;
using AlquilaFacil.Emailer.Sender;
namespace AlquilaFacil.Controllers;
@@ -51,7 +52,15 @@ public class UsuarioController : ControllerBase
if (!emailrecuperacion.Contains("@")) return BadRequest(new { message = "Tiene que ser un email" });
bool ret = RepositorioUsuarios.Singleton.SetEmailRecuperacion(emailrecuperacion, cli);
return ret ? Ok(new { message = "Email de recuperación actualizado con éxito" }) : BadRequest(new { message = "No se pudo actualizar el email de recuperación" });
if (ret == false) return BadRequest(new { message = "No se pudo actualizar el email de recuperación" });
Task.Run(() =>
{
AvisoEmailSender s = new();
s.Send(cli.Email, setemail.EmailRecuperacion);
});
return Ok(new { message = "Email de recuperación actualizado con éxito" });
}
public record recuperarusuario(string Email, string EmailRecuperacion);
@@ -61,7 +70,34 @@ public class UsuarioController : ControllerBase
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
string pin = "";
var ran = new Random();
for (int i = 0; i < 6; i++) pin += ran.Next(0, 10);
bool ret = RepositorioUsuarios.Singleton.SetF2aPin(pin, mails.Email);
if (ret == false) return BadRequest(new { message = "no se pudo generar/guardar el codigo 2fa" });
OtpEmailSender s = new();
s.Send(mails.EmailRecuperacion, mails.Email, pin);
return Ok(new { message = $"Se envio un email de recuperacion a {mails.EmailRecuperacion}" });
}
public record ingreso2fa(string Pin, string Email);
[HttpPost("/api/ingresar2fa")]
public IActionResult IngresarUsuario([FromBody] ingreso2fa data)
{
if (!data.Email.Contains("@")) return BadRequest(new { message = "Tiene que ser un email" });
if (data.Pin.Length != 6) return BadRequest(new { message = "el pin tiene que tener 6 digitos" });
(bool check, long Dni) = RepositorioUsuarios.Singleton.Check2fa(data.Email, data.Pin);
if (check == false) return BadRequest(new { message = "El pin es incorrecto" });
var cli = RepositorioUsuarios.Singleton.ObtenerClientePorDni(Dni);
//esto literalmente no se puede triggerear pero lo pongo para evitar una warning
if (cli == null) return BadRequest(new { message = "El usuario no existe" });
return Ok(new { token = cli.Token });
}
}