Copied to clipboard

Flag this post as spam?

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


  • Deepali Bhola 23 posts 43 karma points
    Aug 01, 2012 @ 17:12
    Deepali Bhola
    0

    can we create custom feild in MemberType?

    i want to craete Login Register module in project.

    i have created Registration with  : UserName, Password, Email

    now i want to add more feild in registration form like mobile, address etc.

    my sample code is below:

                var mt = MemberType.GetByAlias(MembersType);
                var addToMemberGroup = MemberGroup.GetByName(MembersGroup);
              
                var m = Member.MakeNew(txtUsername.Text, mt, new User(0));
                m.Password = txtPassword.Text;
                m.Email = txtEmail.Text;

    can it be possible?

     

  • Richard Brookes 34 posts 57 karma points
    Aug 02, 2012 @ 01:40
    Richard Brookes
    1

    Hi Kamal,

    That is certainly possible with Umbraco. From your code snippet I see that you have already created a member type. This meber type is what holds the custom properties for your member. You can add extra properties to the member type exactly as you would with a document type.

    So having created a property "Mobile", "Street", "Suburb", "City" etc with the alias "mobileAlias" etc. you can set the values using

    m.getProperty("mobileAlias").Value = txtMobile.Text

    then remember to save your user m.Save();

    Having said all that Umbraco uses ASP.NETs membership provider so while your methods are perfectly fine (for now) you are encouraged to use Membership.CreateUser() etc in the System.Web.Security namespace. Take a look at this link http://our.umbraco.org/wiki/how-tos/membership-providers

    As for the prefered way to handle profiles Aaron Powell wrote this article which you might find useful. As I said the way you are doing it will work fine but those methods have been deprecated.

    http://www.aaron-powell.com/umbraco-members-profiles

    cheers

  • Deepali Bhola 23 posts 43 karma points
    Aug 03, 2012 @ 12:07
    Deepali Bhola
    0

    Thanks alot for reply, Its really helpful for me.

    i am new to umbraco, so can u explain me in detail, like:

    if i use Membership.CreateUser() as i checked in our.umbraco.org/wiki/how-tos/membership-providers, where i will pass these lines of code          

    var mt =MemberType.GetByAlias(MembersType);
    var addToMemberGroup =MemberGroup.GetByName(MembersGroup);

    and also:

    m.getProperty("mobileAlias").Value = txtMobile.Text (those custom property)

     

    Hope u understand my query..

     

  • Richard Brookes 34 posts 57 karma points
    Aug 03, 2012 @ 23:45
    Richard Brookes
    0

    Hi Kamal,

    When you use Membership.CreateUser() by default the MemberType is picked up from the web.config file. If you look in there you will find something like the extract below:

    <membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">

          <providers>

            <clear />

            <add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="YOUR MEMBER TYPE" passwordFormat="Hashed" />

            <add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" passwordFormat="Hashed" />

          </providers>

        </membership>

    You just need to set the default member type to the alias of your member type

    To add a member to a group you can use this line of code

    Roles.AddUserToRole(email, "YOUR MEMBER GROUP NAME");

    As for setting the property I can't really explain the ASP.NET profile provider any better than Aaron did in the link that I mentioned in my previous post. He gives a complete example in that post.

    If that seems like too much hard work you could use a kind of hybrid method where you revert to the Umbraco API to set the properties although this was kind of the point of using the ASP.NET providers in the first place.An example of this would be

    var email = txtEmail.Text;

    var member = Membership.GetUser(email);

    if (member == null)

     {

            //the member does not already exist

            member = Membership.CreateUser(txtUsername.Text, txtPassword.Text, email);

            if (member != null)

           {

                 //add the member to the correct role

                  Roles.AddUserToRole(email, "Allowed");

                 Member umbracoMember = new Member((int)member.ProviderUserKey);

                 if (umbracoMember != null)

                 {

                      //save the custom property

                      umbracoMember.getProperty("custom").Value = txtCustom.Text;

                      umbracoMember.Save();

                   }

           }

         }

  • Deepali Bhola 23 posts 43 karma points
    Aug 04, 2012 @ 11:14
    Deepali Bhola
    0

    Thanks Richard, You sloved my problem..

    now every thing is working.


     
Please Sign in or register to post replies

Write your reply to:

Draft