Skip to content

Instantly share code, notes, and snippets.

@kgiszewski
Created July 13, 2018 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kgiszewski/b637cf96286e272d70b24ea446622c5d to your computer and use it in GitHub Desktop.
Save kgiszewski/b637cf96286e272d70b24ea446622c5d to your computer and use it in GitHub Desktop.
@using Microsoft.AspNet.Identity
@inherits UmbracoTemplatePage
@{
var isAuthenticated = User.Identity.IsAuthenticated;
var username = User.Identity.GetUserName();
//run our access control check
var checker = new ContactAccessChecker();
if (!isAuthenticated || !checker.HasAccess(username))
{
//redirect to somewhere else
}
// show the content
public class ContactAccessChecker {
public bool HasAccess(string username)
{
var membership = ApplicationContext.Current.Services.MemberService.GetByUsername(username);
if (membership != null)
{
//we think you are a staff/faculty
//check for roles
var hasRole = true;
if (hasRole)
{
return true;
}
}
else
{
//we think you are a student
var isInDb = true;
if (isInDb)
{
return true;
}
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment