/// <summary> /// Completes the password recovery process. /// </summary> public static async Task Complete(PasswordResetTicket ticket, string newPassword) { if (newPassword.IsEmpty()) { throw new ArgumentNullException(nameof(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()) { await service.UpdatePassword(newPassword); await Database.Update(ticket, t => t.IsUsed = true); scope.Complete(); } }
Task CreateTicket() => Database.Save(Ticket = new PasswordResetTicket { User = User });