Exemple #1
0
        public ActionResult SendRecovery(string email)
        {
            IPBanner.AttemptedToSendRecoveryEmail(Current.RemoteIP);

            var user = Models.User.FindUserByEmail(email);

            if (user == null)
            {
                return(RecoverableError("No account with that email was found", new { email }));
            }

            var now      = Current.Now;
            var token    = Current.UniqueId().ToString();
            var toInsert =
                new PasswordReset
            {
                CreationDate = now,
                TokenHash    = Current.WeakHash(token),
                UserId       = user.Id
            };

            Current.WriteDB.PasswordResets.InsertOnSubmit(toInsert);
            Current.WriteDB.SubmitChanges();

            var toReset =
                SafeRedirect(
                    (Func <string, string, string, ActionResult>)NewPassword,
                    new { token }
                    );

            var resetLink = Current.Url(toReset.Url);

            if (!Current.Email.SendEmail(email, Email.Template.ResetPassword, new { RecoveryLink = resetLink.AsLink() }))
            {
                return(IrrecoverableError("An error occurred sending the email", "This has been recorded, and will be looked into shortly"));
            }

            return(SuccessEmail("Password Recovery Email Sent to " + email, "Check your email for the link to reset your password."));
        }