From 5f422bc11f73c05b6e74bd7611dc5dff56e8b35d Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Mon, 15 Apr 2024 17:16:17 +0330 Subject: [PATCH] ver --- Back/Back.csproj | 2 +- Back/Controllers/VerificationController.cs | 38 +++++ Back/Program.cs | 1 + Back/Services/ServValidatinMsg.cs | 4 +- Back/Validations/GetVerificationValidation.cs | 26 ++++ TaxPayerFull/Pages/Verification.razor | 132 +++++++++++------- TaxPayerFull/Program.cs | 4 +- 7 files changed, 148 insertions(+), 59 deletions(-) create mode 100644 Back/Controllers/VerificationController.cs create mode 100644 Back/Validations/GetVerificationValidation.cs diff --git a/Back/Back.csproj b/Back/Back.csproj index ac6c0cd..38e11a4 100644 --- a/Back/Back.csproj +++ b/Back/Back.csproj @@ -34,7 +34,7 @@ - ..\..\Dlls\Service.dll + ..\..\..\LocalGit\TaxPayerTools\Service\bin\Debug\Service.dll diff --git a/Back/Controllers/VerificationController.cs b/Back/Controllers/VerificationController.cs new file mode 100644 index 0000000..c05bc14 --- /dev/null +++ b/Back/Controllers/VerificationController.cs @@ -0,0 +1,38 @@ +using Back.Data.Models; +using Back.Services; +using Back.Validations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Shared.DTOs; + +namespace Back.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class VerificationController : ControllerBase + { + //private readonly ServValidatinMsg _servValidatinMsg; + private readonly GetVerificationValidation _getVerificationValidation; + public VerificationController(/*ServValidatinMsg servValidatinMsg, */GetVerificationValidation getVerificationValidation) + { + //_servValidatinMsg = servValidatinMsg; + _getVerificationValidation = getVerificationValidation; + + } + [HttpGet("GetVerification/{ID}")] + [AllowAnonymous] + public async Task> GetVerification(int ID) + { + var resultValidationmodel = await _getVerificationValidation.ValidateAsync(ID); + if (!resultValidationmodel.IsValid) + return BadRequest(resultValidationmodel.Errors.Select(s => s.ErrorMessage).ToList()); + + return Ok(new VerificationCodeDto { + prm= _getVerificationValidation.verificationCode.prm, + Type= _getVerificationValidation.verificationCode.Type, + val= _getVerificationValidation.verificationCode.val + }); + } + } +} diff --git a/Back/Program.cs b/Back/Program.cs index bd44c01..a2bd173 100644 --- a/Back/Program.cs +++ b/Back/Program.cs @@ -23,6 +23,7 @@ builder.Services.AddScoped (); builder.Services.AddScoped(); builder.Services.AddScoped (); builder.Services.AddScoped < ServValidatinMsg>(); +builder.Services.AddScoped (); string origins = "OriginTaxPayer"; builder.Services.AddCors(options => { diff --git a/Back/Services/ServValidatinMsg.cs b/Back/Services/ServValidatinMsg.cs index 87a235e..c53b5a0 100644 --- a/Back/Services/ServValidatinMsg.cs +++ b/Back/Services/ServValidatinMsg.cs @@ -16,14 +16,14 @@ namespace Back.Services return await _verificationCodeRepo.Get(w => w.prm == Prm).FirstOrDefaultAsync(); } - public async Task GetRegistrationCode(int ID) + public async Task GetVerificationCode(int ID) { return await _verificationCodeRepo.Get(w => w.ID == ID).FirstOrDefaultAsync(); } public async Task GenerateCode(VerificationCode code) { code.Code = Random.Shared.Next(1000, 9000); - while (await GetRegistrationCode(code.ID) != null) + while (await GetVerificationCode(code.ID) != null) code.Code = Random.Shared.Next(1000, 9000); diff --git a/Back/Validations/GetVerificationValidation.cs b/Back/Validations/GetVerificationValidation.cs new file mode 100644 index 0000000..1ec7526 --- /dev/null +++ b/Back/Validations/GetVerificationValidation.cs @@ -0,0 +1,26 @@ +using Back.Data.Models; +using Back.Services; +using FluentValidation; +using Shared.DTOs; +using System; + +namespace Back.Validations +{ + public class GetVerificationValidation : AbstractValidator + { + public VerificationCode verificationCode { get; set; } + public GetVerificationValidation(ServValidatinMsg _servValidatinMsg) + { + CascadeMode = CascadeMode.Stop; + RuleFor(model => model) + .Custom((model, context) => { + verificationCode= _servValidatinMsg.GetVerificationCode(model).Result; + if (verificationCode==null) + context.AddFailure("کد یافت نشد"); + + + }); + + } + } +} diff --git a/TaxPayerFull/Pages/Verification.razor b/TaxPayerFull/Pages/Verification.razor index 99d514c..ec6a725 100644 --- a/TaxPayerFull/Pages/Verification.razor +++ b/TaxPayerFull/Pages/Verification.razor @@ -1,63 +1,75 @@ @using Shared.DTOs @page "/Verification/{ID:int}" - +@inject HttpClient _hc +@inject NavigationManager nav +احراز هویت
-
-
-
-
- - - - احراز هویت - - @*
-
کد ارسال شده به شماره @Model.Mobile
-
*@ + + + -@* -
-
- - -
- -
*@ - @* - ارسال مجدد - *@ -
- -
- - -
-
-
-
- -
@code { @@ -70,6 +82,18 @@ public VerificationCodeDto Model { get; set; } protected override async Task OnParametersSetAsync() { + var request = await _hc.GetAsync($"Verification/GetVerification/{ID}"); + if (request.IsSuccessStatusCode) + { + + Model = await request.Content.ReadFromJsonAsync(); + // nav.NavigateTo($"Verification/{res}"); + } + else + { + nav.NavigateTo($"/"); + } + await base.OnParametersSetAsync(); } } diff --git a/TaxPayerFull/Program.cs b/TaxPayerFull/Program.cs index 44acca9..27ef188 100644 --- a/TaxPayerFull/Program.cs +++ b/TaxPayerFull/Program.cs @@ -7,9 +7,9 @@ var builder = WebAssemblyHostBuilder.CreateDefault(args); builder.RootComponents.Add("#app"); builder.RootComponents.Add("head::after"); -builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") }); +//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("https://localhost:7075/api/") }); -//builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") }); +builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri("http://localhost:5271/api/") }); CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("fa-Ir");