2011-01-06 07:17:00 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Tanshu.Accounts.Contracts;
|
2011-01-17 14:55:43 +00:00
|
|
|
|
using System.Configuration;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Entities.Auth;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
using Tanshu.Accounts.Repository;
|
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-02-09 12:03:22 +00:00
|
|
|
|
private static Dictionary<string, bool> roles;
|
2011-01-30 07:14:05 +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
|
|
|
|
|
{
|
|
|
|
|
return currentUser;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value != null)
|
|
|
|
|
{
|
|
|
|
|
currentUser = value;
|
|
|
|
|
IsAuthenticated = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentUser = null;
|
|
|
|
|
IsAuthenticated = false;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
roles = null;
|
2011-01-06 07:17:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-09 12:03:22 +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
|
|
|
|
}
|
|
|
|
|
}
|