diff --git a/AggieRent/Services/ApplicantService.cs b/AggieRent/Services/ApplicantService.cs index 444d58c..c9e1e0d 100644 --- a/AggieRent/Services/ApplicantService.cs +++ b/AggieRent/Services/ApplicantService.cs @@ -9,7 +9,7 @@ public class ApplicantService(IApplicantRepository applicantRepository) : IAppli public Applicant? GetApplicantById(string id) { - return _applicantRepository.Get(id); + return _applicantRepository.GetVerbose(id); } public IEnumerable GetApplicants() @@ -85,14 +85,41 @@ public void UpdateApplicant( public void ResetApplicantEmail(string id, string newEmail) { - // TODO: Implement ResetApplicantEmail - throw new Exception("Method not implemented yet!"); + var applicant = + _applicantRepository.Get(id) + ?? throw new ArgumentException("Applicant ID not found"); + + if (!AuthUtils.ValidateEmail(newEmail)) + throw new ArgumentException("Invalid email format"); + + var normalizedEmail = AuthUtils.NormalizeEmail(newEmail); + + if (normalizedEmail.Equals(applicant.Email)) + return; + + var existingApplicant = _applicantRepository + .GetAll() + .FirstOrDefault(a => a.Email == normalizedEmail); + if (existingApplicant != null) + throw new ArgumentException("Email already in use"); + + applicant.Email = normalizedEmail; + _applicantRepository.Update(applicant); } public void ResetApplicantPassword(string id, string newPassword) { - // TODO: Implement ResetApplicantPassword - throw new Exception("Method not implemented yet!"); + var applicant = + _applicantRepository.Get(id) + ?? throw new ArgumentException("Applicant ID not found"); + + if (!AuthUtils.ValidatePassword(newPassword)) + throw new ArgumentException( + "Invalid password! Password must be at least 8 symbols long, with at least 1 lower case character, 1 upper case character, 1 symbol and 1 number" + ); + + applicant.HashedPassword = BC.HashPassword(newPassword); + _applicantRepository.Update(applicant); } public void DeleteApplicant(string id)