Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Walter 9 posts 29 karma points
    Sep 24, 2009 @ 16:32
    Walter
    0

    Controls/package question

    Hi,

    i currently run a local version of umbraco 4.0.2.1. I also work as an intern at a small software development company in holland and they want a new website that is developed with umbraco.

    The problem is i'm busy with creating some controls and i know how to get them to work in umbraco and also know how to create my own package and use it on other umbraco installs. I created a register controll and whithin that register control the user can put in a redirection page and in wich role the user should be put. This is working. But to made this work i had to first make a member group and member type and had to change the defaultMemberTypeAlias of  UmbracoMembershipProvider in the web.config.

    My question:

    Is there a way to make it go automaticly that when you install the package that i'm creating, it automaticly creates the member groups and types and edits the defaultMemberTypeAlias of  UmbracoMembershipProvider in the web.config?

    I hope i made my question understandable since it was kinda hard for me to formulate it in the right way.

    Dutch greets,

    Walter

  • Chris Koiak 700 posts 2626 karma points
    Sep 24, 2009 @ 16:39
    Chris Koiak
    0

    Hi Walter,

    You can specify a usercontrol you want the package to load once the install is compelte. In this usercontrol you could perform the API calls to create the member types, members, etc.

    Here's some code to get you started (find the full source in http://our.umbraco.org/projects/clientarea)

            protected void Page_Load(object sender, EventArgs e)
    {

    // Create Type
    MemberType newType = MemberType.MakeNew(getUser(), "Client");
    newType.Save();

    // Create Groups
    MemberGroup newGroup1 = MemberGroup.MakeNew("Client", getUser());
    MemberGroup newGroup2 = MemberGroup.MakeNew("Client1", getUser());
    MemberGroup newGroup3 = MemberGroup.MakeNew("Client2", getUser());

    newGroup1.Save();
    newGroup3.Save();
    newGroup3.Save();

    // Create Members
    CreateMember("client1.user1", new string[] { "Client", "Client1" });
    CreateMember("client1.user2", new string[] { "Client", "Client1" });
    CreateMember("client2.user1", new string[] { "Client", "Client2" });

    // Add Public Permissions
    XPathNodeIterator iterator = umbraco.library.GetXmlNodeByXPath("//node[@nodeName='Client Area']");
    iterator.MoveNext();
    string clientAreaId = iterator.Current.GetAttribute("id","");

    iterator = umbraco.library.GetXmlNodeByXPath("//node[@nodeName='Login']");
    iterator.MoveNext();
    string loginPageId = iterator.Current.GetAttribute("id", "");

    iterator = umbraco.library.GetXmlNodeByXPath("//node[@nodeName='Insufficent Access']");
    iterator.MoveNext();
    string errorPageId = iterator.Current.GetAttribute("id", "");

    MemberGroup clientGroup = MemberGroup.GetByName("Client");
    MemberGroup client1Group = MemberGroup.GetByName("Client1");
    MemberGroup client2Group = MemberGroup.GetByName("Client2");

    Node clientArea = new Node(Convert.ToInt32(clientAreaId));
    Access.ProtectPage(false, clientArea.Id, Convert.ToInt32(loginPageId), Convert.ToInt32(errorPageId));
    foreach (Node childNode in clientArea.Children)
    {
    Access.ProtectPage(false, childNode.Id, Convert.ToInt32(loginPageId), Convert.ToInt32(errorPageId));
    }

    Access.AddMembershipRoleToDocument(clientArea.Id, "Client");
    Access.AddMembershipRoleToDocument(clientArea.Children[0].Id, "Client1");
    Access.AddMembershipRoleToDocument(clientArea.Children[1].Id, "Client2");

    }

    private void CreateMember(string username, string[] groups)
    {
    MemberType memType = MemberType.GetByAlias("Client");
    Member newMember = Member.MakeNew(username, username + "@test.com", memType, getUser());
    newMember.Password = "password";

    //Proceed for each new node fom supplied xmlData
    foreach (string groupAlias in groups)
    {
    MemberGroup group = MemberGroup.GetByName(groupAlias);
    newMember.AddGroup(group.Id);
    }

    newMember.Save();
    }


    private User getUser()
    {
    int id = BasePage.GetUserId(BasePage.umbracoUserContextID);
    id = (id < 0) ? 0 : id;
    return User.GetUser(id);
    }
  • Chris Koiak 700 posts 2626 karma points
    Sep 24, 2009 @ 16:41
    Chris Koiak
    0

    You could always split the above code into package actions, this would be the nicer approach.

    However, I believe there's an issue at the moment with specifying your own PackageActions; you need to copy the dll into the bin before installing the package... not ideal.

    Chris

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Sep 24, 2009 @ 16:41
    Douglas Robar
    0

    Hi, Walter,

    Makes perfect sense. What you want to do is include some Package Actions in your package that will update the web.config and also makes some member types and groups. See these for info and details...

    http://umbraco.org/documentation/books/package-actions-reference

    http://umbraco.org/assets/package%20actions.pdf

    http://packageactioncontrib.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28296

     

    cheers,
    doug.

  • Walter 9 posts 29 karma points
    Sep 24, 2009 @ 16:45
    Walter
    0

    Hi,

    Thnx for the quick reply. Gonna test this out when i'm comming home(i'm creating everything on my laptop) since its almost time to go home here.

    Will post my results when i tried it here in the topic.

    Thnx again for the quick answer.

  • Walter 9 posts 29 karma points
    Sep 25, 2009 @ 09:44
    Walter
    0

    Heyy All,

    i tried with the package actions and i know now how to use them to create member types(very easy if you understand how it works =)), but i can't seem to find a way to change defaultMemberTypeAlias="TestType" From the umbracomembershipprovider To defaultMemberTypeAlias="Gebruiker" in the umbracomembershipprovider in the web.config file through package actions, Must i do this through c# code in a web user control? .

     Thank you all for your help. Greets Walter

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 25, 2009 @ 10:04
    Dirk De Grave
    0

    Hi Walter, 

    you should do this through a package action. It would read the membership provider from web.config, change the defaultMemberType attribute and save the web.config again.

    Have a look at the packageactionscontrib project on Codeplex for some inspiration on building such a package action.

     

    Cheers,

    /Dirk

     

     

  • Chris Koiak 700 posts 2626 karma points
    Sep 25, 2009 @ 10:46
    Chris Koiak
    0

    Hi Walter,

    As Dirk mentions there are packageActions that project that edit the webconfig. Hopefully you can use some of that code as a starting point.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 25, 2009 @ 10:55
    Richard Soeteman
    0

    Hi Walter,

    I would also go for the package action option. It's really simple to implement. I have the same suggestion as Dirk, download the package action contrib  source code and documentation. In the documentation you'll find a link to the Package Action Tester, an awesome tool to test Package actions.

    Then you need a little basic understanding how to read xml and update web.config properties. This is done in the AddAppConfigKey Action of the project.

    What I would like to have in the PackageActionsContrib project is a way to update all the properties for a MembershipProvider (not just the defaultMemberTypeAlias  ). Don't know if you are allowed to include your code into an open source project. I hope you are:) I can help you with building it offcourse.

    Cheers,

    Richard

     

     

  • Walter 9 posts 29 karma points
    Sep 25, 2009 @ 11:23
    Walter
    0

    So basicly i need to create my own package action like the ones in the package action contrib source that will enable to change the value;

    Thnx guys.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 25, 2009 @ 11:33
    Richard Soeteman
    0

    Hi Walter,

    Yes that is all you need to do

    Cheers,

    Richard

  • Walter 9 posts 29 karma points
    Sep 25, 2009 @ 11:36
    Walter
    0

    Doing a bit c# coding of my own, i found out the following code allowed me to change the defaultMembertypeAlias:

     

     

     

     

     

     

     

     

    protected void Button1_Click(object sender, EventArgs e)

    {

     

    Modify(Label1.Text,TextBox1.Text);

     

    }

     

    public void Modify(string key, string value)

    {

     

          Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~");

     

          MembershipSection membershipSection = (MembershipSection)configuration.GetSection("system.web/membership");

     

          if (membershipSection != null)

             {

                 membershipSection.Providers[

    "UmbracoMembershipProvider"].Parameters.Set(key,value);

                configuration.Save();

             }

    }

     

  • Walter 9 posts 29 karma points
    Sep 25, 2009 @ 16:44
    Walter
    0

    Something weird is happening to my macro's. I created a register macro for my page, whenever i put it in my page en publish it for the first time, the macro is fine, but whenever i save it later again, cause of a litle change, my macro becomes a normal register table.

    I used the .net register component for my controll.

    does some one know if this is a bug or is something wrong with my register control? i tried a fresh register controll couple of times.

    I'm developing my user control in vs 2008 with asp.net 3.5

    thnx in advance

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Sep 25, 2009 @ 22:27
    Richard Soeteman
    0

    Hi Walter,

    It's better to create a seperate issue for this so the subject makes more sense for the problem you are having.

    Cheers,

    Richard

  • Walter 9 posts 29 karma points
    Sep 28, 2009 @ 08:59
    Walter
    0

    OKey i will do that.

     

Please Sign in or register to post replies

Write your reply to:

Draft