Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
API Token Web - Rename files
KrzysztofPajak655cb80465ff
diff --git a/src/API/Grand.Api/Commands/Handlers/Common/GenerateGrandWebTokenCommandHandler.cs b/src/API/Grand.Api/Commands/Handlers/Common/GenerateTokenWebCommandHandler.cssimilarity index 71%rename from src/API/Grand.Api/Commands/Handlers/Common/GenerateGrandWebTokenCommandHandler.csrename to src/API/Grand.Api/Commands/Handlers/Common/GenerateTokenWebCommandHandler.csindex fde3dccc8..d136a25e1 100644--- a/src/API/Grand.Api/Commands/Handlers/Common/GenerateGrandWebTokenCommandHandler.cs+++ b/src/API/Grand.Api/Commands/Handlers/Common/GenerateTokenWebCommandHandler.cs@@ -3,25 +3,21 @@ using Grand.Api.Infrastructure.Extensions;using Grand.Api.Jwt;using Grand.Infrastructure.Configuration;using MediatR;-using System;-using System.Collections.Generic;-using System.Linq;-using System.Text;using System.Threading;using System.Threading.Tasks;namespace Grand.Api.Commands.Handlers.Common{- public class GenerateGrandWebTokenCommandHandler : IRequestHandler<GenerateGrandWebTokenCommand, string>+ public class GenerateTokenWebCommandHandler : IRequestHandler<GenerateTokenWebCommand, string>{private readonly GrandWebApiConfig _grandWebApiConfig;- public GenerateGrandWebTokenCommandHandler(GrandWebApiConfig grandWebApiConfig)+ public GenerateTokenWebCommandHandler(GrandWebApiConfig grandWebApiConfig){_grandWebApiConfig = grandWebApiConfig;}- public async Task<string> Handle(GenerateGrandWebTokenCommand request, CancellationToken cancellationToken)+ public async Task<string> Handle(GenerateTokenWebCommand request, CancellationToken cancellationToken){var token = new JwtTokenBuilder();token.AddSecurityKey(JwtSecurityKey.Create(_grandWebApiConfig.SecretKey));diff --git a/src/API/Grand.Api/Commands/Models/Common/GenerateGrandWebTokenCommand.cs b/src/API/Grand.Api/Commands/Models/Common/GenerateTokenWebCommand.cssimilarity index 54%rename from src/API/Grand.Api/Commands/Models/Common/GenerateGrandWebTokenCommand.csrename to src/API/Grand.Api/Commands/Models/Common/GenerateTokenWebCommand.csindex 90989e07a..2dd8948a0 100644--- a/src/API/Grand.Api/Commands/Models/Common/GenerateGrandWebTokenCommand.cs+++ b/src/API/Grand.Api/Commands/Models/Common/GenerateTokenWebCommand.cs@@ -1,13 +1,9 @@using MediatR;-using System;using System.Collections.Generic;-using System.Linq;-using System.Text;-using System.Threading.Tasks;namespace Grand.Api.Commands.Models.Common{- public class GenerateGrandWebTokenCommand : IRequest<string>+ public class GenerateTokenWebCommand : IRequest<string>{public Dictionary<string, string> Claims { get; set; }}diff --git a/src/API/Grand.Api/Web/TokenController.cs b/src/API/Grand.Api/Controllers/TokenWebController.cssimilarity index 78%rename from src/API/Grand.Api/Web/TokenController.csrename to src/API/Grand.Api/Controllers/TokenWebController.csindex f1566143f..0fc5c1c51 100644--- a/src/API/Grand.Api/Web/TokenController.cs+++ b/src/API/Grand.Api/Controllers/TokenWebController.cs@@ -7,17 +7,15 @@ using Grand.Domain.Customers;using Grand.Infrastructure;using MediatR;using Microsoft.AspNetCore.Authorization;-using Microsoft.AspNetCore.Components;using Microsoft.AspNetCore.Mvc;using System;using System.Collections.Generic;using System.Linq;-using System.Text;using System.Threading.Tasks;-namespace Grand.Api.Web+namespace Grand.Api.Controllers{- public class TokenController : Controller+ public class TokenWebController : Controller{private readonly ICustomerService _customerService;private readonly ICustomerManagerService _customerManagerService;@@ -26,8 +24,13 @@ namespace Grand.Api.Webprivate readonly IRefreshTokenService _refreshTokenService;private readonly IUserFieldService _userFieldService;- public TokenController(ICustomerService customerService, ICustomerManagerService customerManagerService, IMediator mediator, IStoreHelper storeHelper- , IRefreshTokenService refreshTokenService,IUserFieldService userFieldService)+ public TokenWebController(+ ICustomerService customerService,+ ICustomerManagerService customerManagerService,+ IMediator mediator,+ IStoreHelper storeHelper,+ IRefreshTokenService refreshTokenService,+ IUserFieldService userFieldService){_customerService = customerService;_customerManagerService = customerManagerService;@@ -61,10 +64,17 @@ namespace Grand.Api.Web{return BadRequest(result.ToString());}+var customer = await _customerService.GetCustomerByEmail(model.Email);+var claims = new Dictionary<string, string> {- { "Email", model.Email},- { "Token",await _userFieldService.GetFieldsForEntity<string>(customer, SystemCustomerFieldNames.PasswordToken) }+ {+ "Email", model.Email+ },+ {+ "Token",+ await _userFieldService.GetFieldsForEntity<string>(customer, SystemCustomerFieldNames.PasswordToken)+ }};var tokenDto = await GetToken(claims, customer);return Ok(tokenDto);@@ -79,7 +89,7 @@ namespace Grand.Api.WebCustomer customer = null;var claims = new Dictionary<string, string>();var principal = _refreshTokenService.GetPrincipalFromToken(tokenDto.AccessToken);- email= principal.Claims.ToList().FirstOrDefault(x => x.Type == "Email")?.Value;+ email = principal.Claims.ToList().FirstOrDefault(x => x.Type == "Email")?.Value;if (!string.IsNullOrEmpty(email)){customer = await _customerService.GetCustomerByEmail(email);@@ -94,17 +104,17 @@ namespace Grand.Api.Web}var customerRefreshToken = await _refreshTokenService.GetCustomerRefreshToken(customer);- if(customerRefreshToken is null || !customerRefreshToken.Token.Equals(tokenDto.RefreshToken))+ if (customerRefreshToken is null || !customerRefreshToken.Token.Equals(tokenDto.RefreshToken)){return BadRequest("Invalid refresh token");}- var token= await GetToken(claims, customer); ;+ var token = await GetToken(claims, customer); ;return Ok(token);}- private async Task<TokenDto> GetToken(Dictionary<string,string> claims,Customer customer)+ private async Task<TokenDto> GetToken(Dictionary<string, string> claims, Customer customer){- var token = await _mediator.Send(new GenerateGrandWebTokenCommand() { Claims = claims });+ var token = await _mediator.Send(new GenerateTokenWebCommand() { Claims = claims });var refreshToken = _refreshTokenService.GenerateRefreshToken();await _refreshTokenService.SaveRefreshTokenToCustomer(customer, refreshToken);return new TokenDto() {