From c30c460a686e81bdb6bcc9ff7f7b9c62bbd9c1e8 Mon Sep 17 00:00:00 2001 From: MahanCh Date: Wed, 2 Jul 2025 12:03:25 +0330 Subject: [PATCH] feature : add login controller and get detail profile Add user profile and permissions handling - Updated `AuthHelper` to deserialize permissions from claims. - Introduced `GetDates` method in `GeneralController` for date info. - Created `LoginController` with `GetProfile` method to return user profile details. --- 0_Framework/Application/AuthHelper.cs | 4 +- ServiceHost/Controllers/GeneralController.cs | 11 +++++ ServiceHost/Controllers/LoginController.cs | 43 ++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 ServiceHost/Controllers/LoginController.cs diff --git a/0_Framework/Application/AuthHelper.cs b/0_Framework/Application/AuthHelper.cs index bb94f1b2..453c6cb8 100644 --- a/0_Framework/Application/AuthHelper.cs +++ b/0_Framework/Application/AuthHelper.cs @@ -40,7 +40,9 @@ public class AuthHelper : IAuthHelper result.Mobile = claims.FirstOrDefault(x => x is { Type: "Mobile" }).Value; result.SubAccountId = long.Parse(claims.FirstOrDefault(x => x.Type == "SubAccountId").Value); result.WorkshopName = claims.FirstOrDefault(x => x is { Type: "WorkshopName" })?.Value; - return result; + result.Permissions = Tools.DeserializeFromBsonList(claims.FirstOrDefault(x => x is { Type: "permissions" })?.Value); + + return result; } public List GetPermissions() diff --git a/ServiceHost/Controllers/GeneralController.cs b/ServiceHost/Controllers/GeneralController.cs index 723c60a6..e51ff60a 100644 --- a/ServiceHost/Controllers/GeneralController.cs +++ b/ServiceHost/Controllers/GeneralController.cs @@ -1,4 +1,7 @@ using System.Globalization; +using _0_Framework.Application; +using CompanyManagment.EFCore.Migrations; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using ServiceHost.BaseControllers; @@ -6,6 +9,12 @@ namespace ServiceHost.Controllers; public class GeneralController:GeneralBaseController { + + + /// + /// نمایش اطلاعات عمومی مانند تاریخ ها و سال ها + /// + /// [HttpGet("Dates")] public IActionResult GetDates() { @@ -20,4 +29,6 @@ public class GeneralController:GeneralBaseController years,months,currentDate }); } + + } \ No newline at end of file diff --git a/ServiceHost/Controllers/LoginController.cs b/ServiceHost/Controllers/LoginController.cs new file mode 100644 index 00000000..ec8c39ca --- /dev/null +++ b/ServiceHost/Controllers/LoginController.cs @@ -0,0 +1,43 @@ +using _0_Framework.Application; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Controllers; +public record GetProfileDetails(long Id, string Fullname,UserType UserType ,string Mobile, string RoleName,ListPermissions,long? PositionValue); +public class LoginController : GeneralBaseController +{ + + private readonly IAuthHelper _authHelper; + + public LoginController(IAuthHelper authHelper) + { + _authHelper = authHelper; + } + /// + /// جزئیات پروفایل کاربر جاری را برمی گرداند + /// + /// + [HttpGet("Profile")] + public ActionResult GetProfile() + { + if (!_authHelper.IsAuthenticated()) + return Unauthorized(); + var data = _authHelper.CurrentAccountInfo(); + if (data == null) + { + return NotFound("کاربر یافت نشد"); + } + var details = new GetProfileDetails( + data.Id, + data.Fullname, + _authHelper.GetUserTypeWithId().userType, + data.Mobile, + data.RoleName, + data.Permissions, + data.PositionValue + ); + return details; + } +} +