Example #1
0
 public override void CreateRole(string roleName)
 {
     if (roleName.Contains(","))
     {
         throw new ArgumentException("Role names cannot contain commas.");
     }
     if (RoleExists(roleName))
     {
         throw new InvalidOperationException("Role name [" + roleName + "]already exists");
     }
     using (SecurityDAO secDAO = new SecurityDAO())
     {
         secDAO.CreateRole(new Role
         {
             Name = roleName,
             Description = ""
         });
     }
 }
Example #2
0
        public void Init(HttpApplication context)
        {
            if (!InsertDefaultDataOnInit) return;
            using (var db = new DbManager())
            {
                db.SetCommand("TRUNCATE TABLE Users_Roles").ExecuteNonQuery();
                db.SetCommand("TRUNCATE TABLE Menus_Roles").ExecuteNonQuery();
                db.SetCommand("TRUNCATE TABLE Menus").ExecuteNonQuery();
                db.SetCommand("TRUNCATE TABLE Users").ExecuteNonQuery();
                db.SetCommand("TRUNCATE TABLE Roles").ExecuteNonQuery();
            }

            using (var secDAO = new SecurityDAO())
            {
                secDAO.CreateRole("admins", "");

                secDAO.CreateUser("*****@*****.**", "admin", "admin");
                secDAO.AssignRoleToUser("admins", "admin");

                secDAO.CreateMenu("home", "_private/home.aspx");
                secDAO.AssignRoleToMenu("admins", "_private/home.aspx");
            }
        }