Ejemplo n.º 1
0
        public ActionResult Reset(ResetInput input)
        {
            this.ViewData.Model = new ResetViewModel(input);

             if (!this.ModelState.IsValid)
            return View().WithStatus(HttpStatusCode.BadRequest);

             var result = ResetImpl(input);

             if (result.IsError)
            return View().WithErrors(result);

             this.TempData["PostReset"] = result;

             return HttpSeeOther(this.Url.Action(VerificationSent));
        }
Ejemplo n.º 2
0
        OperationResult<ResetResult> ResetImpl(ResetInput input)
        {
            if (input == null) throw new ArgumentNullException("input");

             var errors = new ErrorBuilder();

             if (errors.NotValid(input))
            return errors;

             UserWrapper user = this.repo.FindUserByEmail(input.Email);

             MailMessage message;
             string destinationEmail;

             bool canResetPassword = user != null
            && !user.Disabled;

             if (canResetPassword) {

            user.PasswordResetTicketExpiration = this.Configuration.GetNow()
               .Add(this.Configuration.PasswordResetTicketExpiration);

            this.repo.UpdateUser(user);

            string verificationTicket = new VerificationData(user.Id, null).GetVerificationTicket();
            string verificationUrl = AbsoluteUrl(this.Url.Action(Finish, verificationTicket));

            var mailModel = new VerificationMessageViewModel {
               SiteName = GetSiteName(),
               Url = verificationUrl
            };

            if (!EmailEquals(user.Email, user.Username))
               mailModel.Username = user.Username;

            destinationEmail = user.Email;

            message = new MailMessage {
               To = { destinationEmail },
               Subject = AccountResources.Model_PasswordResetVerificationMessageSubject,
               Body = RenderEmailView(Views.Password.Reset._VerificationMessage, mailModel)
            };

             } else {

            destinationEmail = input.Email;

            var mailModel = new ErrorMessageViewModel {
               SiteName = GetSiteName(),
               ErrorReason = (user == null) ?
                  ErrorReason.AccountNotFound
                  : ErrorReason.AccountDisabled
            };

            message = new MailMessage {
               To = { destinationEmail },
               Subject = AccountResources.Model_PasswordResetVerificationMessageSubject,
               Body = RenderEmailView(Views.Password.Reset._ErrorMessage, mailModel)
            };
             }

             SendEmail(message);

             return new OperationResult<ResetResult>(HttpStatusCode.Accepted, new ResetResult(destinationEmail));
        }
Ejemplo n.º 3
0
        public ActionResult Reset(ResetInput input)
        {
            this.ViewData.Model = new ResetViewModel(input);

             if (!this.ModelState.IsValid) {
            return View().WithStatus(HttpStatusCode.BadRequest);
             }

             var result = this.resetter.Reset(input);

             if (result.IsError) {
            return View().WithErrors(result);
             }

             this.TempData["PostReset"] = result;

             return Redirect(this.Url.Action(VerificationSent));
        }