Exemple #1
0
        public async Task <IHttpActionResult> ChangePassword(ChangePasswordDto changePasswordDto)
        {
            _logger.Debug("Begin");
            if (!ModelState.IsValid)
            {
                _logger.Error(string.Format(
                                  "Model state is not valid. ModelState: [{0}]",
                                  string.Join(Environment.NewLine, ModelState.Select(x => string.Format("{0}: {1}", x.Key, x.Value)))));
                return(BadRequest(ModelState));
            }

            var            id     = User.Identity.GetUserId();
            IdentityResult result = await NdUserManager.ChangePasswordAsync(id, changePasswordDto.OldPassword, changePasswordDto.NewPassword);

            if (!result.Succeeded)
            {
                _logger.Error(string.Format(
                                  "Change password failed. Id: [{0}], Reason: [{1}]",
                                  User.Identity.GetUserId(),
                                  string.Join(Environment.NewLine, result.Errors)));
                return(GetErrorResult(result));
            }

            _logger.Debug(string.Format("Password changed successfully. Id: [{0}]", id));
            return(Ok());
        }