public static ApplicationRoleManager Create(IdentityFactoryOptions <ApplicationRoleManager> options, Microsoft.Owin.IOwinContext context) { var roleManager = new ApplicationRoleManager(new RoleStore <Role>(context.Get <CarManiacsDbContext>())); string userRole = "User"; string adminRole = "Admin"; if (context != null && roleManager.Roles.Count() == 0) { roleManager.Create(new Role(userRole)); roleManager.Create(new Role(adminRole)); } return(roleManager); }
// TODO: Need to find a way to abstract this out, so this can be implemented in a more extensible manner. public static UserManager Create(IdentityFactoryOptions <UserManager> options, Microsoft.Owin.IOwinContext context) { DataContext.AuthenticationDbContext dataContext = context.Get <DataContext.AuthenticationDbContext>( ); UserManager manager = new UserManager(new UserStore <User, Role, Guid, UserLogin, UserRole, UserClaim>(dataContext)); manager.UserValidator = manager.GetUserValidator( ); manager.PasswordValidator = manager.GetPasswordValidator( ); manager.UserLockoutEnabledByDefault = manager.LockoutEnabledByDefault; manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(manager.LockoutTimespanMinutes); manager.MaxFailedAccessAttemptsBeforeLockout = manager.LockoutFailedAttemptsAllowed; //// 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 it in here. //manager.RegisterTwoFactorProvider( "Phone Code", new PhoneNumberTokenProvider<ApplicationUser> { // MessageFormat = "Your security code is {0}" //} ); //manager.RegisterTwoFactorProvider( "Email Code", new EmailTokenProvider<ApplicationUser> { // Subject = "Security Code", // BodyFormat = "Your security code is {0}" //} ); Microsoft.AspNet.Identity.IIdentityMessageService service = manager.GetEmailService( ); if (service != null) { manager.EmailService = service; } service = manager.GetSMSService( ); if (service != null) { manager.SmsService = service; } var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider <User, Guid>(dataProtectionProvider.Create("ASP.NET Identity")); } return(manager); }
public static ApplicationUserManager Create(IdentityFactoryOptions <ApplicationUserManager> options, Microsoft.Owin.IOwinContext context) { var appDbContext = context.Get <ApplicationDbContext>(); var appUserManager = new ApplicationUserManager(new UserStore <ApplicationUser>(appDbContext)); appUserManager.EmailService = new EmailService(); var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { appUserManager.UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity")) { //Code for email confirmation and reset password life time TokenLifespan = TimeSpan.FromHours(6) }; } appUserManager.UserValidator = new UserValidator <ApplicationUser>(appUserManager) { AllowOnlyAlphanumericUserNames = true, RequireUniqueEmail = true }; appUserManager.PasswordValidator = new PasswordValidator { RequiredLength = 6, RequireNonLetterOrDigit = true, RequireDigit = false, RequireLowercase = true, RequireUppercase = true, }; return(appUserManager); }
public static AppUserManager Create(IdentityFactoryOptions <AppUserManager> options, Microsoft.Owin.IOwinContext context) { var manager = new AppUserManager(new UserStore <User>(context.Get <ApplicationDbContext>())); return(manager); }