narsil/Tanshu.Accounts.Repository/Lifetime/Session.cs

52 lines
1.4 KiB
C#
Raw Normal View History

2011-01-06 07:17:00 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanshu.Accounts.Contracts;
using System.Configuration;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Repository;
2011-01-06 07:17:00 +00:00
namespace Tanshu.Accounts.Contracts
2011-01-06 07:17:00 +00:00
{
public static class Session
2011-01-06 07:17:00 +00:00
{
private static Dictionary<string, bool> _roles;
private static User _currentUser;
2011-01-06 07:17:00 +00:00
public static bool IsAuthenticated { get; private set; }
public static User User
2011-01-06 07:17:00 +00:00
{
get
{
return _currentUser;
2011-01-06 07:17:00 +00:00
}
set
{
if (value != null)
{
_currentUser = value;
2011-01-06 07:17:00 +00:00
IsAuthenticated = true;
}
else
{
_currentUser = null;
2011-01-06 07:17:00 +00:00
IsAuthenticated = false;
_roles = null;
2011-01-06 07:17:00 +00:00
}
}
}
public static bool IsAllowed(RoleConstants role)
{
if (_currentUser == null)
return false;
if (_roles == null)
_roles = new Dictionary<string, bool>();
if (!_roles.ContainsKey(role.Role))
_roles.Add(role.Role, MembershipBI.IsUserInRole(_currentUser.UserID, role.Role));
return _roles[role.Role];
}
2011-01-06 07:17:00 +00:00
}
}