本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例7: LoggedOut
public void LoggedOut(IUser user)
{
user.As<UserPart>().LastLogoutUtc = _clock.UtcNow;
}
示例8: LoggedIn
public void LoggedIn(IUser user)
{
user.As<UserPart>().LastLoginUtc = _clock.UtcNow;
}
示例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());
}
}
示例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.");
}
}
示例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>());
}
示例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;
}