Esempio n. 1
0
        public ChangeInput Change()
        {
            UserWrapper user = this.repo.FindUserByName(this.context.CurrentUserName);

             var input = new ChangeInput {
            NewEmail = user.Email
             };

             return input;
        }
Esempio n. 2
0
        OperationResult ChangeImpl(ChangeInput input)
        {
            if (input == null) throw new ArgumentNullException("input");

             var errors = new ErrorBuilder();

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

             UserWrapper user = this.repo.FindUserByName(this.CurrentUserName);

             string currentEmail = user.Email;
             string newEmail = input.NewEmail;

             if (errors.Not(currentEmail.HasValue(), AccountResources.Validation_MissingEmail))
            return errors;

             if (errors.Not(this.passServ.PasswordEquals(input.CurrentPassword, user.Password), AccountResources.Validation_CurrentPasswordIncorrect, () => input.CurrentPassword)
            | errors.Not(!EmailEquals(currentEmail, newEmail), AccountResources.Validation_NewEmailSameAsCurrent, () => input.NewEmail))
            return errors;

             if (errors.Not(this.repo.FindUserByEmail(newEmail) == null, AccountResources.Validation_EmailAlreadyExists, () => input.NewEmail))
            return errors;

             if (!this.Configuration.EnableEmailVerification) {

            user.Email = newEmail;

            this.repo.UpdateUser(user);

            return HttpStatusCode.OK;
             }

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

             this.repo.UpdateUser(user);

             var notifyModel = new NotificationMessageViewModel {
            SiteName = GetSiteName(),
            NewEmail = newEmail,
            OldEmail = currentEmail,
            HelpResource = this.Configuration.HelpResource
             };

             if (!EmailEquals(currentEmail, user.Username))
            notifyModel.Username = user.Username;

             var notifyMessage = new MailMessage {
            To = { user.Email },
            Subject = AccountResources.Model_EmailChangeNotificationMessageSubject,
            Body = RenderEmailView(Views.Email.Change._NotificationMessage, notifyModel)
             };

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

             var verifyModel = new VerificationMessageViewModel {
            SiteName = notifyModel.SiteName,
            Url = verificationUrl
             };

             var verifyMessage = new MailMessage {
            To = { newEmail },
            Subject = AccountResources.Model_EmailChangeVerificationMessageSubject,
            Body = RenderEmailView(Views.Email.Change._VerificationMessage, verifyModel)
             };

             SendEmail(notifyMessage);
             SendEmail(verifyMessage);

             return new OperationResult(HttpStatusCode.Accepted, new ChangeResult(newEmail));
        }
Esempio n. 3
0
        public ActionResult Change(ChangeInput input, FormButton cancel)
        {
            if (cancel)
            return HttpSeeOther(this.Url.Action("", "~Account"));

             this.ViewData.Model = new ChangeViewModel(input);

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

             var result = ChangeImpl(input);

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

             if (result.StatusCode == HttpStatusCode.Accepted) {

            this.TempData["PostChange"] = result;

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

             return HttpSeeOther(this.Url.Action(Saved));
        }