Exemplo n.º 1
0
        /// <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();
            }
        }
Exemplo n.º 2
0
        protected override async Task OnSaved(SaveEventArgs e)
        {
            await base.OnSaved(e);

            if (e.Mode == SaveMode.Insert)
            {
                await PasswordResetService.RequestTicket(this);
            }
        }
        /// <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();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new Password Reset Ticket for the specified user.
        /// </summary>
        public static async Task RequestTicket(User user)
        {
            var service = new PasswordResetService(user);

            using (var scope = Database.CreateTransactionScope())
            {
                await 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();
            }
        }