public static UpdateUserParameter ToParameter(this UpdateResourceOwnerViewModel updateResourceOwnerViewModel)
        {
            if (updateResourceOwnerViewModel == null)
            {
                throw new ArgumentNullException(nameof(updateResourceOwnerViewModel));
            }

            var result = new UpdateUserParameter
            {
                Password = updateResourceOwnerViewModel.NewPassword,
                TwoFactorAuthentication = updateResourceOwnerViewModel.TwoAuthenticationFactor,
                Claims = new List <Claim>(),
                Login  = updateResourceOwnerViewModel.Name
            };

            if (!string.IsNullOrWhiteSpace(updateResourceOwnerViewModel.Name))
            {
                result.Claims.Add(new Claim(Core.Jwt.Constants.StandardResourceOwnerClaimNames.Name, updateResourceOwnerViewModel.Name));
            }

            if (!string.IsNullOrWhiteSpace(updateResourceOwnerViewModel.Email))
            {
                result.Claims.Add(new Claim(Core.Jwt.Constants.StandardResourceOwnerClaimNames.Email, updateResourceOwnerViewModel.Email));
            }

            if (!string.IsNullOrWhiteSpace(updateResourceOwnerViewModel.PhoneNumber))
            {
                result.Claims.Add(new Claim(Core.Jwt.Constants.StandardResourceOwnerClaimNames.PhoneNumber, updateResourceOwnerViewModel.PhoneNumber));
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新User
        /// </summary>
        /// <returns></returns>
        public bool Update(UpdateUserParameter parameter)
        {
            var Result = _UserRepository.Update(new UpdateUserRptParameter()
            {
                UserId    = parameter.UserId,
                Name      = parameter.Name,
                IsBlocked = parameter.IsBlocked
            });

            return(Result);
        }
Ejemplo n.º 3
0
        public async Task When_Passing_Correct_Parameters_Then_ResourceOwnerIs_Updated()
        {
            // ARRANGE
            InitializeFakeObjects();
            var parameter = new UpdateUserParameter
            {
                Login    = "******",
                Password = "******"
            };

            _authenticateResourceOwnerServiceStub.Setup(r => r.AuthenticateResourceOwnerAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(new ResourceOwner()));

            // ACT
            await _updateUserOperation.Execute(parameter);

            // ASSERTS
            _resourceOwnerRepositoryStub.Setup(r => r.UpdateAsync(It.IsAny <ResourceOwner>()));
        }
        public async Task <bool> Execute(UpdateUserParameter updateUserParameter)
        {
            if (updateUserParameter == null)
            {
                throw new ArgumentNullException(nameof(updateUserParameter));
            }

            if (string.IsNullOrWhiteSpace(updateUserParameter.Login))
            {
                throw new ArgumentNullException(nameof(updateUserParameter.Login));
            }

            var resourceOwner = await _authenticateResourceOwnerService.AuthenticateResourceOwnerAsync(updateUserParameter.Login);

            if (resourceOwner == null)
            {
                throw new IdentityServerException(
                          Errors.ErrorCodes.InternalError,
                          Errors.ErrorDescriptions.TheRoDoesntExist);
            }

            resourceOwner.TwoFactorAuthentication = updateUserParameter.TwoFactorAuthentication;
            if (!string.IsNullOrWhiteSpace(updateUserParameter.Password))
            {
                resourceOwner.Password = _authenticateResourceOwnerService.GetHashedPassword(updateUserParameter.Password);
            }

            resourceOwner.Claims = updateUserParameter.Claims;
            if (resourceOwner.Claims != null)
            {
                Claim updatedClaim;
                if (((updatedClaim = resourceOwner.Claims.FirstOrDefault(c => c.Type == Jwt.Constants.StandardResourceOwnerClaimNames.UpdatedAt)) != null))
                {
                    resourceOwner.Claims.Remove(updatedClaim);
                }

                resourceOwner.Claims.Add(new Claim(Jwt.Constants.StandardResourceOwnerClaimNames.UpdatedAt, DateTime.UtcNow.ToString()));
            }

            return(await _resourceOwnerRepository.UpdateAsync(resourceOwner));
        }
Ejemplo n.º 5
0
        public async Task When_ResourceOwner_DoesntExist_Then_Exception_Is_Thrown()
        {
            // ARRANGE
            InitializeFakeObjects();
            var parameter = new UpdateUserParameter
            {
                Login    = "******",
                Password = "******"
            };

            _authenticateResourceOwnerServiceStub.Setup(r => r.AuthenticateResourceOwnerAsync(It.IsAny <string>()))
            .Returns(Task.FromResult((ResourceOwner)null));

            // ACT
            var exception = await Assert.ThrowsAsync <IdentityServerException>(() => _updateUserOperation.Execute(parameter));

            // ASSERTS
            Assert.NotNull(exception);
            Assert.True(exception.Code == Errors.ErrorCodes.InternalError);
            Assert.True(exception.Message == Errors.ErrorDescriptions.TheRoDoesntExist);
        }
Ejemplo n.º 6
0
 public UizaData Update(UpdateUserParameter param)
 {
     param.DescriptionLink = DescriptionLinkUtility.GetDescriptionLink(DescriptionLinkConstants.USER.UPDATE);
     return(this.PutRequest <UizaData>(Constants.ApiAction.USER, param));
 }
Ejemplo n.º 7
0
 public async Task <bool> UpdateUser(UpdateUserParameter updateUserParameter)
 {
     return(await _updateUserOperation.Execute(updateUserParameter));
 }