Van normális bejelenkezési ablak
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -8,11 +9,12 @@ namespace WorkFlowCheck.Web.Middleware
|
|||||||
public class JwtMiddleware
|
public class JwtMiddleware
|
||||||
{
|
{
|
||||||
private readonly RequestDelegate _next;
|
private readonly RequestDelegate _next;
|
||||||
private const string _secretKey = "super_secret_key";
|
public readonly IConfiguration _configuration;
|
||||||
|
|
||||||
public JwtMiddleware(RequestDelegate next)
|
public JwtMiddleware(RequestDelegate next,IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_next = next;
|
_next = next;
|
||||||
|
_configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Invoke(HttpContext context)
|
public async Task Invoke(HttpContext context)
|
||||||
@@ -26,12 +28,14 @@ namespace WorkFlowCheck.Web.Middleware
|
|||||||
|
|
||||||
await _next(context);
|
await _next(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ValidateToken(string token, out Claim[] claims)
|
private bool ValidateToken(string token, out Claim[] claims)
|
||||||
{
|
{
|
||||||
|
var jwtSettings = _configuration.GetSection("Jwt");
|
||||||
|
var secretKey = jwtSettings["SecretKey"];
|
||||||
|
|
||||||
claims = null;
|
claims = null;
|
||||||
var tokenHandler = new JwtSecurityTokenHandler();
|
var tokenHandler = new JwtSecurityTokenHandler();
|
||||||
var key = Encoding.UTF8.GetBytes(_secretKey);
|
var key = Encoding.UTF8.GetBytes(secretKey);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -52,5 +56,6 @@ namespace WorkFlowCheck.Web.Middleware
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,5 +94,6 @@ namespace WorkFlowCheck.Web.Middleware
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
@page
|
||||||
|
@model WorkFlowCheck.Web.Pages.Account.LoginModel
|
||||||
|
@{
|
||||||
|
Layout = null;
|
||||||
|
ViewData["Title"] = "Bejelentkezés";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="hu">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>@ViewData["Title"]</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body class="bg-light d-flex justify-content-center align-items-center vh-100">
|
||||||
|
<div class="card shadow p-4" style="min-width: 350px; max-width: 400px; width: 100%;">
|
||||||
|
<h2 class="mb-4 text-center">Bejelentkezés</h2>
|
||||||
|
|
||||||
|
@if (!string.IsNullOrEmpty(Model.ErrorMessage))
|
||||||
|
{
|
||||||
|
<div class="alert alert-danger">@Model.ErrorMessage</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="UserDTO.UserName" class="form-label">Felhasználónév</label>
|
||||||
|
<input asp-for="UserDTO.UserName" class="form-control" />
|
||||||
|
<span asp-validation-for="UserDTO.UserName" class="text-danger small"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label asp-for="UserDTO.Password" class="form-label">Jelszó</label>
|
||||||
|
<input asp-for="UserDTO.Password" type="password" class="form-control" />
|
||||||
|
<span asp-validation-for="UserDTO.Password" class="text-danger small"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-grid">
|
||||||
|
<button type="submit" class="btn btn-primary">Bejelentkezés</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<partial name="_ValidationScriptsPartial" />
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
|
using WorkFlowCheck.Common.DTO;
|
||||||
|
using WorkFlowCheck.Web.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.Web.Pages.Account
|
||||||
|
{
|
||||||
|
public class LoginModel : PageModel
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly IUserService _userService;
|
||||||
|
[BindProperty]
|
||||||
|
public UserDTO UserDTO { get; set; }
|
||||||
|
public string ErrorMessage { get; set; }
|
||||||
|
|
||||||
|
public LoginModel(IUserService userService)
|
||||||
|
{
|
||||||
|
_userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnGet()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
using WorkFlowCheck.Common.DTO;
|
using WorkFlowCheck.Common.DTO;
|
||||||
@@ -5,6 +6,7 @@ using WorkFlowCheck.Web.Services.Interfaces;
|
|||||||
|
|
||||||
namespace WorkFlowCheck.Web.Pages.BaseStock.CheckPoints
|
namespace WorkFlowCheck.Web.Pages.BaseStock.CheckPoints
|
||||||
{
|
{
|
||||||
|
[Authorize]
|
||||||
public class CheckPointsPageModel : PageModel
|
public class CheckPointsPageModel : PageModel
|
||||||
{
|
{
|
||||||
private readonly ILogger<IndexModel> _logger;
|
private readonly ILogger<IndexModel> _logger;
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ builder.Services.AddMemoryCache();
|
|||||||
builder.Services.AddHttpContextAccessor();
|
builder.Services.AddHttpContextAccessor();
|
||||||
builder.Services.AddHttpClient();
|
builder.Services.AddHttpClient();
|
||||||
|
|
||||||
|
builder.Services.AddScoped<IUserService, UserService>();
|
||||||
builder.Services.AddScoped<IBaseStockService, BaseStockService>();
|
builder.Services.AddScoped<IBaseStockService, BaseStockService>();
|
||||||
|
|
||||||
builder.Host.UseSerilog();
|
builder.Host.UseSerilog();
|
||||||
@@ -76,7 +77,17 @@ app.MapPost("/login", async ([FromBody] UserDTO userDTO, JwtService jwtService,
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.MapGet("/secure-data", [Authorize] () => "This is protected data");
|
app.MapGet("/secure-data", [Authorize] () => "This is protected data");
|
||||||
|
app.Use(async (context, next) =>
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(context.User?.Identity?.Name) &&
|
||||||
|
context.Request.Path == "/")
|
||||||
|
{
|
||||||
|
context.Response.Redirect("/Account/Login");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await next();
|
||||||
|
});
|
||||||
app.MapRazorPages();
|
app.MapRazorPages();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace WorkFlowCheck.Web.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface IUserService
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
using WorkFlowCheck.Web.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.Web.Services
|
||||||
|
{
|
||||||
|
public class UserService : BaseService, IUserService
|
||||||
|
{
|
||||||
|
public UserService(HttpClient httpClient, IConfiguration configuration) : base(httpClient, configuration)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user