rewriting routs

This commit is contained in:
defnotken
2025-09-05 14:52:03 -05:00
parent 56bc277436
commit 332f7f7bb2
2 changed files with 15 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace LightlessSyncAuthService.Controllers; namespace LightlessSyncAuthService.Controllers;
[Route(LightlessAuth.User)] [Route(LightlessAuth.User)]
[Authorize(Policy = "Internal")]
public class UserController : Controller public class UserController : Controller
{ {
protected readonly ILogger Logger; protected readonly ILogger Logger;
@@ -17,8 +18,8 @@ public class UserController : Controller
LightlessDbContextFactory = lightlessDbContext; LightlessDbContextFactory = lightlessDbContext;
} }
[Authorize(Policy = "Internal")] [Route(LightlessAuth.Ban_Uid)]
[HttpPost(LightlessAuth.Ban_Uid)] [HttpPost]
public async Task MarkForBanUid(string uid) public async Task MarkForBanUid(string uid)
{ {
using var dbContext = await LightlessDbContextFactory.CreateDbContextAsync(); using var dbContext = await LightlessDbContextFactory.CreateDbContextAsync();
@@ -35,8 +36,8 @@ public class UserController : Controller
await dbContext.SaveChangesAsync(); await dbContext.SaveChangesAsync();
} }
[Authorize(Policy = "Internal")] [Route(LightlessAuth.User_Unban_Uid)]
[HttpPost(LightlessAuth.User_Unban_Uid)] [HttpPost]
public async Task UnBanUserByUid(string uid) public async Task UnBanUserByUid(string uid)
{ {
using var dbContext = await LightlessDbContextFactory.CreateDbContextAsync(); using var dbContext = await LightlessDbContextFactory.CreateDbContextAsync();
@@ -66,8 +67,8 @@ public class UserController : Controller
await dbContext.SaveChangesAsync(); await dbContext.SaveChangesAsync();
} }
[Authorize(Policy = "Internal")] [Route(LightlessAuth.User_Unban_Discord)]
[HttpPost(LightlessAuth.User_Unban_Discord)] [HttpPost]
public async Task UnBanUserByDiscordId(string discordId) public async Task UnBanUserByDiscordId(string discordId)
{ {
Logger.LogInformation("Unbanning user with discordId: {discordId}", discordId); Logger.LogInformation("Unbanning user with discordId: {discordId}", discordId);

View File

@@ -106,7 +106,9 @@ public class LightlessModule : InteractionModuleBase
using HttpClient c = new HttpClient(); using HttpClient c = new HttpClient();
c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token); c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token);
var testUri = new Uri(_lightlessServicesConfiguration.GetValue<Uri>
(nameof(ServicesConfiguration.MainServerAddress)), "/msgc/sendMessage");
_logger.LogInformation("UnbanByDiscord:URI:{uri}", testUri);
await c.PostAsJsonAsync( await c.PostAsJsonAsync(
new Uri(_lightlessServicesConfiguration.GetValue<Uri>(nameof(ServicesConfiguration.MainServerAddress)), "/msgc/sendMessage"), new Uri(_lightlessServicesConfiguration.GetValue<Uri>(nameof(ServicesConfiguration.MainServerAddress)), "/msgc/sendMessage"),
new ClientMessage(messageType, message, uid ?? string.Empty) new ClientMessage(messageType, message, uid ?? string.Empty)
@@ -152,6 +154,7 @@ public class LightlessModule : InteractionModuleBase
try try
{ {
using HttpClient c = new HttpClient(); using HttpClient c = new HttpClient();
c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token); c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token);
await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri> await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri>
(nameof(ServicesConfiguration.MainServerAddress)), "/user/unbanDiscord"), new { discordId }) (nameof(ServicesConfiguration.MainServerAddress)), "/user/unbanDiscord"), new { discordId })
@@ -193,6 +196,9 @@ public class LightlessModule : InteractionModuleBase
try try
{ {
using HttpClient c = new HttpClient(); using HttpClient c = new HttpClient();
var testUri = new Uri(_lightlessServicesConfiguration.GetValue<Uri>
(nameof(ServicesConfiguration.MainServerAddress)), "/user/unbanDiscord");
_logger.LogInformation("UnbanByDiscord:URI:{uri}", testUri);
c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token); c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token);
await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri> await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri>
(nameof(ServicesConfiguration.MainServerAddress)), "/user/unbanUID"), new { uid }) (nameof(ServicesConfiguration.MainServerAddress)), "/user/unbanUID"), new { uid })
@@ -234,6 +240,7 @@ public class LightlessModule : InteractionModuleBase
try try
{ {
using HttpClient c = new HttpClient(); using HttpClient c = new HttpClient();
c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token); c.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _serverTokenGenerator.Token);
await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri> await c.PostAsJsonAsync(new Uri(_lightlessServicesConfiguration.GetValue<Uri>
(nameof(ServicesConfiguration.MainServerAddress)), "/user/ban"), new { uid }) (nameof(ServicesConfiguration.MainServerAddress)), "/user/ban"), new { uid })