示例#1
0
        public ActionResult ResetPassword(AccountManagementModel accountManagementModel)
        {
            var accountDetail = _accountDao.FindById(accountManagementModel.Id);

            var newPassword  = new PasswordService().GeneratePassword();
            var resetCommand = new ResetAccountPassword
            {
                AccountId = accountManagementModel.Id,
                Password  = newPassword
            };

            _commandBus.Send(resetCommand);

            if (_serverSettings.ServerData.SendPasswordResetAsSMSEnabled)
            {
                var smsCommand = new SendPasswordResetSMS
                {
                    ClientLanguageCode = accountDetail.Language,
                    CountryCode        = accountDetail.Settings.Country,
                    PhoneNumber        = accountDetail.Settings.Phone,
                    Password           = newPassword
                };

                _commandBus.Send(smsCommand);
            }
            else
            {
                var emailCommand = new SendPasswordResetEmail
                {
                    ClientLanguageCode = accountDetail.Language,
                    EmailAddress       = accountDetail.Email,
                    Password           = newPassword,
                };

                _commandBus.Send(emailCommand);
            }

            TempData["UserMessage"] = "Operation done successfully, new password: "******"Index", accountManagementModel));
        }
示例#2
0
        public object Post(ResetPassword request)
        {
            var user = _dao.FindByEmail(request.EmailAddress);

            if (user == null)
            {
                throw new HttpError(ErrorCode.ResetPassword_AccountNotFound.ToString());
            }

            if (!string.IsNullOrEmpty(user.FacebookId))
            {
                throw new HttpError(ErrorCode.ResetPassword_FacebookAccount.ToString());
            }

            if (!string.IsNullOrEmpty(user.TwitterId))
            {
                throw new HttpError(ErrorCode.ResetPassword_TwitterAccount.ToString());
            }

            var currentSession = this.GetSession();

            var currentUserId = currentSession.UserAuthId.HasValueTrimmed()
                                ? new Guid(currentSession.UserAuthId)
                                : Guid.Empty;

            if (user.Id == currentUserId)
            {
                // In case user is signed in, sign out user to force him to authenticate again
                base.RequestContext.Get <IHttpRequest>().RemoveSession();
            }

            var newPassword  = new PasswordService().GeneratePassword();
            var resetCommand = new ResetAccountPassword
            {
                AccountId = user.Id,
                Password  = newPassword
            };

            _commandBus.Send(resetCommand);

            if (_serverSettings.ServerData.SendPasswordResetAsSMSEnabled)
            {
                var smsCommand = new SendPasswordResetSMS
                {
                    ClientLanguageCode = user.Language,
                    CountryCode        = user.Settings.Country,
                    PhoneNumber        = user.Settings.Phone,
                    Password           = newPassword
                };

                _commandBus.Send(smsCommand);
            }
            else
            {
                var emailCommand = new SendPasswordResetEmail
                {
                    ClientLanguageCode = user.Language,
                    EmailAddress       = user.Email,
                    Password           = newPassword,
                };

                _commandBus.Send(emailCommand);
            }

            return(new HttpResult(HttpStatusCode.OK));
        }