• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# MembershipReboot.UserAccount类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中BrockAllen.MembershipReboot.UserAccount的典型用法代码示例。如果您正苦于以下问题:C# UserAccount类的具体用法?C# UserAccount怎么用?C# UserAccount使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UserAccount类属于BrockAllen.MembershipReboot命名空间,在下文中一共展示了UserAccount类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Validate

        public ValidationResult Validate(UserAccountService service, UserAccount account, string value)
        {
            if (String.IsNullOrWhiteSpace(value))
            {
                return new ValidationResult(Resources.ValidationMessages.PasswordRequired);
            }
            
            if (value.Length < this.MinimumLength)
            {
                return new ValidationResult(String.Format(Resources.ValidationMessages.PasswordLength, this.MinimumLength));
            }

            var upper = value.Any(x => Char.IsUpper(x));
            var lower = value.Any(x => Char.IsLower(x));
            var digit = value.Any(x => Char.IsDigit(x));
            var other = value.Any(x => !Char.IsUpper(x) && !Char.IsLower(x) && !Char.IsDigit(x));

            var vals = new bool[] { upper, lower, digit, other };
            var matches = vals.Where(x => x).Count();
            if (matches < this.MinimumNumberOfComplexityRules)
            {
                return new ValidationResult(String.Format(Resources.ValidationMessages.PasswordComplexityRules, this.MinimumNumberOfComplexityRules));
            }

            return null;
        }
开发者ID:neogodless,项目名称:BrockAllen.MembershipReboot,代码行数:26,代码来源:PasswordComplexityValidator.cs


示例2: SignIn

        public virtual void SignIn(UserAccount account, string method)
        {
            if (account == null) throw new ArgumentNullException("account");
            if (String.IsNullOrWhiteSpace(method)) throw new ArgumentNullException("method");

            if (!account.IsAccountVerified)
            {
                throw new ValidationException("Account not yet verified");
            }

            if (!account.IsLoginAllowed)
            {
                throw new ValidationException("Login not allowed for this account");
            }

            // gather claims
            var claims =
                (from uc in account.Claims
                 select new Claim(uc.Type, uc.Value)).ToList();

            if (!String.IsNullOrWhiteSpace(account.Email))
            {
                claims.Insert(0, new Claim(ClaimTypes.Email, account.Email));
            }
            claims.Insert(0, new Claim(ClaimTypes.AuthenticationMethod, method));
            claims.Insert(0, new Claim(ClaimTypes.AuthenticationInstant, DateTime.UtcNow.ToString("s")));
            claims.Insert(0, new Claim(ClaimTypes.Name, account.Username));
            claims.Insert(0, new Claim(MembershipRebootConstants.ClaimTypes.Tenant, account.Tenant));
            claims.Insert(0, new Claim(ClaimTypes.NameIdentifier, account.ID.ToString("D")));

            // create principal/identity
            var id = new ClaimsIdentity(claims, method);
            var cp = new ClaimsPrincipal(id);

            // claims transform
            cp = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.ClaimsAuthenticationManager.Authenticate(String.Empty, cp);

            // issue cookie
            var sam = FederatedAuthentication.SessionAuthenticationModule;
            if (sam == null)
            {
                Tracing.Verbose("[ClaimsBasedAuthenticationService.Signin] SessionAuthenticationModule is not configured");
                throw new Exception("SessionAuthenticationModule is not configured and it needs to be.");
            }

            var handler = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers[typeof(SessionSecurityToken)] as SessionSecurityTokenHandler;
            if (handler == null)
            {
                Tracing.Verbose("[ClaimsBasedAuthenticationService.Signin] SessionSecurityTokenHandler is not configured");
                throw new Exception("SessionSecurityTokenHandler is not configured and it needs to be.");
            }

            var token = new SessionSecurityToken(cp, handler.TokenLifetime);
            token.IsPersistent = FederatedAuthentication.FederationConfiguration.WsFederationConfiguration.PersistentCookiesOnPassiveRedirects;
            token.IsReferenceMode = sam.IsReferenceMode;

            sam.WriteSessionTokenToCookie(token);

            Tracing.Verbose(String.Format("[ClaimsBasedAuthenticationService.Signin] cookie issued: {0}", claims.GetValue(ClaimTypes.NameIdentifier)));
        }
开发者ID:EdHastings,项目名称:BrockAllen.MembershipReboot,代码行数:60,代码来源:ClaimsBasedAuthenticationService.cs


示例3: GetTwoFactorAuthToken

 public string GetTwoFactorAuthToken(UserAccount account)
 {
     if (account == null) throw new ArgumentNullException("account");
     var result = GetCookie(MembershipRebootConstants.AuthenticationService.CookieBasedTwoFactorAuthPolicyCookieName + account.Tenant);
     Tracing.Information("[CookieBasedTwoFactorAuthPolicy.ClearTwoFactorAuthToken] getting cookie for {0}, {1}, found:{2}", account.Tenant, account.Username, result);
     return result;
 }
开发者ID:KamoHaladus,项目名称:BrockAllen.MembershipReboot,代码行数:7,代码来源:CookieBasedTwoFactorAuthPolicy.cs


示例4: Create

        public static UserAccount Create(string username, string password, string email)
        {
            if (SecuritySettings.Instance.EmailIsUsername && username != email)
            {
                throw new ValidationException("Username must be the same as the Email");
            }

            UserAccount account = new UserAccount
            {
                Username = username,
                Email = email,
                Created = DateTime.UtcNow,
                IsAccountVerified = !SecuritySettings.Instance.RequireAccountVerification,
                IsLoginAllowed = SecuritySettings.Instance.AllowLoginAfterAccountCreation,
                Claims = new List<UserClaim>()
            };

            account.SetPassword(password);
            if (SecuritySettings.Instance.RequireAccountVerification)
            {
                account.VerificationKey = StripUglyBase64(Crypto.GenerateSalt());
                account.VerificationKeySent = DateTime.UtcNow;
            }

            return account;
        }
开发者ID:codingoutloud,项目名称:BrockAllen.MembershipReboot,代码行数:26,代码来源:UserAccount.cs


示例5: Remove

 public void Remove(UserAccount item)
 {
     foreach (var claim in item.Claims.ToArray())
     {
         item.Claims.Remove(claim);
     }
     db.Users.Remove(item);
 }
开发者ID:codingoutloud,项目名称:BrockAllen.MembershipReboot,代码行数:8,代码来源:EFUserAccountRepository.cs


示例6: SendAccountVerified

        public void SendAccountVerified(UserAccount user)
        {
            Tracing.Information(String.Format("[NotificationService.SendAccountVerified] {0}, {1}, {2}", user.Tenant, user.Username, user.Email));

            var msg = GetAccountVerifiedFormat();
            var body = DoTokenReplacement(msg, user);
            DeliverMessage(user, "Account Verified", body);
        }
开发者ID:BinaryCoderL,项目名称:BrockAllen.MembershipReboot,代码行数:8,代码来源:NotificationService.cs


示例7: SignIn

        public virtual void SignIn(UserAccount account, string method)
        {
            if (account == null) throw new ArgumentNullException("account");
            if (String.IsNullOrWhiteSpace(method)) throw new ArgumentNullException("method");

            if (!account.IsAccountVerified)
            {
                throw new ValidationException(Resources.ValidationMessages.AccountNotVerified);
            }

            if (!account.IsLoginAllowed)
            {
                throw new ValidationException(Resources.ValidationMessages.LoginNotAllowed);
            }

            if (account.RequiresTwoFactorAuthToSignIn || 
                account.RequiresPasswordReset || 
                this.UserAccountService.IsPasswordExpired(account))
            {
                Tracing.Verbose("[AuthenticationService.SignIn] detected account requires two factor or password reset to sign in: {0}", account.ID);
                IssuePartialSignInToken(account, method);
                return;
            }

            // gather claims
            var claims = GetBasicClaims(account, method);
            
            // get the rest
            if (!String.IsNullOrWhiteSpace(account.Email))
            {
                claims.Add(new Claim(ClaimTypes.Email, account.Email));
            }
            if (!String.IsNullOrWhiteSpace(account.MobilePhoneNumber))
            {
                claims.Add(new Claim(ClaimTypes.MobilePhone, account.MobilePhoneNumber));
            }
            var x509 = from c in account.Certificates
                       select new Claim(ClaimTypes.X500DistinguishedName, c.Subject);
            claims.AddRange(x509);
            var otherClaims =
                (from uc in account.Claims
                 select new Claim(uc.Type, uc.Value)).ToList();
            claims.AddRange(otherClaims);

            // create principal/identity
            var id = new ClaimsIdentity(claims, method);
            var cp = new ClaimsPrincipal(id);

            // claims transform
            if (this.ClaimsAuthenticationManager != null)
            {
                cp = ClaimsAuthenticationManager.Authenticate(String.Empty, cp);
            }

            // issue cookie
            IssueToken(cp);
        }
开发者ID:neogodless,项目名称:BrockAllen.MembershipReboot,代码行数:57,代码来源:AuthenticationService.cs


示例8: ValidateUsername

 internal protected void ValidateUsername(UserAccount account, string value)
 {
     var result = this.usernameValidator.Value.Validate(this, account, value);
     if (result != null && result != ValidationResult.Success)
     {
         Tracing.Error("ValidateUsername failed: " + result.ErrorMessage);
         throw new ValidationException(result.ErrorMessage);
     }
 }
开发者ID:jdiamond,项目名称:BrockAllen.MembershipReboot,代码行数:9,代码来源:UserAccountService.cs


示例9: SignIn

        public virtual void SignIn(UserAccount account, string method)
        {
            if (account == null) throw new ArgumentNullException("account");
            if (String.IsNullOrWhiteSpace(method)) throw new ArgumentNullException("method");

            if (!account.IsAccountVerified)
            {
                throw new ValidationException("Account not yet verified.");
            }

            if (!account.IsLoginAllowed)
            {
                throw new ValidationException("Login not allowed for this account.");
            }

            if (account.RequiresTwoFactorAuthToSignIn)
            {
                Tracing.Verbose("[AuthenticationService.SignIn] detected account requires two factor to sign in: {0}", account.Id);
                IssuePartialSignInTokenForTwoFactorAuth(account, method);
                return;
            }

            // gather claims
            var claims = GetBasicClaims(account, method);
            
            // get the rest
            if (!String.IsNullOrWhiteSpace(account.Email))
            {
                claims.Add(new Claim(ClaimTypes.Email, account.Email));
            }
            if (!String.IsNullOrWhiteSpace(account.MobilePhoneNumber))
            {
                claims.Add(new Claim(ClaimTypes.MobilePhone, account.MobilePhoneNumber));
            }
            var x509 = from c in account.Certificates
                       select new Claim(ClaimTypes.X500DistinguishedName, c.Subject);
            claims.AddRange(x509);
            var otherClaims =
                (from uc in account.Claims
                 select new Claim(uc.Type, uc.Value)).ToList();
            claims.AddRange(otherClaims);

            // create principal/identity
            var id = new ClaimsIdentity(claims, method);
            var cp = new ClaimsPrincipal(id);

            // claims transform
            cp = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.ClaimsAuthenticationManager.Authenticate(String.Empty, cp);

            // issue cookie
            IssueToken(cp);
        }
开发者ID:andyevans2000,项目名称:Illuminate,代码行数:52,代码来源:AuthenticationService.cs


示例10: DoTokenReplacement

        protected virtual string DoTokenReplacement(string msg, UserAccount user)
        {
            msg = msg.Replace("{username}", user.Username);
            msg = msg.Replace("{email}", user.Email);

            msg = msg.Replace("{applicationName}", appInfo.ApplicationName);
            msg = msg.Replace("{emailSignature}", appInfo.EmailSignature);
            msg = msg.Replace("{loginUrl}", appInfo.LoginUrl);

            msg = msg.Replace("{confirmAccountCreateUrl}", appInfo.VerifyAccountUrl + user.VerificationKey);
            msg = msg.Replace("{cancelNewAccountUrl}", appInfo.CancelNewAccountUrl + user.VerificationKey);

            msg = msg.Replace("{confirmPasswordResetUrl}", appInfo.ConfirmPasswordResetUrl + user.VerificationKey);
            msg = msg.Replace("{confirmChangeEmailUrl}", appInfo.ConfirmChangeEmailUrl + user.VerificationKey);

            
            return msg; 
        }
开发者ID:BinaryCoderL,项目名称:BrockAllen.MembershipReboot,代码行数:18,代码来源:NotificationService.cs


示例11: Create

        internal static UserAccount Create(string tenant, string username, string password, string email)
        {
            UserAccount account = new UserAccount
            {
                Tenant = tenant,
                Username = username,
                Email = email,
                Created = DateTime.UtcNow,
                IsAccountVerified = !SecuritySettings.Instance.RequireAccountVerification,
                IsLoginAllowed = SecuritySettings.Instance.AllowLoginAfterAccountCreation,
                Claims = new List<UserClaim>()
            };

            account.SetPassword(password);
            if (SecuritySettings.Instance.RequireAccountVerification)
            {
                account.VerificationKey = StripUglyBase64(Crypto.GenerateSalt());
                account.VerificationKeySent = DateTime.UtcNow;
            }

            return account;
        }
开发者ID:simongh,项目名称:BrockAllen.MembershipReboot,代码行数:22,代码来源:UserAccount.cs


示例12: Authenticate

 public virtual bool Authenticate(string username, string password, out UserAccount account)
 {
     return Authenticate(null, username, password, out account);
 }
开发者ID:jdiamond,项目名称:BrockAllen.MembershipReboot,代码行数:4,代码来源:UserAccountService.cs


示例13: AuthenticateWithCertificate

        public virtual bool AuthenticateWithCertificate(Guid accountID, X509Certificate2 certificate, out UserAccount account)
        {
            Tracing.Information("[UserAccountService.AuthenticateWithCertificate] called for userID: {0}", accountID);
            
            certificate.Validate();

            account = this.GetByID(accountID);
            if (account == null) throw new ArgumentException("Invalid AccountID");

            var result = account.Authenticate(certificate);
            Update(account);

            Tracing.Verbose("[UserAccountService.AuthenticateWithCertificate] result: {0}", result);
            
            return result;
        }
开发者ID:jdiamond,项目名称:BrockAllen.MembershipReboot,代码行数:16,代码来源:UserAccountService.cs


示例14: AuthenticateWithCode

        public virtual bool AuthenticateWithCode(Guid accountID, string code, out UserAccount account)
        {
            Tracing.Information("[UserAccountService.AuthenticateWithCode] called {0}", accountID);

            account = this.GetByID(accountID);
            if (account == null) throw new ArgumentException("Invalid AccountID");

            var result = account.VerifyTwoFactorAuthCode(code);
            Update(account);

            Tracing.Verbose("[UserAccountService.AuthenticateWithCode] result {0}", result);

            return result;
        }
开发者ID:jdiamond,项目名称:BrockAllen.MembershipReboot,代码行数:14,代码来源:UserAccountService.cs


示例15: IssuePartialSignInTokenForTwoFactorAuth

        private void IssuePartialSignInTokenForTwoFactorAuth(UserAccount account, string method)
        {
            if (account == null) throw new ArgumentNullException("account");

            Tracing.Verbose("[AuthenticationService.IssuePartialSignInCookieForTwoFactorAuth] Account ID: {0}", account.ID);

            var claims = GetBasicClaims(account, method);

            var ci = new ClaimsIdentity(claims); // no auth type param so user will not be actually authenticated
            var cp = new ClaimsPrincipal(ci);

            IssueToken(cp, MembershipRebootConstants.AuthenticationService.TwoFactorAuthTokenLifetime, false);
        }
开发者ID:rtrevelar,项目名称:BrockAllen.MembershipReboot,代码行数:13,代码来源:AuthenticationService.cs


示例16: SendChangeUsernameRequestNotice

        public void SendChangeUsernameRequestNotice(UserAccount user)
        {
            Tracing.Information(String.Format("[NotificationService.SendChangeUsernameRequestNotice] {0}, {1}, {2}", user.Tenant, user.Username, user.Email));

            var msg = GetUsernameChangedNoticeFormat();
            var body = DoTokenReplacement(msg, user);
            DeliverMessage(user, "Username Changed", body);
        }
开发者ID:BinaryCoderL,项目名称:BrockAllen.MembershipReboot,代码行数:8,代码来源:NotificationService.cs


示例17: IsPasswordExpired

        public virtual bool IsPasswordExpired(UserAccount account)
        {
            if (account == null) throw new ArgumentNullException("account");

            return account.GetIsPasswordExpired(SecuritySettings.PasswordResetFrequency);
        }
开发者ID:jdiamond,项目名称:BrockAllen.MembershipReboot,代码行数:6,代码来源:UserAccountService.cs


示例18: DeleteAccount

        protected internal virtual void DeleteAccount(UserAccount account)
        {
            if (account == null) throw new ArgumentNullException("account");

            Tracing.Verbose("[UserAccountService.DeleteAccount] marking account as closed: {0}", account.ID);

            account.CloseAccount();
            Update(account);

            if (SecuritySettings.AllowAccountDeletion || !account.IsAccountVerified)
            {
                Tracing.Verbose("[UserAccountService.DeleteAccount] removing account record: {0}", account.ID);
                this.userRepository.Remove(account);
            }
        }
开发者ID:jdiamond,项目名称:BrockAllen.MembershipReboot,代码行数:15,代码来源:UserAccountService.cs


示例19: Update

        public virtual void Update(UserAccount account)
        {
            if (account == null)
            {
                Tracing.Error("[UserAccountService.Update] called -- failed null account");
                throw new ArgumentNullException("account");
            }

            Tracing.Information("[UserAccountService.Update] called for account: {0}", account.ID);

            account.LastUpdated = account.UtcNow;
            this.userRepository.Update(account);
        }
开发者ID:jdiamond,项目名称:BrockAllen.MembershipReboot,代码行数:13,代码来源:UserAccountService.cs


示例20: SendResetPassword

        public void SendResetPassword(UserAccount user)
        {
            Tracing.Information(String.Format("[NotificationService.SendResetPassword] {0}, {1}, {2}", user.Tenant, user.Username, user.Email));

            var msg = GetResetPasswordFormat();
            var body = DoTokenReplacement(msg, user);
            DeliverMessage(user, "Password Reset Request", body);
        }
开发者ID:BinaryCoderL,项目名称:BrockAllen.MembershipReboot,代码行数:8,代码来源:NotificationService.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Accounts.MockUserAccountService类代码示例发布时间:2022-05-24
下一篇:
C# EntityFramework.MyEntityContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap