コード例 #1
0
        public async Task <ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager2 manager2)
        {
            // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
            var userIdentity = await manager2.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

            // Add custom user claims here
            return(userIdentity);
        }
コード例 #2
0
        public static ApplicationUserManager2 Create(IdentityFactoryOptions <ApplicationUserManager2> options,
                                                     IOwinContext context)
        {
            var manager = new ApplicationUserManager2(new UserStore2(context.Get <ApplicationDbContext2>()));

            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator <ApplicationUser2, int>(manager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail             = true
            };
            // Configure validation logic for passwords
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength          = 6,
                RequireNonLetterOrDigit = true,
                RequireDigit            = true,
                RequireLowercase        = true,
                RequireUppercase        = true,
            };
            // Configure user lockout defaults
            manager.UserLockoutEnabledByDefault          = true;
            manager.DefaultAccountLockoutTimeSpan        = TimeSpan.FromMinutes(5);
            manager.MaxFailedAccessAttemptsBeforeLockout = 5;
            // Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user
            // You can write your own provider and plug in here.
            manager.RegisterTwoFactorProvider("PhoneCode", new PhoneNumberTokenProvider <ApplicationUser2, int>
            {
                MessageFormat = "Your security code is: {0}"
            });
            manager.RegisterTwoFactorProvider("EmailCode", new EmailTokenProvider <ApplicationUser2, int>
            {
                Subject    = "SecurityCode",
                BodyFormat = "Your security code is {0}"
            });
            manager.EmailService = new EmailService2();
            //manager.SmsService = new SmsService2();
            var dataProtectionProvider = options.DataProtectionProvider;

            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider =
                    new DataProtectorTokenProvider <ApplicationUser2, int>(dataProtectionProvider.Create("ASP.NET Identity"));
            }
            return(manager);
        }
コード例 #3
0
 public ApplicationSignInManager2(ApplicationUserManager2 userManager, IAuthenticationManager authenticationManager)
     : base(userManager, authenticationManager)
 {
 }