From 5ebcbcf774e5cac5d31bd5442e312358b0659c13 Mon Sep 17 00:00:00 2001 From: MahanCh Date: Tue, 15 Jul 2025 16:00:49 +0330 Subject: [PATCH] add get profileMethod --- .../Admin}/Controllers/LoginController.cs | 25 ++++++----- .../Client/Controllers/LoginController.cs | 44 +++++++++++++++++++ ServiceHost/ServiceHost.csproj | 1 - 3 files changed, 59 insertions(+), 11 deletions(-) rename ServiceHost/{ => Areas/Admin}/Controllers/LoginController.cs (57%) create mode 100644 ServiceHost/Areas/Client/Controllers/LoginController.cs diff --git a/ServiceHost/Controllers/LoginController.cs b/ServiceHost/Areas/Admin/Controllers/LoginController.cs similarity index 57% rename from ServiceHost/Controllers/LoginController.cs rename to ServiceHost/Areas/Admin/Controllers/LoginController.cs index ec8c39ca..9ef8f89f 100644 --- a/ServiceHost/Controllers/LoginController.cs +++ b/ServiceHost/Areas/Admin/Controllers/LoginController.cs @@ -1,13 +1,15 @@ using _0_Framework.Application; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using ServiceHost.BaseControllers; +using ServiceHost.Controllers; -namespace ServiceHost.Controllers; -public record GetProfileDetails(long Id, string Fullname,UserType UserType ,string Mobile, string RoleName,ListPermissions,long? PositionValue); -public class LoginController : GeneralBaseController +namespace ServiceHost.Areas.Admin.Controllers; +public record GetAdminProfileDetails(long Id, string Fullname, string Mobile, string RoleName, List Permissions, long? PositionValue); + +public class LoginController:AdminBaseController { + private readonly IAuthHelper _authHelper; public LoginController(IAuthHelper authHelper) @@ -15,23 +17,27 @@ public class LoginController : GeneralBaseController _authHelper = authHelper; } /// - /// جزئیات پروفایل کاربر جاری را برمی گرداند + /// جزئیات پروفایل کاربر ادمین را برمی گرداند /// /// [HttpGet("Profile")] - public ActionResult GetProfile() + public ActionResult GetProfile() { if (!_authHelper.IsAuthenticated()) return Unauthorized(); + var data = _authHelper.CurrentAccountInfo(); if (data == null) { return NotFound("کاربر یافت نشد"); } - var details = new GetProfileDetails( + + if (_authHelper.GetUserTypeWithId().userType is not UserType.Admin) + return Unauthorized(); + + var details = new GetAdminProfileDetails( data.Id, data.Fullname, - _authHelper.GetUserTypeWithId().userType, data.Mobile, data.RoleName, data.Permissions, @@ -39,5 +45,4 @@ public class LoginController : GeneralBaseController ); return details; } -} - +} \ No newline at end of file diff --git a/ServiceHost/Areas/Client/Controllers/LoginController.cs b/ServiceHost/Areas/Client/Controllers/LoginController.cs new file mode 100644 index 00000000..179813f8 --- /dev/null +++ b/ServiceHost/Areas/Client/Controllers/LoginController.cs @@ -0,0 +1,44 @@ +using _0_Framework.Application; +using Microsoft.AspNetCore.Mvc; +using ServiceHost.BaseControllers; + +namespace ServiceHost.Areas.Client.Controllers; + +public record GetClientProfileDetails(long Id, string Fullname, string Mobile, List Permissions,List Workshops); + +public class LoginController: ClientBaseController +{ + 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 Unauthorized(); + + if (_authHelper.GetUserTypeWithId().userType is not UserType.Client and not UserType.SubAccount) + return Unauthorized(); + + + var details = new GetClientProfileDetails( + data.Id, + data.Fullname, + data.Mobile, + data.Permissions, + data.WorkshopList + ); + return details; + } +} \ No newline at end of file diff --git a/ServiceHost/ServiceHost.csproj b/ServiceHost/ServiceHost.csproj index 76206104..4162b460 100644 --- a/ServiceHost/ServiceHost.csproj +++ b/ServiceHost/ServiceHost.csproj @@ -95,7 +95,6 @@ -