From 4bc3fd2fbc52fb356865eae0af089ffcb31c8a42 Mon Sep 17 00:00:00 2001 From: MahanCh Date: Wed, 27 Aug 2025 16:34:55 +0330 Subject: [PATCH] feat: add employer authentication method and view model to registration workflow --- .../Employer/IEmployerApplication.cs | 61 ++++++++++++++++++- .../EmployerApplication.cs | 46 +++++++++++++- .../RegistrationWorkflowController.cs | 13 ++++ 3 files changed, 118 insertions(+), 2 deletions(-) diff --git a/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs b/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs index fc1406ea..8eb80975 100644 --- a/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs +++ b/CompanyManagment.App.Contracts/Employer/IEmployerApplication.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Threading.Tasks; using System.Transactions; using _0_Framework.Application; @@ -128,6 +129,64 @@ public interface IEmployerApplication #endregion Task CreateWorkflowRegistration(CreateEmployerWorkflowRegistration command); + Task> AuthenticateEmployer(string nationalCode, string dateOfBirth, string mobile); +} + +public class AuthenticateUserViewModel +{ + /// + /// نام + /// + public string FName { get; set; } + /// + /// نام خانوادگی + /// + public string LName { get; set; } + + /// + /// نام پدر + /// + public string FatherName { get; set; } + + /// + /// جنسیت + /// + public Gender Gender { get; set; } + + /// + /// کد ملی + /// + public string NationalCode { get; set; } + + /// + ///تاریخ تولد + /// + public DateTime DateOfBirth { get; set; } + + /// + /// سری شناسنامه + /// + public string IdNumberSeri { get; set; } + + /// + /// سریال شناسنامه + /// + public string IdNumberSerial { get; set; } + + + /// + /// شماره شناسنامه + /// + public string IdNumber { get; set; } + + + + /// + /// شماره همراه + /// + public string Phone { get; set; } + + } public class CreateEmployerWorkflowRegistration diff --git a/CompanyManagment.Application/EmployerApplication.cs b/CompanyManagment.Application/EmployerApplication.cs index 02cb2715..9cdd053c 100644 --- a/CompanyManagment.Application/EmployerApplication.cs +++ b/CompanyManagment.Application/EmployerApplication.cs @@ -5,6 +5,7 @@ using System.Security.AccessControl; using System.Threading.Tasks; using _0_Framework.Application; using _0_Framework.Application.Enums; +using _0_Framework.Application.UID; using _0_Framework.Exceptions; using Company.Domain.empolyerAgg; using Company.Domain.InstitutionContractAgg; @@ -12,6 +13,7 @@ using Company.Domain.WorkshopAgg; using CompanyManagment.App.Contracts.Checkout; using CompanyManagment.App.Contracts.Employer; using CompanyManagment.EFCore.Repository; +using Microsoft.Identity.Client; namespace CompanyManagment.Application; @@ -28,13 +30,15 @@ public class EmployerApplication : IEmployerApplication public bool registerIdIsOk = true; public bool nationalIdIsOk = true; private readonly IInstitutionContractRepository _institutionContractRepository; + private readonly IUidService _uidService; public EmployerApplication(IEmployerRepository employerRepository, IWorkshopRepository workshopRepository, - IInstitutionContractRepository institutionContractRepository) + IInstitutionContractRepository institutionContractRepository, IUidService uidService) { _EmployerRepository = employerRepository; _workshopRepository = workshopRepository; _institutionContractRepository = institutionContractRepository; + _uidService = uidService; } public OperationResult Active(long id) @@ -1316,6 +1320,46 @@ public class EmployerApplication : IEmployerApplication return operation.Succcedded(); } + public async Task> AuthenticateEmployer(string nationalCode, + string dateOfBirth, + string mobile) + { + var op = new OperationResult(); + + var dateOfBirthGr = dateOfBirth.ToGeorgianDateTime(); + + var isMachMobilAndNationalCode = await _uidService.IsMachPhoneWithNationalCode(nationalCode, mobile); + if (isMachMobilAndNationalCode == null) + return op.Failed("خطا در سرویس احراز هویت"); + if (!isMachMobilAndNationalCode.IsMatched) + return op.Failed("شماره همراه وارد شده با کد ملی مطابقت ندارد"); + var apiRespons = await _uidService.GetPersonalInfo(nationalCode, dateOfBirth); + + if (apiRespons == null) + return op.Failed("خطا در سرویس احراز هویت"); + if (apiRespons.ResponseContext.Status.Code != 0) + return op.Failed($"{apiRespons.ResponseContext.Status.Message}"); + + var idNumber = apiRespons.IdentificationInformation.ShenasnamehNumber == "0" + ? apiRespons.IdentificationInformation.NationalId + : apiRespons.IdentificationInformation.ShenasnamehNumber; + + var res = new AuthenticateUserViewModel() + { + DateOfBirth = dateOfBirthGr, + FatherName = apiRespons.BasicInformation.FatherName, + FName = apiRespons.BasicInformation.FirstName, + Gender = apiRespons.BasicInformation.GenderEnum, + IdNumber = apiRespons.IdentificationInformation.ShenasnamehNumber, + IdNumberSeri = apiRespons.IdentificationInformation.ShenasnameSeri, + IdNumberSerial = apiRespons.IdentificationInformation.ShenasnameSerial, + LName = apiRespons.BasicInformation.LastName, + NationalCode = nationalCode, + Phone = mobile, + }; + return op.Succcedded(res); + } + private async Task> CreateLegalEmployerRegistration( CreateLegalEmployerWorkflowRegistration command, long contractingPartyId) { diff --git a/ServiceHost/Areas/Admin/Controllers/RegistrationWorkflowController.cs b/ServiceHost/Areas/Admin/Controllers/RegistrationWorkflowController.cs index b3907b27..0e8317d8 100644 --- a/ServiceHost/Areas/Admin/Controllers/RegistrationWorkflowController.cs +++ b/ServiceHost/Areas/Admin/Controllers/RegistrationWorkflowController.cs @@ -58,5 +58,18 @@ namespace ServiceHost.Areas.Admin.Controllers var result = await _workshopApplication.CreateWorkshopWorkflowRegistration(command); return result; } + [HttpPost("auth-employer")] + public async Task>> AuthenticateEmployer(AuthenticateEmployerWorkflowRequest command) + { + var result = await _employerApplication.AuthenticateEmployer(command.NationalCode, command.DateOfBirth, command.Mobile); + return result; + } + } + + public class AuthenticateEmployerWorkflowRequest + { + public string NationalCode { get; set; } + public string DateOfBirth { get; set; } + public string Mobile { get; set; } } }