Example #1
0
        public async Task <IActionResult> UpdateUserPassword(Guid id, [FromBody] UserForPasswordUpdateDto user)
        {
            //This verification disable edit another user, update to add Admin role
            if (id != Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            if (user == null)
            {
                _logger.LogError("User object sent from client is null.");
                return(BadRequest("User object is null"));
            }

            if (!ModelState.IsValid)
            {
                _logger.LogError("Invalid User object sent from client.");
                return(BadRequest("Invalid model object"));
            }

            var dbUser = await _repository.User.GetUserByIdAsync(id);

            if (dbUser.IsEmptyObject())
            {
                _logger.LogError($"User with id: {id}, hasn't been found in db.");
                return(NotFound());
            }

            await _repository.User.UpdateUserPasswordAsync(dbUser, user.Password);

            _logger.LogInfo($"Updated User password with id: {id}");
            return(NoContent());
        }
Example #2
0
        public async Task <IActionResult> UpdateUserPassword(int id,
                                                             [FromBody] UserForPasswordUpdateDto userForPasswordUpdate)
        {
            if (userForPasswordUpdate == null)
            {
                ModelState.AddModelError("Message", "Unable to locate payload for new request");
                return(BadRequest(ModelState));
            }

            var command = new ChangeUserPasswordCommand(id, userForPasswordUpdate.Password);

            _logger.LogInformation(
                "----- Sending command: ChangeUserPasswordCommand - {userId}",
                command.UserId);

            var commandResult = await _mediator.Send(command);

            if (!commandResult)
            {
                return(BadRequest("Command not created"));
            }

            return(Ok());
        }
Example #3
0
        public void UpdateUserPassword(UserForPasswordUpdateDto userForPasswordUpdate)
        {
            var hashedPassword = Session.HashPassword(userForPasswordUpdate.Password);

            _userRepository.UpdateUserPassword(userForPasswordUpdate.Id, hashedPassword);
        }