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.
This commit is contained in:
@@ -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<int>(claims.FirstOrDefault(x => x is { Type: "permissions" })?.Value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<int> GetPermissions()
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// نمایش اطلاعات عمومی مانند تاریخ ها و سال ها
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Dates")]
|
||||
public IActionResult GetDates()
|
||||
{
|
||||
@@ -20,4 +29,6 @@ public class GeneralController:GeneralBaseController
|
||||
years,months,currentDate
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
43
ServiceHost/Controllers/LoginController.cs
Normal file
43
ServiceHost/Controllers/LoginController.cs
Normal file
@@ -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,List<int>Permissions,long? PositionValue);
|
||||
public class LoginController : GeneralBaseController
|
||||
{
|
||||
|
||||
private readonly IAuthHelper _authHelper;
|
||||
|
||||
public LoginController(IAuthHelper authHelper)
|
||||
{
|
||||
_authHelper = authHelper;
|
||||
}
|
||||
/// <summary>
|
||||
/// جزئیات پروفایل کاربر جاری را برمی گرداند
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("Profile")]
|
||||
public ActionResult<GetProfileDetails> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user