Exemplo n.º 1
0
        public ApiResult ChangePassword(string id, [FromBody] ChangePasswordModel member)
        {
            Argument.ThrowIfNullOrEmpty(member.Password, "旧密码");
            Argument.ThrowIfNullOrEmpty(member.NewPassword, "新密码");

            if (!AuthorizedUser.Id.Equals(id, StringComparison.OrdinalIgnoreCase))
            {
                throw new WebApiInnerException("0001", "只允许修改自己密码");
            }

            var result = new ApiResult();

            if (Platform != Platform.Web)
            {
                member.Password    = _securityService.Decrypt(member.Password);
                member.NewPassword = _securityService.Decrypt(member.NewPassword);
            }

            var identityResult = _userManager.ChangePasswordAsync(AuthorizedUser.Id, member.Password, member.NewPassword).Result;

            if (!identityResult.Succeeded)
            {
                throw new WebApiInnerException("0002", identityResult.Errors.FirstOrDefault());
            }

            return(result);
        }