feat: implement core domain models, authentication service, and UI components for the attendance system
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Asistencia.Models;
|
||||
|
||||
namespace Asistencia.Data.Repositories;
|
||||
|
||||
public class ProfesorRepository
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public ProfesorRepository(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Profesor?> BuscarPorRutAsync(string rut)
|
||||
{
|
||||
return await _context.Profesores.FirstOrDefaultAsync(p => p.RutPasaporte == rut);
|
||||
}
|
||||
|
||||
public async Task<bool> ActualizarClaveAsync(string rut, string nuevaClave)
|
||||
{
|
||||
var profesor = await _context.Profesores.FirstOrDefaultAsync(p => p.RutPasaporte == rut);
|
||||
if (profesor == null) return false;
|
||||
|
||||
profesor.Clave = nuevaClave;
|
||||
profesor.CrearClave = false;
|
||||
await _context.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> ActualizarEmailAsync(string rut, string email)
|
||||
{
|
||||
var profesor = await _context.Profesores.FirstOrDefaultAsync(p => p.RutPasaporte == rut);
|
||||
if (profesor == null) return false;
|
||||
|
||||
profesor.Email = email;
|
||||
await _context.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<Profesor?> AutenticarAsync(string rut, string clave)
|
||||
{
|
||||
var profesor = await _context.Profesores.FirstOrDefaultAsync(p => p.RutPasaporte == rut);
|
||||
if (profesor == null) return null;
|
||||
|
||||
if (profesor.CrearClave) return null;
|
||||
|
||||
var claveDescifrada = Helpers.CryptoHelper.Desencriptar(profesor.Clave);
|
||||
return claveDescifrada == clave ? profesor : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user