private static void CreateCmsDefaultRoles(NccDbContext nccDbContext, RoleManager <NccRole> roleManager) { var nccPermissionService = new NccPermissionService(new NccPermissionRepository(nccDbContext), new NccPermissionDetailsRepository(nccDbContext)); var administrator = CreatePermissionObject("Administrator"); var manager = CreatePermissionObject("Manager"); var editor = CreatePermissionObject("Editor"); var author = CreatePermissionObject("Author"); var contributor = CreatePermissionObject("Contributor"); var subscriber = CreatePermissionObject("Subscriber"); nccPermissionService.Save( new List <NccPermission>() { administrator, manager, editor, author, contributor, subscriber } ); NccRole superAdmin = new NccRole() { Name = NccCmsRoles.SuperAdmin, NormalizedName = NccCmsRoles.SuperAdmin }; var sa = roleManager.CreateAsync(superAdmin).Result; }
public static async Task <NccUser> CreateSuperAdminUser( NccDbContext nccDbContext, UserManager <NccUser> userManager, RoleManager <NccRole> roleManager, SignInManager <NccUser> signInManager, WebSiteInfo setupInfo ) { CreateCmsDefaultRoles(nccDbContext, roleManager); NccRole superAdmin = await roleManager.FindByNameAsync(NccCmsRoles.SuperAdmin); if (superAdmin != null) { var adminUser = new NccUser() { Email = setupInfo.Email, FullName = "Site Super Admin", Name = "Super Admin", UserName = setupInfo.AdminUserName, }; await userManager.CreateAsync(adminUser, setupInfo.AdminPassword); NccUser user = await userManager.FindByNameAsync(setupInfo.AdminUserName); await userManager.AddToRoleAsync(user, NccCmsRoles.SuperAdmin); return(user); } return(null); }
public static async Task <NccUser> CreateSuperAdminUser( UserManager <NccUser> userManager, RoleManager <NccRole> roleManager, SignInManager <NccUser> signInManager, WebSiteInfo setupInfo ) { CreateCmsDefaultRoles(roleManager); NccRole admin = await roleManager.FindByNameAsync(NccCmsRoles.Administrator); var adminUser = new NccUser() { Email = setupInfo.Email, FullName = "Site Admin", Name = "Administrator", UserName = setupInfo.AdminUserName, }; await userManager.CreateAsync(adminUser, setupInfo.AdminPassword); NccUser user = await userManager.FindByNameAsync(setupInfo.AdminUserName); await userManager.AddToRoleAsync(user, NccCmsRoles.SuperAdmin); return(user); }
protected override NccUserRole CreateUserRole(NccUser user, NccRole role) { return(new NccUserRole() { UserId = user.Id, RoleId = role.Id }); }
private static void CreateCmsDefaultRoles(RoleManager <NccRole> roleManager) { NccRole superAdmin = new NccRole() { Name = NccCmsRoles.SuperAdmin, NormalizedName = NccCmsRoles.SuperAdmin }; NccRole administrator = new NccRole() { Name = NccCmsRoles.Administrator, NormalizedName = NccCmsRoles.Administrator }; NccRole author = new NccRole() { Name = NccCmsRoles.Author, NormalizedName = NccCmsRoles.Author }; NccRole contributor = new NccRole() { Name = NccCmsRoles.Contributor, NormalizedName = NccCmsRoles.Contributor }; NccRole editor = new NccRole() { Name = NccCmsRoles.Editor, NormalizedName = NccCmsRoles.Editor }; NccRole subscriber = new NccRole() { Name = NccCmsRoles.Subscriber, NormalizedName = NccCmsRoles.Subscriber }; //NccRole reader = new NccRole() { Name = NccCmsRoles.Reader, NormalizedName = NccCmsRoles.Reader }; var sa = roleManager.CreateAsync(superAdmin).Result; var a = roleManager.CreateAsync(administrator).Result; var au = roleManager.CreateAsync(author).Result; var c = roleManager.CreateAsync(contributor).Result; var e = roleManager.CreateAsync(editor).Result; var s = roleManager.CreateAsync(subscriber).Result; //roleManager.CreateAsync(reader); }
protected override IdentityRoleClaim <long> CreateRoleClaim(NccRole role, Claim claim) { return(new IdentityRoleClaim <long> { RoleId = role.Id, ClaimType = claim.Type, ClaimValue = claim.Value }); }