2018-08-24 10:41:33 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Tanshu.Accounts.Entities;
|
2011-01-06 07:17:00 +00:00
|
|
|
|
|
2011-02-09 12:03:22 +00:00
|
|
|
|
namespace Tanshu.Accounts.Contracts
|
2011-01-06 07:17:00 +00:00
|
|
|
|
{
|
2011-02-09 12:03:22 +00:00
|
|
|
|
public static class Session
|
2011-01-06 07:17:00 +00:00
|
|
|
|
{
|
2011-04-11 12:55:45 +00:00
|
|
|
|
private static User _currentUser;
|
2011-01-06 07:17:00 +00:00
|
|
|
|
public static bool IsAuthenticated { get; private set; }
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public static User User
|
2011-01-06 07:17:00 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2011-04-11 12:55:45 +00:00
|
|
|
|
return _currentUser;
|
2011-01-06 07:17:00 +00:00
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != null)
|
|
|
|
|
{
|
2011-04-11 12:55:45 +00:00
|
|
|
|
_currentUser = value;
|
2011-01-06 07:17:00 +00:00
|
|
|
|
IsAuthenticated = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-04-11 12:55:45 +00:00
|
|
|
|
_currentUser = null;
|
2011-01-06 07:17:00 +00:00
|
|
|
|
IsAuthenticated = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-16 11:11:55 +00:00
|
|
|
|
public static bool IsAllowed(string role)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2011-04-11 12:55:45 +00:00
|
|
|
|
if (_currentUser == null)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
return false;
|
2018-08-24 10:41:33 +00:00
|
|
|
|
return _currentUser.Permissions.Any(x => x.Name == role);
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
2011-01-06 07:17:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|