Пример #1
0
        public ActionResult ForgotPassword(PasswordResetInfo model)
        {
            var redirect = this.RedirectAuthenticatedUser();

            if (redirect != null)
            {
                return(redirect);
            }

            if (!this.accountRepository.Exists(model.Email))
            {
                this.ModelState.AddModelError(nameof(model.Email), Errors.UserDoesNotExist);

                return(this.View(model));
            }

            try
            {
                var newPassword = this.accountRepository.RestorePassword(model.Email);
                this.notificationService.SendPassword(model.Email, newPassword);
                return(this.View("InfoMessage", new InfoMessage(Captions.ResetPasswordSuccess)));
            }
            catch (Exception ex)
            {
                Log.Error($"Can't reset password for user {model.Email}", ex, this);
                this.ModelState.AddModelError(nameof(model.Email), ex.Message);

                return(this.View(model));
            }
        }
Пример #2
0
        public void ResetPassword(PasswordResetInfo reset)
        {
            reset.VerifyPassword();

            inTransaction("PasswordReset", () =>
            {
                var security = repos.Security.ValidateAndGet(
                    reset.Token,
                    SecurityAction.PasswordReset
                    );

                var user = security.User;

                if (user.Control.ProcessingDeletion)
                {
                    throw Error.UserDeleted.Throw();
                }

                if (user.Control.WipeRequest != null)
                {
                    throw Error.UserAskedWipe.Throw();
                }

                user.Password = reset.Password;

                repos.User.ChangePassword(user);

                repos.Security.Disable(reset.Token);
            });
        }
Пример #3
0
 /// <remarks/>
 public void NotifyPasswordResetAsync(PasswordResetInfo info, object userState)
 {
     if ((this.NotifyPasswordResetOperationCompleted == null))
     {
         this.NotifyPasswordResetOperationCompleted = new System.Threading.SendOrPostCallback(this.OnNotifyPasswordResetOperationCompleted);
     }
     this.InvokeAsync("NotifyPasswordReset", new object[] {
         info
     }, this.NotifyPasswordResetOperationCompleted, userState);
 }
Пример #4
0
        internal void NotifyPasswordChanged(Guid customerId, string loginName, string newPassword)
        {
            PasswordResetInfo info = new PasswordResetInfo
            {
                CustomerID = customerId,
                LoginName  = loginName,
                Password   = newPassword
            };

            lock (this._ToBeSendEntitiesLock)
            {
                this._ToBeSendEntities.Enqueue(info);
            }
            this._HasToBeSendEntityEvent.Set();
        }
Пример #5
0
        public void ForgotPassword_NotValidPassword_ShouldReturnModel(PasswordResetInfo model, [Frozen] IAccountRepository repo, [NoAutoProperties] AccountsController controller)
        {
            var fakeSite = new FakeSiteContext(new StringDictionary
            {
                { "displayMode", "normal" }
            }) as SiteContext;

            using (new SiteContextSwitcher(fakeSite))
            {
                repo.RestorePassword(Arg.Any <string>()).Returns("new password");
                repo.Exists(Arg.Any <string>()).Returns(true);
                controller.ModelState.AddModelError("Error", "Error");
                var result = controller.ForgotPassword(model);
                result.Should().BeOfType <ViewResult>().Which.Model.Should().Be(model);
            }
        }
Пример #6
0
        public void ForgotPassword_UserDoesNotExist_ShouldReturnModel(PasswordResetInfo model, [Frozen] IAccountRepository repo)
        {
            var fakeSite = new FakeSiteContext(new StringDictionary
            {
                { "displayMode", "normal" }
            }) as SiteContext;

            using (new SiteContextSwitcher(fakeSite))
            {
                repo.RestorePassword(Arg.Any <string>()).Returns("new password");
                repo.Exists(Arg.Any <string>()).Returns(false);
                var controller = new AccountsController(repo, null, null, null, null);
                var result     = controller.ForgotPassword(model);
                result.Should().BeOfType <ViewResult>().Which.Model.Should().Be(model);
                result.Should().BeOfType <ViewResult>().Which.ViewData.ModelState.Should().ContainKey(nameof(model.Email)).WhichValue.Errors.Should().Contain(x => x.ErrorMessage == "User with specified e-mail address does not exist");
            }
        }
Пример #7
0
        public void ForgotPassword_ShouldCatchAndReturnViewWithError(PasswordResetInfo model, [Frozen] IAccountRepository repo, INotificationService notificationService, IAccountsSettingsService settingService)
        {
            var fakeSite = new FakeSiteContext(new StringDictionary
            {
                { "displayMode", "normal" }
            }) as SiteContext;

            using (new SiteContextSwitcher(fakeSite))
            {
                repo.RestorePassword(Arg.Any <string>()).ThrowsForAnyArgs(new Exception("Error"));
                repo.Exists(Arg.Any <string>()).Returns(true);
                var controller = new AccountsController(repo, notificationService, settingService, null, null);
                var result     = controller.ForgotPassword(model);
                result.Should().BeOfType <ViewResult>().Which.Model.Should().Be(model);
                result.Should().BeOfType <ViewResult>().Which.ViewData.ModelState.Should().ContainKey(nameof(model.Email)).WhichValue.Errors.Should().Contain(x => x.ErrorMessage == "Error");
            }
        }
Пример #8
0
        public Result <PasswordResetInfo> GetPasswordResetInfo(string tokenString)
        {
            Guid   resetToken;
            string userEmail;

            // Parse token to string and retrieve user email from cache, return error msg if anything fails
            if (string.IsNullOrWhiteSpace(tokenString) ||
                !Guid.TryParse(tokenString, out resetToken) ||
                !cache.TryGet(CacheKeys.ForgotPasswordGuid(resetToken), out userEmail))
            {
                throw new ValidationException(MsgInvalidResetToken);
            }

            // Valid, return success
            PasswordResetInfo resultInfo = new PasswordResetInfo {
                Token = resetToken, Email = userEmail
            };

            return(new Result <PasswordResetInfo>(resultInfo));
        }
Пример #9
0
        public ActionResult ForgotPassword(PasswordResetInfo model)
        {
            if (!_accountRepository.Exists(model.Email))
            {
                ModelState.AddModelError(nameof(model.Email), UserDoesNotExistError);

                return(View(model));
            }

            try
            {
                var newPassword = _accountRepository.RestorePassword(model.Email);
                _notificationService.SendPassword(model.Email, newPassword);
                return(this.InfoMessage(InfoMessage.Success(DictionaryPhraseRepository.Current.Get("/Accounts/Forgot Password/Reset Password Success", "Your password has been reset."))));
            }
            catch (Exception ex)
            {
                Log.Error($"Can't reset password for user {model.Email}", ex, this);
                ModelState.AddModelError(nameof(model.Email), ex.Message);

                return(View(model));
            }
        }
Пример #10
0
        public void ForgotPasswordShouldReturnSuccessView([Frozen] IAccountRepository repo, INotificationService ns, PasswordResetInfo model, IAccountsSettingsService accountSetting, InfoMessage info)
        {
            var fakeSite = new FakeSiteContext(new StringDictionary
            {
                {
                    "displayMode", "normal"
                }
            }) as SiteContext;

            using (new SiteContextSwitcher(fakeSite))
            {
                var controller = new AccountsController(repo, ns, accountSetting, null, null);
                repo.RestorePassword(Arg.Any <string>()).Returns("new password");
                repo.Exists(Arg.Any <string>()).Returns(true);
                var result = controller.ForgotPassword(model);
                result.Should().BeOfType <ViewResult>().Which.ViewName.Should().Be(ViewPath.InfoMessage);
            }
        }
Пример #11
0
 /// <remarks/>
 public void NotifyPasswordResetAsync(PasswordResetInfo info)
 {
     this.NotifyPasswordResetAsync(info, null);
 }
Пример #12
0
 public void NotifyPasswordReset(PasswordResetInfo info)
 {
     this.Invoke("NotifyPasswordReset", new object[] {
         info
     });
 }
 public void ProcessTest()
 {
     PasswordResetInfo info = new PasswordResetInfo(Guid.Parse("EF84F319-64CD-4540-893C-171104CF0804"), "nancy1", "12345678");
     ProcessPasswordResetService.Default.Process(info);
 }
        public void ForgotPasswordShouldRedirectLoggedUser(Database db, [Content] DbItem item, PasswordResetInfo model, [Frozen] IAccountRepository repo, [NoAutoProperties] AccountsController controller)
        {
            var fakeSite = new FakeSiteContext(new StringDictionary
            {
                { "displayMode", "normal" },
                { "rootPath", "/sitecore/content" },
                { "startItem", item.Name }
            }) as SiteContext;

            fakeSite.Database = db;
            Language.Current  = Language.Invariant;

            using (new SiteContextSwitcher(fakeSite))
                using (new UserSwitcher(@"extranet\fake", true))
                {
                    repo.RestorePassword(Arg.Any <string>()).Returns("new password");
                    repo.Exists(Arg.Any <string>()).Returns(true);
                    var result = controller.ForgotPassword(model);
                    result.Should().BeOfType <RedirectResult>();
                }
        }
Пример #15
0
        private void Send(object emailEntity)
        {
            try
            {
                Execution execution = emailEntity as Execution;
                if (execution != null)
                {
                    Logger.InfoFormat("TransactonServer.NotifyExecution(before send) OrderId= {0}", execution.OrderId);
                    this._EmailService.NotifyOrderExecuted(execution.OrderId);
                    Logger.InfoFormat("TransactonServer.NotifyExecution(after send) OrderId= {0}", execution.OrderId);
                    return;
                }

                AccountRisk accountRisk = emailEntity as AccountRisk;
                if (accountRisk != null)
                {
                    this._EmailService.NotifyRiskLevelChanged(accountRisk.ToRiskLevelChangedInfo());
                    return;
                }

                BalanceInfo balanceInfo = emailEntity as BalanceInfo;
                if (balanceInfo != null)
                {
                    this._EmailService.NotifyBalanceChanged(balanceInfo);
                    return;
                }

                OrderDeleted orderDeleted = emailEntity as OrderDeleted;
                if (orderDeleted != null)
                {
                    this._EmailService.NotifyOrderDeleted(orderDeleted.OrderId);
                    return;
                }

                TradeDayReset tradeDayReset = emailEntity as TradeDayReset;
                if (tradeDayReset != null)
                {
                    this._EmailService.NotifyResetStatement(tradeDayReset.TradeDay.Day);
                    this.SetTradeDayResetEmailGenerated(tradeDayReset.TradeDay.Day);
                    return;
                }

                PasswordResetInfo passwordResetInfo = emailEntity as PasswordResetInfo;
                if (passwordResetInfo != null)
                {
                    this._EmailService.NotifyPasswordReset(passwordResetInfo);
                }

                VerificationCodeInfo verificationCodeInfo = emailEntity as VerificationCodeInfo;
                if (verificationCodeInfo != null)
                {
                    this._EmailService.NotifyTelephonePinReset(verificationCodeInfo);
                }

                ApplyDelivery applyDelivery = emailEntity as ApplyDelivery;
                if (applyDelivery != null)
                {
                    this._EmailService.NotifyDeliveryListing(applyDelivery.DeliveryRequestId);
                }
            }
            catch (Exception exception)
            {
                Logger.Error(emailEntity.ToString(), exception);
            }
        }