Esempio n. 1
0
        public static AuthUserManager Create(IdentityFactoryOptions <AuthUserManager> options, IOwinContext context)
        {
            AuthContext     db      = context.Get <AuthContext>();
            AuthUserManager manager = new AuthUserManager(new UserStore <AuthUser>(db));

            return(manager);
        }
Esempio n. 2
0
        protected override void Seed(AuthContext context)
        {
            var userManager = new AuthUserManager(new UserStore <AuthUser>(context));
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var role1       = new IdentityRole("admin");
            var role2       = new IdentityRole("user1");
            var role3       = new IdentityRole("user2");


            roleManager.Create(role1);
            roleManager.Create(role2);
            roleManager.Create(role3);

            var admin = new AuthUser {
                Email = "*****@*****.**", UserName = "******"
            };
            string password = "******";
            var    result   = userManager.Create(admin, password);

            if (result.Succeeded)
            {
                userManager.AddToRole(admin.Id, role1.Name);
                userManager.AddToRole(admin.Id, role2.Name);
                userManager.AddToRole(admin.Id, role3.Name);
            }

            var user1 = new AuthUser {
                Email = "*****@*****.**", UserName = "******"
            };

            password = "******";
            result   = userManager.Create(user1, password);
            if (result.Succeeded)
            {
                userManager.AddToRole(user1.Id, role2.Name);
            }

            var user2 = new AuthUser {
                Email = "*****@*****.**", UserName = "******"
            };

            password = "******";
            result   = userManager.Create(user2, password);
            if (result.Succeeded)
            {
                userManager.AddToRole(user2.Id, role3.Name);
            }

            base.Seed(context);
        }