Mini.Crm/Mini.Web/WebHelper/UserRightsHelper.cs

42 lines
1.2 KiB
C#

using Microsoft.AspNetCore.Http;
using Mini.Common;
using Mini.Web.WebHelper.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Mini.Web.WebHelper
{
public class UserRightsHelper
{
public static string[] getUserRights(HttpContext context)
{
UserRights userRights = null;
if (context.User.Identity.IsAuthenticated)
{
string userId = context.User.Identity.Name;
string cacheKey = "Cache_UserInfo_" + userId;
userRights = CacheHelper.Get<UserRights>(cacheKey);
if (userRights == null)
{
var login = MvcContext.GetLoginHelper();
var userrights = login.getRights(Convert.ToInt32(userId));
CacheHelper.Set(cacheKey, userrights);
userRights = new UserRights();
userRights.rights = userrights.rights;
}
}
else
{
userRights = new UserRights();
}
return userRights.rights==null ? new string[] { "-1" }: userRights.rights;
}
}
}