diff --git a/src/FrontOffice.BFF.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandHandler.cs b/src/FrontOffice.BFF.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandHandler.cs index 1de4a6a..00c7952 100644 --- a/src/FrontOffice.BFF.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandHandler.cs +++ b/src/FrontOffice.BFF.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandHandler.cs @@ -5,15 +5,21 @@ namespace FrontOffice.BFF.Application.UserCQ.Commands.UpdateUser; public class UpdateUserCommandHandler : IRequestHandler { private readonly IApplicationContractContext _context; + private readonly ICurrentUserService _currentUserService; - public UpdateUserCommandHandler(IApplicationContractContext context) + public UpdateUserCommandHandler(IApplicationContractContext context, ICurrentUserService currentUserService) { _context = context; + _currentUserService = currentUserService; } public async Task Handle(UpdateUserCommand request, CancellationToken cancellationToken) { - // var updatingUserRequest = new UpdateUserRequest(); + var updatingUserRequest = request.Adapt(); + if (request.Id <= 0) + { + updatingUserRequest.Id = Convert.ToInt64(_currentUserService.UserId); + } // var existUser = await _context.User.GetUserAsync(new GetUserRequest() // { // Id = request.Id @@ -60,7 +66,7 @@ public class UpdateUserCommandHandler : IRequestHandler // updatingUserRequest.SmsNotifications = request.SmsNotifications; // } - await _context.User.UpdateUserAsync(request: request.Adapt(), + await _context.User.UpdateUserAsync(request: updatingUserRequest, cancellationToken: cancellationToken); return Unit.Value; } diff --git a/src/FrontOffice.BFF.Infrastructure/ConfigureServices.cs b/src/FrontOffice.BFF.Infrastructure/ConfigureServices.cs index 53fae38..5e825bd 100644 --- a/src/FrontOffice.BFF.Infrastructure/ConfigureServices.cs +++ b/src/FrontOffice.BFF.Infrastructure/ConfigureServices.cs @@ -4,19 +4,25 @@ using FrontOffice.BFF.Infrastructure.Services; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; +using Microsoft.IdentityModel.Logging; using Microsoft.IdentityModel.Tokens; namespace Microsoft.Extensions.DependencyInjection; public static class ConfigureServices { - public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration) + public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, + IConfiguration configuration) { services.AddSingleton(); services.AddSingleton(); services.AddInfrastructureGrpcServices(configuration); + #region AddAuthentication +#if DEBUG + IdentityModelEventSource.ShowPII = true; +#endif var message = ""; services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(jwtBearerOptions => @@ -31,8 +37,8 @@ public static class ConfigureServices jwtBearerOptions.RequireHttpsMetadata = false; jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters { - ValidateIssuer = false,//todo change to true in production - ValidateAudience = false,//todo change to true in production + ValidateIssuer = false, //todo change to true in production + ValidateAudience = false, //todo change to true in production ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = configuration["JwtIssuer"],