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