Merge branch 'newmain'
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
namespace FrontOffice.BFF.Application.UserCQ.Commands.SetPasswordForUser;
|
||||||
|
public record SetPasswordForUserCommand : IRequest<Unit>
|
||||||
|
{
|
||||||
|
//کلمه عبور فعلی
|
||||||
|
public string? CurrentPassword { get; init; }
|
||||||
|
//کلمه عبور
|
||||||
|
public string NewPassword { get; init; }
|
||||||
|
//تایید کلمه عبور
|
||||||
|
public string ConfirmPassword { get; init; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
namespace FrontOffice.BFF.Application.UserCQ.Commands.SetPasswordForUser;
|
||||||
|
public class SetPasswordForUserCommandHandler : IRequestHandler<SetPasswordForUserCommand, Unit>
|
||||||
|
{
|
||||||
|
private readonly IApplicationContractContext _context;
|
||||||
|
|
||||||
|
public SetPasswordForUserCommandHandler(IApplicationContractContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Unit> Handle(SetPasswordForUserCommand request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
//TODO: Implement your business logic
|
||||||
|
return new Unit();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace FrontOffice.BFF.Application.UserCQ.Commands.SetPasswordForUser;
|
||||||
|
public class SetPasswordForUserCommandValidator : AbstractValidator<SetPasswordForUserCommand>
|
||||||
|
{
|
||||||
|
public SetPasswordForUserCommandValidator()
|
||||||
|
{
|
||||||
|
RuleFor(model => model.NewPassword)
|
||||||
|
.NotEmpty();
|
||||||
|
RuleFor(model => model.ConfirmPassword)
|
||||||
|
.NotEmpty();
|
||||||
|
}
|
||||||
|
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||||
|
{
|
||||||
|
var result = await ValidateAsync(ValidationContext<SetPasswordForUserCommand>.CreateWithOptions((SetPasswordForUserCommand)model, x => x.IncludeProperties(propertyName)));
|
||||||
|
if (result.IsValid)
|
||||||
|
return Array.Empty<string>();
|
||||||
|
return result.Errors.Select(e => e.ErrorMessage);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
namespace FrontOffice.BFF.Application.UserCQ.Queries.AdminGetJwtToken;
|
||||||
|
public record AdminGetJwtTokenQuery : IRequest<AdminGetJwtTokenResponseDto>
|
||||||
|
{
|
||||||
|
//نام کاربری
|
||||||
|
public string Username { get; init; }
|
||||||
|
//کلمه عبور
|
||||||
|
public string Password { get; init; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
namespace FrontOffice.BFF.Application.UserCQ.Queries.AdminGetJwtToken;
|
||||||
|
public class AdminGetJwtTokenQueryHandler : IRequestHandler<AdminGetJwtTokenQuery, AdminGetJwtTokenResponseDto>
|
||||||
|
{
|
||||||
|
private readonly IApplicationContractContext _context;
|
||||||
|
|
||||||
|
public AdminGetJwtTokenQueryHandler(IApplicationContractContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<AdminGetJwtTokenResponseDto> Handle(AdminGetJwtTokenQuery request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
//TODO: Implement your business logic
|
||||||
|
return new AdminGetJwtTokenResponseDto();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace FrontOffice.BFF.Application.UserCQ.Queries.AdminGetJwtToken;
|
||||||
|
public class AdminGetJwtTokenQueryValidator : AbstractValidator<AdminGetJwtTokenQuery>
|
||||||
|
{
|
||||||
|
public AdminGetJwtTokenQueryValidator()
|
||||||
|
{
|
||||||
|
RuleFor(model => model.Username)
|
||||||
|
.NotEmpty();
|
||||||
|
RuleFor(model => model.Password)
|
||||||
|
.NotEmpty();
|
||||||
|
}
|
||||||
|
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||||
|
{
|
||||||
|
var result = await ValidateAsync(ValidationContext<AdminGetJwtTokenQuery>.CreateWithOptions((AdminGetJwtTokenQuery)model, x => x.IncludeProperties(propertyName)));
|
||||||
|
if (result.IsValid)
|
||||||
|
return Array.Empty<string>();
|
||||||
|
return result.Errors.Select(e => e.ErrorMessage);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace FrontOffice.BFF.Application.UserCQ.Queries.AdminGetJwtToken;
|
||||||
|
public class AdminGetJwtTokenResponseDto
|
||||||
|
{
|
||||||
|
//توکن
|
||||||
|
public string Token { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
using Grpc.Core.Interceptors;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using FrontOffice.BFF.Application.Common.Interfaces;
|
||||||
|
|
||||||
|
namespace FrontOffice.BFF.WebApi.Common.Behaviours;
|
||||||
|
|
||||||
|
public class LoggingBehaviour : Interceptor
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICurrentUserService _currentUserService;
|
||||||
|
public LoggingBehaviour(ILogger<LoggingBehaviour> logger, ICurrentUserService currentUserService)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_currentUserService = currentUserService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
|
||||||
|
TRequest request,
|
||||||
|
ServerCallContext context,
|
||||||
|
UnaryServerMethod<TRequest, TResponse> continuation)
|
||||||
|
{
|
||||||
|
var requestName = typeof(TRequest).Name;
|
||||||
|
var userId = _currentUserService.UserId ?? string.Empty;
|
||||||
|
_logger.LogInformation("gRPC Starting receiving call. Type/Method: {Type} / {Method} Request: {Name} {@UserId} {@Request}",
|
||||||
|
MethodType.Unary, context.Method , requestName, userId, request);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await continuation(request, context);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "gRPC Request: Unhandled Exception for Request {Name} {@Request}", requestName, request);
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
using Grpc.Core.Interceptors;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using FrontOffice.BFF.Application.Common.Interfaces;
|
||||||
|
|
||||||
|
namespace FrontOffice.BFF.WebApi.Common.Behaviours;
|
||||||
|
|
||||||
|
public class PerformanceBehaviour : Interceptor
|
||||||
|
{
|
||||||
|
private readonly Stopwatch _timer;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ICurrentUserService _currentUserService;
|
||||||
|
public PerformanceBehaviour(ILogger<PerformanceBehaviour> logger, ICurrentUserService currentUserService)
|
||||||
|
{
|
||||||
|
_timer = new Stopwatch();
|
||||||
|
_logger = logger;
|
||||||
|
_currentUserService = currentUserService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
|
||||||
|
TRequest request,
|
||||||
|
ServerCallContext context,
|
||||||
|
UnaryServerMethod<TRequest, TResponse> continuation)
|
||||||
|
{
|
||||||
|
_timer.Start();
|
||||||
|
|
||||||
|
var response = await continuation(request, context);
|
||||||
|
|
||||||
|
_timer.Stop();
|
||||||
|
|
||||||
|
var elapsedMilliseconds = _timer.ElapsedMilliseconds;
|
||||||
|
|
||||||
|
if (elapsedMilliseconds > 500)
|
||||||
|
{
|
||||||
|
var requestName = typeof(TRequest).Name;
|
||||||
|
var userId = _currentUserService.UserId ?? string.Empty;
|
||||||
|
|
||||||
|
_logger.LogWarning("gRPC Long Running Request: {Name} ({ElapsedMilliseconds} milliseconds) {@UserId} {@Request}",
|
||||||
|
requestName, elapsedMilliseconds, userId, request);
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using FrontOffice.BFF.User.Protobuf.Protos.User;
|
using FrontOffice.BFF.Protobuf.Protos.User;
|
||||||
using FrontOffice.BFF.WebApi.Common.Services;
|
using FrontOffice.BFF.WebApi.Common.Services;
|
||||||
using FrontOffice.BFF.Application.UserCQ.Commands.UpdateUser;
|
using FrontOffice.BFF.Application.UserCQ.Commands.UpdateUser;
|
||||||
using FrontOffice.BFF.Application.UserCQ.Commands.DeleteUser;
|
using FrontOffice.BFF.Application.UserCQ.Commands.DeleteUser;
|
||||||
@@ -6,6 +6,8 @@ using FrontOffice.BFF.Application.UserCQ.Queries.GetUser;
|
|||||||
using FrontOffice.BFF.Application.UserCQ.Queries.GetAllUserByFilter;
|
using FrontOffice.BFF.Application.UserCQ.Queries.GetAllUserByFilter;
|
||||||
using FrontOffice.BFF.Application.UserCQ.Commands.CreateNewOtpToken;
|
using FrontOffice.BFF.Application.UserCQ.Commands.CreateNewOtpToken;
|
||||||
using FrontOffice.BFF.Application.UserCQ.Commands.VerifyOtpToken;
|
using FrontOffice.BFF.Application.UserCQ.Commands.VerifyOtpToken;
|
||||||
|
using FrontOffice.BFF.Application.UserCQ.Queries.AdminGetJwtToken;
|
||||||
|
using FrontOffice.BFF.Application.UserCQ.Commands.SetPasswordForUser;
|
||||||
namespace FrontOffice.BFF.WebApi.Services;
|
namespace FrontOffice.BFF.WebApi.Services;
|
||||||
public class UserService : UserContract.UserContractBase
|
public class UserService : UserContract.UserContractBase
|
||||||
{
|
{
|
||||||
@@ -39,4 +41,12 @@ public class UserService : UserContract.UserContractBase
|
|||||||
{
|
{
|
||||||
return await _dispatchRequestToCQRS.Handle<VerifyOtpTokenRequest, VerifyOtpTokenCommand, VerifyOtpTokenResponse>(request, context);
|
return await _dispatchRequestToCQRS.Handle<VerifyOtpTokenRequest, VerifyOtpTokenCommand, VerifyOtpTokenResponse>(request, context);
|
||||||
}
|
}
|
||||||
|
public override async Task<AdminGetJwtTokenResponse> AdminGetJwtToken(AdminGetJwtTokenRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
return await _dispatchRequestToCQRS.Handle<AdminGetJwtTokenRequest, AdminGetJwtTokenQuery, AdminGetJwtTokenResponse>(request, context);
|
||||||
|
}
|
||||||
|
public override async Task<Empty> SetPasswordForUser(SetPasswordForUserRequest request, ServerCallContext context)
|
||||||
|
{
|
||||||
|
return await _dispatchRequestToCQRS.Handle<SetPasswordForUserRequest, SetPasswordForUserCommand>(request, context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,18 @@ service UserContract
|
|||||||
body: "*"
|
body: "*"
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
rpc AdminGetJwtToken(AdminGetJwtTokenRequest) returns (AdminGetJwtTokenResponse){
|
||||||
|
option (google.api.http) = {
|
||||||
|
get: "/AdminGetJwtToken"
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
rpc SetPasswordForUser(SetPasswordForUserRequest) returns (google.protobuf.Empty){
|
||||||
|
option (google.api.http) = {
|
||||||
|
post: "/SetPasswordForUser"
|
||||||
|
body: "*"
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
message UpdateUserRequest
|
message UpdateUserRequest
|
||||||
{
|
{
|
||||||
@@ -161,6 +173,21 @@ message VerifyOtpTokenResponse
|
|||||||
int32 remaining_attempts = 4;
|
int32 remaining_attempts = 4;
|
||||||
int32 remaining_seconds = 5;
|
int32 remaining_seconds = 5;
|
||||||
}
|
}
|
||||||
|
message AdminGetJwtTokenRequest
|
||||||
|
{
|
||||||
|
string username = 1;
|
||||||
|
string password = 2;
|
||||||
|
}
|
||||||
|
message AdminGetJwtTokenResponse
|
||||||
|
{
|
||||||
|
string token = 1;
|
||||||
|
}
|
||||||
|
message SetPasswordForUserRequest
|
||||||
|
{
|
||||||
|
google.protobuf.StringValue current_password = 1;
|
||||||
|
string new_password = 2;
|
||||||
|
string confirm_password = 3;
|
||||||
|
}
|
||||||
|
|
||||||
message PaginationState
|
message PaginationState
|
||||||
{
|
{
|
||||||
@@ -189,3 +216,4 @@ message DecimalValue
|
|||||||
|
|
||||||
sfixed32 nanos = 2;
|
sfixed32 nanos = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using FrontOfficeMicroservice.Protobuf.Protos.User;
|
||||||
|
namespace FrontOfficeMicroservice.Protobuf.Validator.User;
|
||||||
|
|
||||||
|
public class AdminGetJwtTokenRequestValidator : AbstractValidator<AdminGetJwtTokenRequest>
|
||||||
|
{
|
||||||
|
public AdminGetJwtTokenRequestValidator()
|
||||||
|
{
|
||||||
|
RuleFor(model => model.Username)
|
||||||
|
.NotEmpty();
|
||||||
|
RuleFor(model => model.Password)
|
||||||
|
.NotEmpty();
|
||||||
|
}
|
||||||
|
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||||
|
{
|
||||||
|
var result = await ValidateAsync(ValidationContext<AdminGetJwtTokenRequest>.CreateWithOptions((AdminGetJwtTokenRequest)model, x => x.IncludeProperties(propertyName)));
|
||||||
|
if (result.IsValid)
|
||||||
|
return Array.Empty<string>();
|
||||||
|
return result.Errors.Select(e => e.ErrorMessage);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using FrontOfficeMicroservice.Protobuf.Protos.User;
|
||||||
|
namespace FrontOfficeMicroservice.Protobuf.Validator.User;
|
||||||
|
|
||||||
|
public class SetPasswordForUserRequestValidator : AbstractValidator<SetPasswordForUserRequest>
|
||||||
|
{
|
||||||
|
public SetPasswordForUserRequestValidator()
|
||||||
|
{
|
||||||
|
RuleFor(model => model.NewPassword)
|
||||||
|
.NotEmpty();
|
||||||
|
RuleFor(model => model.ConfirmPassword)
|
||||||
|
.NotEmpty();
|
||||||
|
}
|
||||||
|
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
||||||
|
{
|
||||||
|
var result = await ValidateAsync(ValidationContext<SetPasswordForUserRequest>.CreateWithOptions((SetPasswordForUserRequest)model, x => x.IncludeProperties(propertyName)));
|
||||||
|
if (result.IsValid)
|
||||||
|
return Array.Empty<string>();
|
||||||
|
return result.Errors.Select(e => e.ErrorMessage);
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user