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


C# UserType.Count方法代码示例

本文整理汇总了C#中UserType.Count方法的典型用法代码示例。如果您正苦于以下问题:C# UserType.Count方法的具体用法?C# UserType.Count怎么用?C# UserType.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserType的用法示例。


在下文中一共展示了UserType.Count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Authorize

        /// <summary>
        /// Method that checks if the user is authenticated and authorized to execute the method based on the authorization token.
        /// If authorization is optional and the user is not yet authenticated, a new account is created for the user.
        /// </summary>
        /// <param name="allowedUserTypes">Array of authorized UserTypes.</param>
        public void Authorize(UserType[] allowedUserTypes)
        {
            // Get user info using the AuthorizationToken HTTP header
            OpenIDUserInfo userInfo = this.userManager.GetOpenIDUserInfo();

            // Only continue if user info was successfully retrieved from the Access token issuer
            if (userInfo != null)
            {
                // Try to match a user using the user info retrieved from the Access Token issuer
                User matchedUser = this.userManager.MatchUser(userInfo);

                // Set the property that indicates if the user is authenticated
                this.IsAuthenticated = (matchedUser != null);

                // Check if the user is authenticated
                if (this.IsAuthenticated)
                {
                    // The user is authenticated, set the property that indicates if the user is authorized to execute the method
                    this.IsAuthorized = (allowedUserTypes.Count() == 0 || allowedUserTypes.Contains(matchedUser.Type));
                }
                else
                {
                    // The user is not authenticated - check if authorization is optional or if a customer is authorized to execute the method
                    if (allowedUserTypes.Count() == 0 || allowedUserTypes.Contains(UserType.Customer))
                    {
                        // Authorization is optional or a customer is authorized to execute the method, create a new user using the user info retrieved from the Access Token issuer
                        this.userManager.CreateUser(userInfo);

                        // Set the properties that indicate that the user is authenticated and authorized to execute the method
                        this.IsAuthenticated = true;
                        this.IsAuthorized = true;
                    }
                }
            }
        }
开发者ID:Teunozz,项目名称:nl.fhict.intellicloud.backend,代码行数:40,代码来源:AuthorizationHandler.cs


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