Beispiel #1
0
        public async void PerformInitialSetup(PicshareIdentityDbContext context)
        {
            // initial configuration will go here
            PicshareUserManager userMgr = new PicshareUserManager(new UserStore <PicshareUser>(context));
            PicshareRoleManager roleMgr = new PicshareRoleManager(new RoleStore <PicshareRole>(context));
            string roleName             = "Administrators";
            string userName             = "******";
            string password             = "******";

            if (!await roleMgr.RoleExistsAsync(roleName))
            {
                await roleMgr.CreateAsync(new PicshareRole(roleName));
            }

            PicshareUser user = await userMgr.FindByNameAsync(userName);

            if (user == null)
            {
                await userMgr.CreateAsync(new PicshareUser { UserName = userName }, password);

                user = await userMgr.FindByNameAsync(userName);
            }

            if (!await userMgr.IsInRoleAsync(user.Id, roleName))
            {
                await userMgr.AddToRoleAsync(user.Id, roleName);
            }
        }
Beispiel #2
0
        public static PicshareUserManager Create(IdentityFactoryOptions <PicshareUserManager> options, IOwinContext context)
        {
            PicshareIdentityDbContext db      = context.Get <PicshareIdentityDbContext>();
            PicshareUserManager       manager = new PicshareUserManager(new UserStore <PicshareUser>(db));

            manager.PasswordValidator = new PasswordValidator
                                        //new CustomPasswordValidator
            {
                RequiredLength          = 1,
                RequireNonLetterOrDigit = false,
                RequireDigit            = false,
                RequireLowercase        = false,
                RequireUppercase        = false
            };

            manager.UserValidator = new UserValidator <PicshareUser>(manager)
                                    //new CustomUserValidator(manager)
            {
                AllowOnlyAlphanumericUserNames = true,
                RequireUniqueEmail             = false
            };

            return(manager);
        }