bool isUserFound =
false;
bool isUserGone =
false;
UtilityService utility =
newUtilityService();
string rawurl =
HttpContext.Current.Request.RawUrl;
if (e.Identity.IsAuthenticated)
{
if (userPlaceHolder ==
null) //local property to tackle hitting DB multiple times
{
UserInternal userInternal = utility.GetLoggedInUser(e.Identity.Name);
if (userInternal !=
null)
{
userPlaceHolder = userInternal;
isUserFound = true;
//TODO: check for gone, you can use userInternal or userPlaceHolder
isUserGone = false;
}
}
else
{
isUserFound = true;
//TODO: check for gone, use userPlaceHolder
isUserGone = false;
}
}
//set the user
if (isUserFound && !isUserGone)
{
string role = String.IsNullOrWhiteSpace(userPlaceHolder.UserClass) ? String.Empty : userPlaceHolder.UserClass;
// Setting the current user and role in the Principal
e.User = new System.Security.Principal.GenericPrincipal(e.Identity, newstring[] { role });
HttpContext.Current.User = e.User;
}
//handle gone and user not found
if (!rawurl.LowerInvariantContains(
ControllerNames.Message) &&
!rawurl.LowerInvariantContains(
".css") &&
!rawurl.LowerInvariantContains(
".js") &&
!rawurl.LowerInvariantContains(
".jpg") &&
!rawurl.LowerInvariantContains(
".gif") &&
!rawurl.LowerInvariantContains(
".png"))
{
if (!isUserFound || isUserGone)
{
string url = String.Empty;
if (isUserGone)
url = utility.GetSiteRestrictedLink(ProcessingMessagesEnum.UserLocked);
else
url = utility.GetSiteRestrictedLink(ProcessingMessagesEnum.UserNotAuthorizedToViewSite); ;
HttpContext.Current.Response.Redirect(url);
}
}
}
Bookmarks