mirror of
https://github.com/techgarage-ir/MTWireGuard.git
synced 2025-08-20 01:18:19 +02:00
Use new front-end based on Dashmin template
This commit is contained in:
parent
c118242c5b
commit
dbd7fafb34
4391 changed files with 228401 additions and 73494 deletions
34
UI/Middlewares/ClientReportingMiddleware.cs
Normal file
34
UI/Middlewares/ClientReportingMiddleware.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using MTWireGuard.Application;
|
||||
using MTWireGuard.Application.Repositories;
|
||||
|
||||
namespace MTWireGuard.Middlewares
|
||||
{
|
||||
public class ClientReportingMiddleware(RequestDelegate next)
|
||||
{
|
||||
public async Task Invoke(HttpContext context, IMikrotikRepository api)
|
||||
{
|
||||
if ((context.Request.Path.Value == "/" || context.Request.Path.Value == "/Index") && (!context.User.Identity.IsAuthenticated))
|
||||
{
|
||||
var ip = context.Connection.RemoteIpAddress;
|
||||
var users = await api.GetUsersAsync();
|
||||
var user = users.Find(x => x.Address == $"{ip}/32");
|
||||
if (user != null)
|
||||
{
|
||||
context.Session.Set("user", user);
|
||||
context.Response.Redirect("/Client", true);
|
||||
}
|
||||
}
|
||||
|
||||
await next(context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ClientReportingMiddlewareExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseClientReporting(this IApplicationBuilder builder)
|
||||
{
|
||||
return builder.UseMiddleware<ClientReportingMiddleware>();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue