本文整理汇总了C#中IUserRepository.GetUserByUserId方法的典型用法代码示例。如果您正苦于以下问题:C# IUserRepository.GetUserByUserId方法的具体用法?C# IUserRepository.GetUserByUserId怎么用?C# IUserRepository.GetUserByUserId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserRepository
的用法示例。
在下文中一共展示了IUserRepository.GetUserByUserId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnAuthorization
//public RequireAuthenticationAttribute(IUserRepository repository)
//{
// this.userRepository = repository;
//}
public void OnAuthorization(System.Web.Mvc.AuthorizationContext filterContext)
{
if (!filterContext.HttpContext.Request.IsAuthenticated)
{
var url = filterContext.HttpContext.Request.Url;
var redirectUrl = string.Format("{0}://{1}/", url.Scheme, url.Authority);
//filterContext.Result = new RedirectResult("https://michelotti-apps.accesscontrol.windows.net:443/v2/wsfederation?wa=wsignin1.0&wtrealm=" + redirectUrl);
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {{ "Controller", "Account" }, { "Action", "SignIn" }, { "Area", "" } });
}
else
{
// User *is* authenticated so check to see if they are approved
var identity = filterContext.HttpContext.User.Identity as IClaimsIdentity;
var approvedClaim = identity.Claims.Where(c => c.ClaimType == "PlaybookApproved").SingleOrDefault();
if (approvedClaim == null || approvedClaim.Value != "true")
{
var nameIdClaim = identity.Claims.SingleOrDefault(c => c.ClaimType == ClaimTypes.NameIdentifier);
//var emailClaim = identity.Claims.SingleOrDefault(c => c.ClaimType == ClaimTypes.Email);
//TODO: need dependency injection for RequireAuthenticationAttribute
this.userRepository = new UserRepository();
var user = userRepository.GetUserByUserId(nameIdClaim.Value);
if (user != null && user.IsApproved)
{
// Add custom claim
identity.Claims.Add(new Claim("PlaybookApproved", "true"));
if (user.Permissions != null)
{
identity.Claims.Add(new Claim("Permissions", user.Permissions));
}
userRepository.InsertUserActivity(new UserActivity { UserId = nameIdClaim.Value, Name = user.Name, Action = "Authenticate" });
}
else
{
// User is not in repository or hasn't been approved yet so redirect to Approval Screen
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
{
action = "ApprovalRequired",
controller = "Account",
area = ""
}));
}
}
}
}