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.
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
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;
|
|
}
|
|
}
|
|
|