-
-
Save kgiszewski/b637cf96286e272d70b24ea446622c5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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