Errors updated. Do not use old build.
This commit is contained in:
51
Tanshu.Accounts.Repository/Lifetime/Session.cs
Normal file
51
Tanshu.Accounts.Repository/Lifetime/Session.cs
Normal file
@ -0,0 +1,51 @@
|
||||
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;
|
||||
|
||||
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(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];
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user