Copied to clipboard

Flag this post as spam?

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


  • Doogie Talons 183 posts 318 karma points
    Oct 16, 2015 @ 00:06
    Doogie Talons
    0

    Assigning Member Group on Member Creation

    Been looking all over for a solution to this.

    Using the new var registerModel = Members.CreateRegistrationModel();

    Basicall on an order confirmation page I want to allow the person to create themselves as a memeber by using the existing parameters and entering a password.

    I want them to have instant access to a member group.

    I can get them registered without custom properties (I'll get to that later)

    But what I can't do is assing them to a group.

    Is there any way to do this in the control "Register Member" which is supplied with umbraco.

    Also..

    In the script it itterates through custom properties. With the following.

     @if (registerModel.MemberProperties != null)
                {
                    for (var i = 0; i < registerModel.MemberProperties.Count; i++)
                    {
                        @Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.MemberProperties[i].Name)
                        @* 
                            By default this will render a textbox but if you want to change the editor template for this property you can 
                            easily change it. For example, if you wanted to render a custom editor for this field called "MyEditor" you would
                            create a file at ~/Views/Shared/EditorTemplates/MyEditor.cshtml", then you will change the next line of code to 
                            render your specific editor template like:
                            @Html.EditorFor(m => profileModel.MemberProperties[i].Value, "MyEditor")
                        *@
                        @Html.EditorFor(m => registerModel.MemberProperties[i].Value)
                        @Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
                        <br />
                    }
                }
    

    Hoever I want to simply fill in two fields memberFirstName and memberLastName.

    I can't work out how to just edit the fields by thier alias name

    LIKE...

     @if (registerModel.MemberProperties != null)
                {
    
     @Html.HiddenFor(m => registerModel.MemberProperties.Alias("memberFirstName"), new {@Value = @memFirstName})
    
    
                }
    

    Obvioulsy that doenst work but is there anyway to send the data directly without the form fields in the itteration.

    Kind Regards

    Doogie

  • Marc Goodson 1622 posts 10744 karma points MVP 6x c-trib
    Oct 18, 2015 @ 23:55
    Marc Goodson
    103

    Hi Doogie

    If you have access to the MemberService

    var memberService = Services.MemberService;
    

    The you should be able to create a new member with

    var member = memberService.CreateMemberWithIdentity("username","emailaddress","name of user", "aliasOfMemberType");
    

    then set any custom properties using

    member.SetValue("superCustomProperty", "valuetoset");
    

    then assign that member to a group/role using:

    memberService.AssignRole(member.Username,"Custom Member Group");
    

    Then save the member:

    memberService.Save(member);
    

    and set their password:

    memberService.SavePassword(member,"theirpassword");
    

    and finally log them in:

    Members.Login("theirusername", "theirpassword");
    

    if that helps give you a bit of a steer ?

    https://our.umbraco.org/documentation/reference/management/services/memberservice

    regards

    Marc

  • Doogie Talons 183 posts 318 karma points
    Oct 20, 2015 @ 16:20
    Doogie Talons
    0

    So to take so long to reply.

    Using your post I have completed the task

    Thankyou very much

    Doogie

  • Liam Dilley 103 posts 271 karma points
    Jun 29, 2021 @ 06:10
    Liam Dilley
    0

    Old post but something still valid.

    • Not part of this thread but never try to set the password for a member before saving the member. It wont set it otherwise. Save the member then the password.
    • Relevant here - Make sure you do the save password as the last data update in your code. If you have say the member group setting code after the savePassword it wont assign the member group.
Please Sign in or register to post replies

Write your reply to:

Draft