当前位置: 首页>>代码示例>>C#>>正文


C# IUserRepository.GetUserByUserId方法代码示例

本文整理汇总了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 = ""
                        }));

                    }
                }
            }
        }
开发者ID:smichelotti,项目名称:MichelottiPlaybook,代码行数:53,代码来源:RequireAuthenticationAttribute.cs


注:本文中的IUserRepository.GetUserByUserId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。