Na most egy validator is beköszönt
This commit is contained in:
@@ -93,7 +93,7 @@ namespace WorkFlowCheck.API.Controllers
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
[HttpPost("Authenticate")]
|
[HttpPost("Authenticate")]
|
||||||
public async Task<ApiResponseDTO<UserDTO>> Authenticate([FromBody] UserDTO userSimpleDTO)
|
public async Task<ApiResponseDTO<UserDTO>> Authenticate([FromBody] UserSimpleDTO userSimpleDTO)
|
||||||
{
|
{
|
||||||
var retVal = new ApiResponseDTO<UserDTO>()
|
var retVal = new ApiResponseDTO<UserDTO>()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ namespace WorkFlowCheck.Common.DTO
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Email { get; set; } = null!;
|
public string Email { get; set; } = null!;
|
||||||
|
[Required(ErrorMessage = "Az utónév kötelező.")]
|
||||||
public string FirstName { get; set; } = null!;
|
public string FirstName { get; set; } = null!;
|
||||||
|
[Required(ErrorMessage = "Az vezetéknév kötelező.")]
|
||||||
public string LastName { get; set; } = null!;
|
public string LastName { get; set; } = null!;
|
||||||
|
[Required(ErrorMessage = "A felhasználónév kötelező.")]
|
||||||
public string UserName { get;set; } = null!;
|
public string UserName { get;set; } = null!;
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
public string JwtToken { get; set; } = null!;
|
public string JwtToken { get; set; } = null!;
|
||||||
@@ -16,7 +19,9 @@ namespace WorkFlowCheck.Common.DTO
|
|||||||
|
|
||||||
public class UserSimpleDTO
|
public class UserSimpleDTO
|
||||||
{
|
{
|
||||||
|
[Required(ErrorMessage = "A felhasználónév kötelező.")]
|
||||||
public string UserName { get; set; } = null!;
|
public string UserName { get; set; } = null!;
|
||||||
|
[Required(ErrorMessage = "A jelszó megadása kötelező.")]
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/jquery-validation@1.19.5/dist/jquery.validate.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/jquery-validation-unobtrusive@4.0.0/dist/jquery.validate.unobtrusive.min.js"></script>
|
||||||
|
|
||||||
<partial name="_ValidationScriptsPartial" />
|
<partial name="_ValidationScriptsPartial" />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="hu">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
|||||||
@@ -44,8 +44,8 @@
|
|||||||
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
||||||
var formData = getFormAsNestedObject('#UserForm');
|
var formData = getFormAsNestedObject('#UserForm');
|
||||||
const $form = $('#UserForm');
|
const $form = $('#UserForm');
|
||||||
console.log($form);
|
|
||||||
if ($form[0].checkValidity())
|
if ($form.valid())
|
||||||
{
|
{
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: $('#UserEditPostUrl').val(),
|
url: $('#UserEditPostUrl').val(),
|
||||||
@@ -78,6 +78,22 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
const $form = $("#userForm");
|
||||||
|
|
||||||
|
$form.validate({
|
||||||
|
errorClass: "text-danger small",
|
||||||
|
errorPlacement: function (error, element) {
|
||||||
|
error.appendTo(element.parent());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// $form.on("submit", function (e) {
|
||||||
|
// if (!$form.valid()) {
|
||||||
|
// e.preventDefault(); // Ne küldje be, ha van hiba
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ using WorkFlowCheck.Common.DTO;
|
|||||||
using WorkFlowCheck.Web.Middleware;
|
using WorkFlowCheck.Web.Middleware;
|
||||||
using WorkFlowCheck.Web.Services;
|
using WorkFlowCheck.Web.Services;
|
||||||
using WorkFlowCheck.Web.Services.Interfaces;
|
using WorkFlowCheck.Web.Services.Interfaces;
|
||||||
|
using WorkFlowCheck.Web.Validators;
|
||||||
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@@ -50,6 +51,8 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.Services.AddFluentValidationSetup();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
app.UseMiddleware<JwtMiddleware>();
|
app.UseMiddleware<JwtMiddleware>();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
using FluentValidation.AspNetCore;
|
||||||
|
using FluentValidation;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.Web.Validators
|
||||||
|
{
|
||||||
|
public static class FluentValidationConfig
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddFluentValidationSetup(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddFluentValidationAutoValidation();
|
||||||
|
services.AddFluentValidationClientsideAdapters(); // ha valaha szeretnél client-side-t is
|
||||||
|
|
||||||
|
// Itt regisztrálod a validátorokat – automatikusan az adott assembly-ből
|
||||||
|
services.AddValidatorsFromAssembly(typeof(FluentValidationConfig).Assembly);
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using WorkFlowCheck.Common.DTO;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.Web.Validators
|
||||||
|
{
|
||||||
|
public class UserDTOValidator : AbstractValidator<UserDTO>
|
||||||
|
{
|
||||||
|
public UserDTOValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.UserName)
|
||||||
|
.NotEmpty().WithMessage("A felhasználónév kötelező.");
|
||||||
|
|
||||||
|
RuleFor(x => x.FirstName)
|
||||||
|
.NotEmpty().WithMessage("A keresztnév kötelező.");
|
||||||
|
|
||||||
|
RuleFor(x => x.LastName)
|
||||||
|
.NotEmpty().WithMessage("A vezetéknév kötelező.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,8 @@
|
|||||||
<Content Remove="C:\Users\ivanszabo\.nuget\packages\datatables.net\2.2.2\contentFiles\any\any\wwwroot\js\dataTables.min.js" />
|
<Content Remove="C:\Users\ivanszabo\.nuget\packages\datatables.net\2.2.2\contentFiles\any\any\wwwroot\js\dataTables.min.js" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="FluentValidation" Version="11.11.0" />
|
||||||
|
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
|
||||||
<PackageReference Include="jquery" Version="3.7.1" />
|
<PackageReference Include="jquery" Version="3.7.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.14" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.14" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.11" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.11" />
|
||||||
|
|||||||
Reference in New Issue
Block a user