diff --git a/AccountManagement.Application.Contracts/Account/IAccountApplication.cs b/AccountManagement.Application.Contracts/Account/IAccountApplication.cs index 3c31d726..ac21411b 100644 --- a/AccountManagement.Application.Contracts/Account/IAccountApplication.cs +++ b/AccountManagement.Application.Contracts/Account/IAccountApplication.cs @@ -66,4 +66,11 @@ public interface IAccountApplication public bool CheckExistClientAccount(string userName); List GetAdminAccountsNew(); + void CameraLogin(CameraLoginRequest request); +} + +public class CameraLoginRequest +{ + public string UserName { get; set; } + public string Password { get; set; } } \ No newline at end of file diff --git a/AccountManagement.Application/AccountApplication.cs b/AccountManagement.Application/AccountApplication.cs index 4204be40..74880b13 100644 --- a/AccountManagement.Application/AccountApplication.cs +++ b/AccountManagement.Application/AccountApplication.cs @@ -18,6 +18,7 @@ using Microsoft.AspNetCore.Mvc.Rendering; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; using Company.Domain.WorkshopAgg; using System.Security.Claims; +using _0_Framework.Exceptions; using AccountManagement.Domain.PositionAgg; using AccountManagement.Domain.SubAccountAgg; using AccountManagement.Domain.SubAccountPermissionSubtitle1Agg; @@ -803,4 +804,29 @@ public class AccountApplication : IAccountApplication { return _accountRepository.GetAdminAccountsNew(); } + + public void CameraLogin(CameraLoginRequest request) + { + var cameraAccount = _cameraAccountRepository.GetBy(request.UserName); + + if (cameraAccount == null) + { + throw new BadRequestException(ApplicationMessages.WrongUserPass); + } + + (bool Verified, bool NeedUpgrade) result = _passwordHasher.Check(cameraAccount.Password, request.Password); + + if (!result.Verified) + throw new BadRequestException(ApplicationMessages.WrongUserPass); + + var mobile = string.IsNullOrWhiteSpace(cameraAccount.Mobile) ? " " : cameraAccount.Mobile; + + var authViewModel = new CameraAuthViewModel(cameraAccount.id, cameraAccount.WorkshopId, + cameraAccount.Username, mobile, cameraAccount.WorkshopName, cameraAccount.AccountId, + cameraAccount.IsActiveSting); + if (cameraAccount.IsActiveSting != "true") + throw new BadRequestException(ApplicationMessages.WrongUserPass); + + _authHelper.CameraSignIn(authViewModel); + } } \ No newline at end of file diff --git a/ServiceHost/Areas/Camera/Controllers/CameraController.cs b/ServiceHost/Areas/Camera/Controllers/CameraController.cs new file mode 100644 index 00000000..7db5cf13 --- /dev/null +++ b/ServiceHost/Areas/Camera/Controllers/CameraController.cs @@ -0,0 +1,256 @@ +using ServiceHost.BaseControllers; +using System; +using System.IO; +using System.Linq; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Hosting; +using _0_Framework.Application; +using AccountManagement.Application.Contracts.Account; +using AccountManagement.Application.Contracts.CameraAccount; +using AccountManagement.Domain.TaskAgg; +using CompanyManagment.App.Contracts.PersonnleCode; +using CompanyManagment.App.Contracts.RollCall; +using CompanyManagment.App.Contracts.RollCallEmployee; +using CompanyManagment.App.Contracts.RollCallService; +using CompanyManagment.App.Contracts.Employee; +using Microsoft.AspNetCore.Authorization; + +namespace ServiceHost.Areas.Camera.Controllers; + +public class CameraController:CameraBaseController +{ + private readonly IWebHostEnvironment _webHostEnvironment; + private readonly IConfiguration _configuration; + private readonly IEmployeeApplication _employeeApplication; + private readonly IRollCallApplication _rollCallApplication; + private readonly IRollCallServiceApplication _rollCallServiceApplication; + private readonly IRollCallEmployeeApplication _rollCallEmployeeApplication; + private readonly IAuthHelper _authHelper; + private readonly IPersonnelCodeApplication _personnelCodeApplication; + private readonly IAccountApplication _accountApplication; + private readonly IPasswordHasher _passwordHasher; + private readonly ICameraAccountApplication _cameraAccountApplication; + + public CameraController(IWebHostEnvironment webHostEnvironment, + IConfiguration configuration, + IEmployeeApplication employeeApplication, + IRollCallApplication rollCallApplication, + IAuthHelper authHelper, + IRollCallServiceApplication rollCallServiceApplication, + IRollCallEmployeeApplication rollCallEmployeeApplication, + IPersonnelCodeApplication personnelCodeApplication, + IAccountApplication accountApplication, + IPasswordHasher passwordHasher, + ICameraAccountApplication cameraAccountApplication) + { + _webHostEnvironment = webHostEnvironment; + _configuration = configuration; + _employeeApplication = employeeApplication; + _rollCallApplication = rollCallApplication; + _authHelper = authHelper; + _rollCallServiceApplication = rollCallServiceApplication; + _rollCallEmployeeApplication = rollCallEmployeeApplication; + _personnelCodeApplication = personnelCodeApplication; + _accountApplication = accountApplication; + _passwordHasher = passwordHasher; + _cameraAccountApplication = cameraAccountApplication; + } + + [HttpPost("login")] + [AllowAnonymous] + public IActionResult CameraLogin([FromBody]CameraLoginRequest request) + { + _accountApplication.CameraLogin(request); + return Ok(); + } + + + [HttpGet("SendPersonelCodeToGetEmployeeId")] + public IActionResult SendPersonelCodeToGetEmployeeId(long personelCode, long workshopId) + { + long employeeId = _personnelCodeApplication.GetEmployeeIdByPersonelCode(personelCode, workshopId); + + if (employeeId == 0) + { + return new JsonResult(new + { + isSuccess = false, + message = "کد پرسنلی یافت نشد", + }); + } + + bool rollcallEmployee = _rollCallEmployeeApplication.IsEmployeeRollCallActive(employeeId, workshopId); + if (!rollcallEmployee) + { + return new JsonResult(new + { + isSuccess = false, + message = "پرسنل مورد نظر غیر فعال است", + + }); + } + + var repeatStatus = _rollCallApplication.CheckRepeat(employeeId, workshopId); + switch (repeatStatus) + { + case "IncomRegistred-InvalidOut": + return new JsonResult(new + { + isSuccess = false, + message = "شما به تازگی ثبت ورود نموده اید ,تا 2 دقیقه نمی توانید ثبت خروج نمایید", + }); + case "outRegistred-InvalidIncom": + return new JsonResult(new + { + isSuccess = false, + message = "شما به تازگی ثبت خروج نموده اید تا 2 دقیقه نمی توانید ثبت ورود نمایید", + }); + } + + return new JsonResult(new + { + isSuccess = true, + message = "", + personId = $"{employeeId}", + + }); + } + + [HttpGet("EmployeeFlag")] + public IActionResult EmployeeFlag(long employeeId, long workshopId) + { + var employee = _rollCallEmployeeApplication.GetByEmployeeIdAndWorkshopId(employeeId, workshopId); + var employeeFullName = employee?.EmployeeFullName ?? string.Empty; + var flagId = _rollCallApplication.Flag(employeeId, workshopId); + + return new JsonResult(new + { + employeeName = employeeFullName, + flag = flagId + + }); + + } + + [HttpGet("Out")] + public IActionResult Out(long flagId) + { + var res = _rollCallApplication.Edit(flagId); + if (res.IsSuccedded) + { + return new JsonResult(new + { + isSuccess = true, + }); + } + else + { + return new JsonResult(new + { + isSuccess = false, + }); + } + } + + [HttpGet("InCom")] + public IActionResult InCom(long employeeId, long workshopId) + { + var now = DateTime.Now; + var command = new CreateRollCall() + { + WorkshopId = workshopId, + EmployeeId = employeeId, + StartDate = now, + + }; + var res = _rollCallApplication.Create(command); + if (res.IsSuccedded) + { + return new JsonResult(new + { + isSuccess = true, + }); + } + else + { + return new JsonResult(new + { + isSuccess = false, + }); + } + + } + + [HttpGet("ShowPicture")] + public IActionResult ShowPicture(int index, long workshopId, long label) + { + var filePath = Path.Combine(_webHostEnvironment.ContentRootPath, "Faces", workshopId.ToString(), label.ToString(), $"{index}.jpg"); + + if (!System.IO.File.Exists(filePath)) + { + return NotFound(); + } + + var contentType = "image/jpeg"; + return PhysicalFile(filePath, contentType); + } + + [HttpGet("PersonnelWorkshopAjax")] + public IActionResult PersonnelWorkshopAjax() + { + var cameraAccount = _authHelper.CameraAccountInfo(); + if (cameraAccount.WorkshopId > 0) + { + var result = _rollCallEmployeeApplication.GetActivePersonnelByWorkshopId(cameraAccount.WorkshopId); + if (cameraAccount.WorkshopId == 170) + result = result.Select(x => + { + if (x.PersonelCode == 477) + x.EmployeeLName = "نوزاد"; + return x; + }).ToList(); + + return new JsonResult(result); + } + else + { + return new JsonResult(new + { + isSuccess = false, + message = "کارگاه ای یافت نشد!" + }); + } + } + + [HttpPost("CheckPassword")] + public IActionResult CheckPassword([FromForm] string password) + { + var cameraAccount = _authHelper.CameraAccountInfo(); + var cameraPassword = _cameraAccountApplication.GetDetails(cameraAccount.Id).Password; + (bool Verified, bool NeedUpgrade) result = _passwordHasher.Check(cameraPassword, password); + if (result.Verified) + { + _accountApplication.Logout(); + return new JsonResult(new + { + isSuccess = true, + + }); + } + + return new JsonResult(new + { + isSuccess = false, + errorMessage = "گذرواژه اشتباه است", + }); + + } + + [HttpGet("Logout")] + public IActionResult Logout() + { + _accountApplication.Logout(); + return new JsonResult(new { isSuccess = true }); + } + +} \ No newline at end of file diff --git a/ServiceHost/BaseControllers/CameraBaseController.cs b/ServiceHost/BaseControllers/CameraBaseController.cs index 44a601d6..50a2f466 100644 --- a/ServiceHost/BaseControllers/CameraBaseController.cs +++ b/ServiceHost/BaseControllers/CameraBaseController.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc; namespace ServiceHost.BaseControllers; -//[ApiExplorerSettings(GroupName = "Camera")] +[ApiExplorerSettings(GroupName = "Camera")] [Authorize(Policy = "CameraArea")] [Area("Camera")] [Route("api/[area]/[controller]")] diff --git a/ServiceHost/Properties/launchSettings.json b/ServiceHost/Properties/launchSettings.json index 788962e4..81186f13 100644 --- a/ServiceHost/Properties/launchSettings.json +++ b/ServiceHost/Properties/launchSettings.json @@ -19,7 +19,7 @@ "sqlDebugging": true, "dotnetRunMessages": "true", "nativeDebugging": true, - "applicationUrl": "https://localhost:5004;http://localhost:5003;", + "applicationUrl": "https://localhost:5004;http://localhost:5003;https://192.168.162.36:8080;http://192.168.162.36:8081", "jsWebView2Debugging": false, "hotReloadEnabled": true },