public async Task ChangePassword(ChangePasswordInput input)
        {
            await CheckPasswordComplexity(input.NewPassword);

            var user = await GetCurrentUserAsync();

            CheckErrors(await UserManager.ChangePasswordAsync(user.Id, input.CurrentPassword, input.NewPassword));
        }
        public async Task ChangePassword(ChangePasswordInput input)
        {
            await UserManager.InitializeOptionsAsync(AbpSession.TenantId);

            var user = await GetCurrentUserAsync();

            CheckErrors(await UserManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword));
        }
示例#3
0
        public async Task ChangePassword(ChangePasswordInput input)
        {
            User currentUserAsync = await this.GetCurrentUserAsync();

            IdentityResult identityResult = await this.UserManager.ChangePasswordAsync(currentUserAsync.Id, input.CurrentPassword, input.NewPassword);

            this.CheckErrors(identityResult);
        }
示例#4
0
 public ActionResult ChangePassword(ChangePasswordInput input)
 {
     if (!ModelState.IsValid)
     {
         return(View(input));
     }
     service.ChangePassword(input.Id, input.Password);
     return(Json(new{ Login = service.Get(input.Id).Login }));
 }
示例#5
0
 public ActionResult ChangePassword(ChangePasswordInput input)
 {
     if (!ModelState.IsValid)
     {
         return(View(input));
     }
     s.ChangePassword(input.Id, input.Password);
     return(Content("ok"));
 }
示例#6
0
        public ActionResult ChangePassword(ChangePasswordInput input)
        {
            if (!ModelState.IsValid)
            {
                return(View(input));
            }

            s.ChangePassword(input.Id, input.Password);
            return(Json(new { input.Id }));
        }
示例#7
0
        public async Task <IActionResult> ChangePassword([FromBody] ChangePasswordInput input)
        {
            if (input.NewPassword != input.ConfirmNewPassword)
            {
                return(BadRequest(new { Message = "As senhas precisam ser iguais!" }));
            }
            var result = _handler.Handle(input);

            return(await ApiResponse(result));
        }
示例#8
0
        public async Task ChangePassword(ChangePasswordInput input)
        {
            //await CheckPasswordComplexity(input.NewPassword);

            var user = await UserManager.GetUserByIdAsync(AbpSession.GetUserId());

            //await UserManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword);
            CheckErrors(await UserManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword));
            //CheckErrors(await _userManager.ChangePasswordAsync(user, input.User.Password));
        }
示例#9
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="input"></param>
        /// <param name="output"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool ChangePassword(ChangePasswordInput input, ref ChangePasswordOutput output, ref string errMsg)
        {
            bool doChange = HttpCommonMethod <ChangePasswordInput, ChangePasswordOutput>("/antuser/user.resetPassword.do", GlobalVariable.RequestMethod.POST, input, ref output, ref errMsg);

            if (doChange && output.result == (int)GlobalVariable.Result.Failure)
            {
                errMsg = string.IsNullOrEmpty(output.errorCode) ? "修改密码失败" : resources.GetString("E_" + output.errorCode);
                return(false);
            }
            return(doChange);
        }
示例#10
0
        public async Task ChangePassword(ChangePasswordInput input)
        {
            var user = await _userManager.GetUserByIdAsync(AbpSession.UserId.Value);

            var result = await _userManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword);

            if (!result.Succeeded)
            {
                throw new AbpProjectNameBusinessException(ErrorCode.ChangePasswordFailed, string.Join(" ", result.Errors.Select(e => L(e.Code))));
            }
        }
        public void ChangePassword(ChangePasswordInput input)
        {
            var currentUser = _userRepository.Get(AbpUser.CurrentUserId.Value);

            if (currentUser.Password != input.CurrentPassword)
            {
                throw new UserFriendlyException("Current password is invalid!");
            }

            currentUser.Password = input.NewPassword;
            currentUser.Password = new PasswordHasher().HashPassword(currentUser.Password);
        }
示例#12
0
        public async Task <IActionResult> SubmitChangePassword([FromBody] ChangePasswordInput input)
        {
            var userId = _userApp.GetCurrentUserId();

            userId.CheckArgumentIsNull(nameof(userId));
            var userEntity = await _userApp.FindUserAsync(userId);

            userEntity.CheckArgumentIsNull(nameof(userEntity));
            var(succeeded, error) =
                await _userApp.ChangePasswordAsync(userEntity, input.OldUserPassword, input.UserPassword);

            return(succeeded ? Success("重置密码成功") : Error(error));
        }
示例#13
0
        public void ChangePassword(ChangePasswordInput input)
        {
            Assert.IfNullOrWhiteSpaceThrow(input.Password1, "密码不能为空");
            Assert.IfNullOrWhiteSpaceThrow(input.Password2, "密码不能为空");
            Assert.IfTrueThrow(input.Password1 != input.Password2, "密码不一致");

            var user = _userRepository.GetById(input.Id);

            Assert.IfNullThrow(user, "用户不存在");

            user.Password = input.Password1.ToMD5();

            _userRepository.Update(user);
        }
示例#14
0
        public async Task ChangePasswordFromAdmin(ChangePasswordInput input)
        {
            if (input.UserId == null)
            {
                throw new UserFriendlyException(L("UserNotFound"));
            }
            var user = await UserManager.GetUserByIdAsync(input.UserId.Value);

            var hasher = new PasswordHasher();

            user.Password = hasher.HashPassword(input.NewPassword);
            user.ShouldChangePasswordOnLogin = true;
            await UserManager.UpdateAsync(user);
        }
示例#15
0
        /// <summary>
        /// 修改当前用户密码
        /// </summary>
        /// <returns></returns>
        public async Task <bool> ChangePassword(ChangePasswordInput input)
        {
            var user = await _userManager.GetUserByIdAsync(GetSessionUserId());

            // 检查密码是否正确
            if (!await _userManager.CheckPasswordAsync(user, input.CurrentPassword))
            {
                throw new UserFriendlyException("输入的当前密码错误");
            }
            // 修改密码
            var result = await _userManager.ChangePasswordAsync(user, input.NewPassword);

            return(result.Succeeded);
        }
示例#16
0
        public async Task ChangePassword(ChangePasswordInput input)
        {
            await CheckPasswordComplexity(input.NewPassword);

            var user = await GetCurrentUserAsync();

            user.ShouldChangePasswordOnNextLogin = false;
            var loginAsync = await _logInManager.LoginAsync(user.UserName, input.CurrentPassword, shouldLockout : false);

            if (loginAsync.Result != AbpLoginResultType.Success)
            {
                throw new UserFriendlyException("原密码错误");
            }
            user.Password = _passwordHasher.HashPassword(user, input.NewPassword);
            //CheckErrors(await UserManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword));
        }
示例#17
0
        public async Task ChangePassword(ChangePasswordInput input)
        {
            var user = await UserManager.FindByIdAsync(AbpSession.UserId.Value);

            if (user == null)
            {
                throw new UserFriendlyException("用户不存在");
            }

            if (!await UserManager.CheckPasswordAsync(user, input.Password))
            {
                throw new UserFriendlyException("原密码错误");
            }
            UserManager.RemovePassword(user.Id);
            UserManager.AddPassword(user.Id, input.NewPassword);
        }
示例#18
0
        public async Task ChangePassword(ChangePasswordInput input)
        {
            Debug.Assert(_abpSession.UserId != null, "_abpSession.UserId != null");
            var userId = _abpSession.UserId.Value;
            var user   = await _userManager.GetUserByIdAsync(userId);

            var loginAsync = await _logInManager.LoginAsync(user.UserName, input.CurrentPassword, shouldLockout : false);

            if (loginAsync.Result != AbpLoginResultType.Success)
            {
                throw new UserFriendlyException(
                          "Your 'Existing Password' did not match the one on record.  Please try again or contact an administrator for assistance in resetting your password.");
            }

            user.Password = _passwordHasher.HashPassword(user, input.NewPassword);
        }
示例#19
0
        public ICommandResult Handle(ChangePasswordInput input)
        {
            var user = _repository.FirstOrDefault(p => p.Username == input.Username);

            user.ResetPassword(input.NewPassword);

            var validator = new UserValidator().Validate(user);

            if (validator.IsValid)
            {
                _repository.Update(user);
            }

            _mailService.Send(user.Email.Address, "Senha resetada!", $"Sua nova senha é: {input.NewPassword}");
            return(new CommandResult($"A senha de {user.Name} foi resetada com sucesso e enviada para o e-mail {user.Email}.", validator.Errors));
        }
示例#20
0
        public async Task ChangePassword(ChangePasswordInput input)
        {
            await UserManager.InitializeOptionsAsync(AbpSession.TenantId);

            var user = await GetCurrentUserAsync();

            if (await UserManager.CheckPasswordAsync(user, input.CurrentPassword))
            {
                CheckErrors(await UserManager.ChangePasswordAsync(user, input.NewPassword));
            }
            else
            {
                CheckErrors(IdentityResult.Failed(new IdentityError
                {
                    Description = "Incorrect password."
                }));
            }
        }
        public async Task <bool> ChangePassword([FromBody] ChangePasswordInput changePasswordInput)
        {
            if (!ModelState.IsValid)
            {
                return(false);
            }

            try
            {
                return(await this.userService.ChangePassword(changePasswordInput));
            }
            catch (Exception exception)
            {
                Debug.Write($"An error occured: {exception.Message}");

                return(false);
            }
        }
        public virtual async Task ChangePasswordAsync(Guid id, ChangePasswordInput input)
        {
            var user = await UserManager.GetByIdAsync(id);

            if (user.IsExternal)
            {
                throw new BusinessException(code: Volo.Abp.Identity.IdentityErrorCodes.ExternalUserPasswordChange);
            }

            if (user.PasswordHash == null)
            {
                (await UserManager.AddPasswordAsync(user, input.NewPassword)).CheckErrors();

                return;
            }

            (await UserManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword)).CheckErrors();
        }
示例#23
0
        public async Task <ActionResult> ChangePassword([FromBody] ChangePasswordInput input)
        {
            if (input.NewPassword != input.PasswordRepeat)
            {
                return(BadRequest("Passwords are not matched!")); // TODO: Make these messages static object
            }

            var user = await _authenticationAppService.FindUserByUserNameAsync(User.Identity.Name);

            var result = await _authenticationAppService.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword);

            if (!result.Succeeded)
            {
                return(BadRequest(string.Join(Environment.NewLine, result.Errors.Select(e => e.Description))));
            }

            return(Ok());
        }
示例#24
0
        public async Task <IActionResult> ChangePassword(ChangePasswordInput input)
        {
            if (string.IsNullOrEmpty(input.Password))
            {
                return(BadRequest(EmptyPasswordErrorMessage));
            }

            var userExists = await this.userService.ExistsByIdAsync(input.UserId);

            if (!userExists)
            {
                return(BadRequest(UserNotExistsErrorMessage));
            }

            await this.identityService.ChangePassword(input.UserId, input.Password);

            return(Ok("Password changed!"));
        }
示例#25
0
        public async Task ChangePassword(ChangePasswordInput input)
        {
            var user = await UserManager.GetUserByIdAsync(StudioXSession.GetUserId());

            var hashedPassword     = passwordHasher.HashPassword(user, input.Password);
            var verificationResult = passwordHasher.VerifyHashedPassword(user, hashedPassword, input.Password);

            if (verificationResult != PasswordVerificationResult.Success)
            {
                throw new UserFriendlyException("Current password must match old password!");
            }

            var identityResult = await UserManager.ChangePasswordAsync(user, input.NewPassword);

            if (!identityResult.Succeeded)
            {
                throw new UserFriendlyException(identityResult.Errors.JoinAsString(", "));
            }
        }
        public async Task ChangePassword(ChangePasswordInput input)
        {
            if (AbpSession.UserName == "demo")
            {
                throw new UserFriendlyException("少年不要调皮,demo的密码不能修改。");
            }
            if (AbpSession.UserName == "admin")
            {
                throw new UserFriendlyException("少年不要调皮,Admin的密码不能修改。");
            }



            await CheckPasswordComplexity(input.NewPassword);

            var user = await GetCurrentUserAsync();

            CheckErrors(await UserManager.ChangePasswordAsync(user.Id, input.CurrentPassword, input.NewPassword));
        }
示例#27
0
        public async Task Execute(ChangePasswordInput input)
        {
            if (input == null)
            {
                outputPort.WriteError(""); return;
            }

            var user = await userRepository.Get(input.UserId);

            if (user == null)
            {
                outputPort.NotFound(""); return;
            }

            user.Password = passwordHasher.EncodePassword(input.NewPassword);
            bool success = await userRepository.Update(user);

            outputPort.Standart(new ChangePasswordOutput(success));
        }
示例#28
0
    public virtual async Task ChangePasswordAsync(ChangePasswordInput input)
    {
        await IdentityOptions.SetAsync();

        var currentUser = await UserManager.GetByIdAsync(CurrentUser.GetId());

        if (currentUser.IsExternal)
        {
            throw new BusinessException(code: IdentityErrorCodes.ExternalUserPasswordChange);
        }

        if (currentUser.PasswordHash == null)
        {
            (await UserManager.AddPasswordAsync(currentUser, input.NewPassword)).CheckErrors();

            return;
        }

        (await UserManager.ChangePasswordAsync(currentUser, input.CurrentPassword, input.NewPassword)).CheckErrors();
    }
示例#29
0
        /// <summary>
        /// Reset user password
        /// </summary>
        /// <param name="changePasswordInput"></param>
        /// <returns></returns>
        public async Task <bool> ChangePassword(ChangePasswordInput changePasswordInput)
        {
            var user = await this.applicationDbContext.ApplicationUsers.FirstOrDefaultAsync(
                x => x.Username == changePasswordInput.Username);

            if (user == null)
            {
                return(false);
            }

            var passwordDetails = CreatePassword(changePasswordInput.Password);

            user.HashedPassword = passwordDetails.HashedPassword;
            user.Salt           = passwordDetails.Salt;

            this.applicationDbContext.ApplicationUsers.Update(user);
            await this.applicationDbContext.SaveChangesAsync();

            return(true);
        }
示例#30
0
        public async Task <ApiResult> ChangePassword([FromBody] ChangePasswordInput input)
        {
            ApiResult result = new ApiResult();
            var       user   = await userManager.FindByNameAsync(session.Username);

            if (user != null)
            {
                var changeRs = await userManager.ChangePasswordAsync(user, input.CurrentPassword, input.NewPassword);

                result.success = changeRs.Succeeded;
                result.message = string.Join(',', changeRs.Errors.Select(x => x.Description));
            }
            else
            {
                result.success = false;
                result.message = "用户不存在";
            }

            return(result);
        }