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


C# IUser.As方法代码示例

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


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

示例1: TryCheckAccess

        public bool TryCheckAccess(Permission permission, IUser user, IContent content) {
            var context = new CheckAccessContext { Permission = permission, User = user, Content = content };
            _authorizationServiceEventHandler.Checking(context);

            for (var adjustmentLimiter = 0; adjustmentLimiter != 3; ++adjustmentLimiter) {
                if (!context.Granted && context.User != null) {
                    if (!String.IsNullOrEmpty(_workContextAccessor.GetContext().CurrentSite.SuperUser) &&
                           String.Equals(context.User.UserName, _workContextAccessor.GetContext().CurrentSite.SuperUser, StringComparison.Ordinal)) {
                        context.Granted = true;
                    }
                }

                if (!context.Granted) {

                    // determine which set of permissions would satisfy the access check
                    var grantingNames = PermissionNames(context.Permission, Enumerable.Empty<string>()).Distinct().ToArray();

                    // determine what set of roles should be examined by the access check
                    IEnumerable<string> rolesToExamine;
                    if (context.User == null) {
                        rolesToExamine = AnonymousRole;
                    } 
                    else if (user.As<IUserRoles>().Roles.Any()) {
                        

                        // the current user is not null, so get his roles and add "Authenticated" to it
                        rolesToExamine = user.As<IUserRoles>().Roles.Union(AuthenticatedRole);

                    } else {
                        // the user is not null and has no specific role, then it's just "Authenticated"
                        rolesToExamine = AuthenticatedRole;
                    }

                    foreach (var role in rolesToExamine) {
                        foreach (var permissionName in _roleService.GetPermissionsForRoleByName(role)) {
                            string possessedName = permissionName;
                            if (grantingNames.Any(grantingName => String.Equals(possessedName, grantingName, StringComparison.OrdinalIgnoreCase))) {
                                context.Granted = true;
                            }

                            if (context.Granted)
                                break;
                        }

                        if (context.Granted)
                            break;
                    }
                }

                context.Adjusted = false;
                _authorizationServiceEventHandler.Adjust(context);
                if (!context.Adjusted)
                    break;
            }

            _authorizationServiceEventHandler.Complete(context);

            return context.Granted;
        }
开发者ID:NIKASoftwareDevs,项目名称:Orchard,代码行数:59,代码来源:CASAuthorizationService.cs

示例2: IsAuthorizedToView

 public bool IsAuthorizedToView(IUser user, IGraphContext graphContext)
 {
     var roles = GetAuthorizedToView(graphContext);
     if (roles.Contains("Anonymous")) return true;
     if (user == null) return false;
     return user.As<IUserRoles>().Roles.Intersect(roles).Count() != 0;
 }
开发者ID:Lombiq,项目名称:Associativy-Frontend-Engines-Administration,代码行数:7,代码来源:FrontendAuthorizer.cs

示例3: GetUserInfo

 public QuickLogOnUserInfo GetUserInfo(IUser user)
 {
     var part = user.As<WinXinUserInfoPart>();
     if (part != null)
     {
         part.Record.Loader(
          () => _winXinUserInfoPartRecordRepository
          .Fetch(x => x.UserId == user.Id).FirstOrDefault());
         var record = part.Record.Value;
         if (record != null)
         {
             var model = new QuickLogOnUserInfo
             {
                 UniqueId = record.openid,
                 NickName = record.nickname,
                 City = record.city,
                 Country = record.country,
                 HeadimgUrl = (record.headimgurl != null && record.headimgurl.Length > 0) ?
                 (record.headimgurl.Substring(0, record.headimgurl.Length - 1) + "46") : "",
                 Province = record.province,
                 Sex = record.sex == "1" ? "男" : "女",
                 Original = record
             };
             return model;
         }
     }
     return null;
 }
开发者ID:jksharp,项目名称:Orchard.OAuth.China,代码行数:28,代码来源:WeiXinOAuthProvider.cs

示例4: GetNotificationsUserPartOrThrow

        private static NotificationsUserPart GetNotificationsUserPartOrThrow(IUser user)
        {
            var notificationsUserPart = user.As<NotificationsUserPart>();

            if (notificationsUserPart == null)
            {
                throw new ArgumentException("The supplied user object should have NotificationsUserPart attached.");
            }

            return notificationsUserPart;
        }
开发者ID:Lombiq,项目名称:Orchard-User-Notifications,代码行数:11,代码来源:NotificationsToUserDispatcher.cs

示例5: GetClient

 public DropNetClient GetClient(IUser user) {
     if (user == null) return null;
     var userSettings = user.As<DropboxUserSettingsPart>();
     if (string.IsNullOrEmpty(userSettings.UserToken) 
         || string.IsNullOrEmpty(userSettings.UserSecret))
         return null;
     
     var settings = _orchard.WorkContext.CurrentSite.As<DropboxSettingsPart>();
     return new DropNetClient(settings.ApiKey, settings.ApiSecret,
                              userSettings.UserToken, userSettings.UserSecret);
 }
开发者ID:CloudMetal,项目名称:Kobowi.Dropbox,代码行数:11,代码来源:DropboxService.cs

示例6: SetPassword

        public void SetPassword(IUser user, string password) {
            if (!user.Is<UserPart>())
                throw new InvalidCastException();

            var userRecord = user.As<UserPart>().Record;
            SetPassword(userRecord, password);
        }
开发者ID:rupertwhitlock,项目名称:IncreasinglyAbsorbing,代码行数:7,代码来源:MembershipService.cs

示例7: LoggedOut

 public void LoggedOut(IUser user)
 {
     user.As<UserPart>().LastLogoutUtc = _clock.UtcNow;
 }
开发者ID:xw616525957,项目名称:Orchard,代码行数:4,代码来源:LoginUserEventHandler.cs

示例8: LoggedIn

 public void LoggedIn(IUser user)
 {
     user.As<UserPart>().LastLoginUtc = _clock.UtcNow;
 }
开发者ID:xw616525957,项目名称:Orchard,代码行数:4,代码来源:LoginUserEventHandler.cs

示例9: SetPassword

        public void SetPassword(IUser user, string password)
        {
            if (!user.Is<UserPart>())
                throw new InvalidCastException();

            var userPart = user.As<UserPart>();

            switch (GetSettings().PasswordFormat) {
                case MembershipPasswordFormat.Clear:
                    SetPasswordClear(userPart, password);
                    break;
                case MembershipPasswordFormat.Hashed:
                    SetPasswordHashed(userPart, password);
                    break;
                case MembershipPasswordFormat.Encrypted:
                    SetPasswordEncrypted(userPart, password);
                    break;
                default:
                    throw new ApplicationException(T("Unexpected password format value").ToString());
            }
        }
开发者ID:Zlatinsz,项目名称:podnebeto,代码行数:21,代码来源:MembershipService.cs

示例10: SetPassword

        public void SetPassword(IUser user, string password)
        {
            var userLdap = user.As<UserLdapPart>();
            if (userLdap.LdapDirectoryId == null &&
                ValidateUser(user.UserName, userLdap.CurrentPassword) == null)
                throw new ApplicationException("Invalid username or password.");

            originalMembershipService.Value.SetPassword(user, password);

            if (userLdap.LdapDirectoryId != null)
            {
                var directory = ldapDirectoryCache.GetDirectory(userLdap.LdapDirectoryId.Value);
                var ldapService = ldapServiceFactory.For(directory);

                bool passwordChanged;
                try
                {
                    passwordChanged = ldapService.ChangePassword(user.UserName, userLdap.CurrentPassword, password);
                }
                catch (Exception ex)
                {
                    if (ex is ApplicationException || ex is System.DirectoryServices.Protocols.DirectoryException)
                        Logger.Error("An error occurred when changing password of user {0}. Details: {1}", user.UserName, ex);
                    throw new ApplicationException("Password could not be changed.", ex);
                }

                if (!passwordChanged)
                    throw new ApplicationException("Password could not be changed.");
            }
        }
开发者ID:kubo08,项目名称:Orchard,代码行数:30,代码来源:LdapMembershipService.cs

示例11: UpdateFacebookUser

        public void UpdateFacebookUser(IUser user, IFacebookUser facebookUser)
        {
            var part = user.As<FacebookUserPart>();

            // Could this be better, e.g. with Automapper?
            part.FacebookUserId = facebookUser.FacebookUserId;
            part.FacebookUserName = facebookUser.FacebookUserName;
            part.FirstName = facebookUser.FirstName;
            part.Gender = facebookUser.Gender;
            part.IsVerified = facebookUser.IsVerified;
            part.LastName = facebookUser.LastName;
            part.Link = facebookUser.Link;
            part.Locale = facebookUser.Locale;
            part.Name = facebookUser.Name;
            part.TimeZone = facebookUser.TimeZone;

            _eventHandler.UserUpdated(user.As<IFacebookUser>());
        }
开发者ID:Lombiq,项目名称:Orchard-Facebook-Suite-Connect,代码行数:18,代码来源:FacebookConnectService.cs

示例12: ValidateTFA

        private void ValidateTFA(IUser user, string tfaCode)
        {
            //TODO: need null check on user??? Should it ever reach here with the user as null???
            var userTFA = user.As<TwoFactorAuthenticationPart>();
            var isValidCode = _twoFactorAuthenticator.IsValid(userTFA.SecretKey, tfaCode, 1);

            if (!isValidCode)
            {
                ModelState.AddModelError("tfacode", T("Invalid TFA Code."));
            }

            //return isValidCode;
        }
开发者ID:EmeraldElements,项目名称:Google-TFA,代码行数:13,代码来源:TwoFactorAuthenticationController.cs


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