public PlatformRepository_EF()
 {
     context = new PolitiekeBarometerContext();
 }
Exemplo n.º 2
0
        private void CreateUserAndRoles()
        {
            PolitiekeBarometerContext context = new PolitiekeBarometerContext();
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

            if (!roleManager.RoleExists("SuperAdmin"))
            {
                var role = new IdentityRole("SuperAdmin");
                roleManager.Create(role);

                var user = new ApplicationUser();
                user.Name           = "Thomas Somers";
                user.UserName       = "******";
                user.Email          = "*****@*****.**";
                user.EmailConfirmed = true;

                user.Gebruiker = new Gebruiker()
                {
                    Email       = user.Email,
                    GebruikerId = user.Id,
                    Naam        = user.Name
                };
                string pwd = "ThomasSuperAdmin20";

                var newuser = userManager.Create(user, pwd);
                if (newuser.Succeeded)
                {
                    userManager.AddToRole(user.Id, "SuperAdmin");
                }
            }

            if (!roleManager.RoleExists("AdminPolitiek"))
            {
                var role = new IdentityRole("Admin" + "Politiek");
                roleManager.Create(role);

                var user = new ApplicationUser();
                user.Name           = "Thomas Admin";
                user.UserName       = "******";
                user.Email          = "*****@*****.**";
                user.EmailConfirmed = true;
                string pwd = "ThomasAdmin20";
                user.Gebruiker = new Gebruiker()
                {
                    Email       = user.Email,
                    GebruikerId = user.Id,
                    Naam        = user.Name
                };
                var newuser = userManager.Create(user, pwd);
                if (newuser.Succeeded)
                {
                    userManager.AddToRole(user.Id, "AdminPolitiek");
                }

                var gewoneGebruiker = new ApplicationUser();
                gewoneGebruiker.Name           = "Sam";
                gewoneGebruiker.UserName       = "******";
                gewoneGebruiker.Email          = "*****@*****.**";
                gewoneGebruiker.EmailConfirmed = true;
                string gebruikerPW = "SamUser";
                gewoneGebruiker.Gebruiker = new Gebruiker()
                {
                    Email       = gewoneGebruiker.Email,
                    GebruikerId = gewoneGebruiker.Id,
                    Naam        = gewoneGebruiker.Name
                };
                var User = userManager.Create(gewoneGebruiker, gebruikerPW);
            }
        }
Exemplo n.º 3
0
        public ActionResult CreateDeelplatform(FormCollection form)
        {
            Deelplatform deelplatform = new Deelplatform()
            {
                Naam              = form["txtNaam"],
                PersoonString     = form["txtPersoonstring"],
                OrganisatieString = form["txtOrganisatiestring"],
                ThemaString       = form["txtThemastring"],
            };
            var          roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(PolitiekeBarometerContext.Create()));
            IdentityRole adminRole   = new IdentityRole("Admin" + deelplatformURL);

            roleManager.Create(adminRole);
            IPlatformManager platformManager = new PlatformManager();

            platformManager.createDeelplatform(deelplatform);

            return(RedirectToAction("LijstDeelplatformen"));
        }
 public ElementRepository_EF()
 {
     context = new PolitiekeBarometerContext();
 }
 public ElementRepository_EF(UnitOfWork unitOfWork)
 {
     context = unitOfWork.Context;
 }
 public PostRepository_EF(UnitOfWork unitOfWork)
 {
     context = unitOfWork.Context;
 }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            Uri url = HttpContext.Current.Request.Url;

            var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(PolitiekeBarometerContext.Create()));
            var user        = System.Web.HttpContext.Current.User.Identity;

            string[] segments     = url.AbsolutePath.Split('/');
            string   deelplatform = segments[1];

            if (user.IsAuthenticated)
            {
                var roles = userManager.GetRoles(user.GetUserId());
                if (roles.Contains("SuperAdmin") || roles.Contains("Admin" + deelplatform))
                {
                    base.OnActionExecuting(filterContext);
                }
                else
                {
                    filterContext.Result = new RedirectResult("/" + deelplatform + "/Error/AdminError");
                }
            }
            else
            {
                filterContext.Result = new RedirectResult("/" + deelplatform + "/Account/Login");
            }
        }
Exemplo n.º 8
0
 public DashboardRepository_EF(UnitOfWork unitOfWork)
 {
     context = unitOfWork.Context;
 }
Exemplo n.º 9
0
 public DashboardRepository_EF()
 {
     context = new PolitiekeBarometerContext();
 }
 public PlatformRepository_EF(UnitOfWork unitOfWork)
 {
     context = unitOfWork.Context;
 }