da929ad036
Breaking Change: Renamed Discontinued to IsActive and added NA field to products. Cleanup: Removed not used attributes Change: RoleConstants changed to simple string Feature: Table Create/Edit/Reorder and Modifier Create/Edit Form Feature: Bills now show the Tax name from the database and not a hack
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using Tanshu.Accounts.Entities.Auth;
|
|
using Tanshu.Accounts.Repository;
|
|
|
|
namespace Tanshu.Accounts.Contracts
|
|
{
|
|
public static class Session
|
|
{
|
|
private static Dictionary<string, bool> _roles;
|
|
private static User _currentUser;
|
|
public static bool IsAuthenticated { get; private set; }
|
|
public static User User
|
|
{
|
|
get
|
|
{
|
|
return _currentUser;
|
|
}
|
|
set
|
|
{
|
|
if (value != null)
|
|
{
|
|
_currentUser = value;
|
|
IsAuthenticated = true;
|
|
}
|
|
else
|
|
{
|
|
_currentUser = null;
|
|
IsAuthenticated = false;
|
|
_roles = null;
|
|
}
|
|
}
|
|
}
|
|
public static bool IsAllowed(string role)
|
|
{
|
|
if (_currentUser == null)
|
|
return false;
|
|
if (_roles == null)
|
|
_roles = new Dictionary<string, bool>();
|
|
if (!_roles.ContainsKey(role))
|
|
_roles.Add(role, new UserBI().IsUserInRole(_currentUser.UserID, role));
|
|
return _roles[role];
|
|
}
|
|
}
|
|
}
|