/// <summary>
        /// Used to create a user manager with custom store
        /// </summary>
        /// <param name="options"></param>
        /// <param name="customUserStore"></param>
        /// <param name="membershipProvider"></param>
        /// <returns></returns>
        public static UmbracoMembersUserManager <TUser> Create(
            IdentityFactoryOptions <UmbracoMembersUserManager <TUser> > options,
            UmbracoMembersUserStore <TUser> customUserStore,
            IdentityEnabledMembersMembershipProvider membershipProvider = null)
        {
            //we'll grab some settings from the membership provider
            var provider = membershipProvider ?? Membership.Providers["UmbracoMembershipProvider"] as IdentityEnabledMembersMembershipProvider;

            if (provider == null)
            {
                throw new InvalidOperationException("In order to use " + typeof(UmbracoMembersUserManager <>) + " the Umbraco members membership provider must be of type " + typeof(IdentityEnabledMembersMembershipProvider));
            }

            var manager = new UmbracoMembersUserManager <TUser>(customUserStore);

            // Configure validation logic for usernames
            manager.UserValidator = new UserValidator <TUser, int>(manager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail             = true
            };

            // Configure validation logic for passwords
            manager.PasswordValidator = new PasswordValidator
            {
                RequiredLength          = provider.MinRequiredPasswordLength,
                RequireNonLetterOrDigit = provider.MinRequiredNonAlphanumericCharacters > 0,
                RequireDigit            = false,
                RequireLowercase        = false,
                RequireUppercase        = false
            };

            //use a custom hasher based on our membership provider
            manager.PasswordHasher = new MembershipPasswordHasher(provider);

            //NOTE: Not implementing these currently

            //// 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<ApplicationUser>
            //{
            //    MessageFormat = "Your security code is: {0}"
            //});
            //manager.RegisterTwoFactorProvider("EmailCode", new EmailTokenProvider<ApplicationUser>
            //{
            //    Subject = "Security Code",
            //    BodyFormat = "Your security code is: {0}"
            //});

            //manager.EmailService = new EmailService();
            //manager.SmsService = new SmsService();

            var dataProtectionProvider = options.DataProtectionProvider;

            if (dataProtectionProvider != null)
            {
                manager.UserTokenProvider = new DataProtectorTokenProvider <TUser, int>(dataProtectionProvider.Create("ASP.NET Identity"));
            }
            return(manager);
        }
        /// <summary>
        /// Configure identity User Manager for Umbraco with custom user store
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="app"></param>
        /// <param name="customUserStore"></param>
        /// <param name="appContext"></param>
        /// <param name="membershipProvider"></param>
        public static void ConfigureUserManagerForUmbracoMembers <T>(this IAppBuilder app,
                                                                     UmbracoMembersUserStore <T> customUserStore,
                                                                     ApplicationContext appContext,
                                                                     IdentityEnabledMembersMembershipProvider membershipProvider = null)
            where T : UmbracoIdentityMember, new()
        {
            if (appContext == null)
            {
                throw new ArgumentNullException("appContext");
            }

            //Don't proceed if the app is not ready
            if (!appContext.IsConfigured ||
                appContext.DatabaseContext == null ||
                !appContext.DatabaseContext.IsDatabaseConfigured)
            {
                return;
            }

            //Configure Umbraco user manager to be created per request
            app.CreatePerOwinContext <UmbracoMembersUserManager <T> >(
                (o, c) => UmbracoMembersUserManager <T> .Create(
                    o,
                    customUserStore,
                    membershipProvider));

            //Configure Umbraco member event handler to be created per request - this will ensure that the
            // external logins are kept in sync if members are deleted from Umbraco
            app.CreatePerOwinContext <MembersEventHandler <T> >((options, context) => new MembersEventHandler <T>(context));
        }
Example #3
0
        public static void ConfigureUserManagerForUmbracoMembers <T>(this IAppBuilder app,
                                                                     UmbracoMembersUserStore <T> customUserStore,
                                                                     IdentityEnabledMembersMembershipProvider membershipProvider = null)
            where T : UmbracoIdentityMember, new()
        {
            //Configure Umbraco user manager to be created per request
            app.CreatePerOwinContext <UmbracoMembersUserManager <T> >(
                (o, c) => UmbracoMembersUserManager <T> .Create(
                    o,
                    customUserStore,
                    membershipProvider));

            //Configure Umbraco member event handler to be created per request - this will ensure that the
            // external logins are kept in sync if members are deleted from Umbraco
            app.CreatePerOwinContext <MembersEventHandler <T> >((options, context) => new MembersEventHandler <T>(context));
        }
Example #4
0
        /// <summary>
        /// Used to create a user manager with custom store
        /// </summary>
        /// <param name="options"></param>
        /// <param name="customUserStore"></param>
        /// <param name="membershipProvider"></param>
        /// <returns></returns>
        public static UmbracoMembersUserManager <TUser> Create(
            IdentityFactoryOptions <UmbracoMembersUserManager <TUser> > options,
            UmbracoMembersUserStore <TUser> customUserStore,
            IdentityEnabledMembersMembershipProvider membershipProvider = null)
        {
            //we'll grab some settings from the membership provider
            var provider = membershipProvider ?? Membership.Providers["UmbracoMembershipProvider"] as IdentityEnabledMembersMembershipProvider;

            if (provider == null)
            {
                throw new InvalidOperationException("In order to use " + typeof(UmbracoMembersUserManager <>) + " the Umbraco members membership provider must be of type " + typeof(IdentityEnabledMembersMembershipProvider));
            }

            var manager = new UmbracoMembersUserManager <TUser>(customUserStore);

            Configure(manager, provider, options);

            return(manager);
        }