/// <summary> /// Creates a new Password Reset Ticket for the specified user. /// </summary> public static void RequestTicket(User user) { var service = new PasswordResetService(user); using (var scope = Database.CreateTransactionScope()) { service.CreateTicket(); service.SendEmail(); scope.Complete(); } }
/// <summary> /// Completes the password recovery process. /// </summary> public static void Complete(PasswordResetTicket ticket, string newPassword) { if (newPassword.IsEmpty()) throw new ArgumentNullException("newPassword"); if (ticket.IsExpired) throw new ValidationException("This ticket has expired. Please request a new ticket."); if (ticket.IsUsed) throw new ValidationException("This ticket has been used once. Please request a new ticket."); var service = new PasswordResetService(ticket.User); using (var scope = Database.CreateTransactionScope()) { service.UpdatePassword(newPassword); Database.Update(ticket, t => t.IsUsed = true); scope.Complete(); } }