mirror of
https://github.com/techgarage-ir/MTWireGuard.git
synced 2025-08-25 11:55:20 +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
39
UI/Pages/Client.cshtml.cs
Normal file
39
UI/Pages/Client.cshtml.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using MTWireGuard.Application.Repositories;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using MTWireGuard.Application.Models.Requests;
|
||||
using MTWireGuard.Application.Models.Mikrotik;
|
||||
using MTWireGuard.Application;
|
||||
|
||||
namespace MTWireGuard.Pages
|
||||
{
|
||||
[AllowAnonymous]
|
||||
[IgnoreAntiforgeryToken(Order = 1001)]
|
||||
public class ClientModel(IMikrotikRepository api) : PageModel
|
||||
{
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
var user = HttpContext.Session.Get<WGPeerViewModel>("user");
|
||||
if (user == null)
|
||||
{
|
||||
return RedirectPermanent("/Login");
|
||||
}
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync([FromBody] LoginRequest login)
|
||||
{
|
||||
var users = await api.GetUsersAsync();
|
||||
var user = users.Find(x => x.Name.Equals(login.Username, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (user != null)
|
||||
{
|
||||
HttpContext.Session.Set("user", user);
|
||||
return Page();
|
||||
}
|
||||
return Unauthorized();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue