Copied to clipboard

Flag this post as spam?

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


  • Mathias Andreasen 43 posts 155 karma points
    Jan 08, 2016 @ 10:30
    Mathias Andreasen
    0

    Changing member login name programmatically

    Hello first time umbracian here, making my debut on the forums! ;)

    Im building a web shop wherein retailers have the possiblity to edit and update their customers, I've built a standard form where the retailer can change member properties for their customer like name, email, shipping information and so on, but I can't find a way to programmatically change the member's login name.

    Im retrieving the member using the MemberService found in Umbraco.Core but can't find no way to get/set the login name.

    Code snippet:

            // Update umbraco member
            var member = Services.MemberService.GetByUsername(customer.LoginName);
            member.SetValue("firstName", model.FirstName);
            member.SetValue("lastName", model.LastName);
            member.Email = model.Email;
            // change member login to match member email (email is login name)
            Services.MemberService.Save(member);
    

    I did some searching on the forums before I decided to create this post and most topics were a couple of years of old and didn't provide a solid answer to this question, maybe some of the more seasoned Umbraco devs could help me out?

    // Mathias

  • Ryan 34 posts 138 karma points
    Jan 08, 2016 @ 10:50
    Ryan
    102

    Hi, hopefully this helps.

    var member = Services.MemberService.GetByusername(customer.LoginName);
    member.Username = "new value";
    Services.MemberService.Save(member);
    

    I'm pretty sure that will change the members login to the value set for the username.

  • Mathias Andreasen 43 posts 155 karma points
    Jan 08, 2016 @ 13:04
    Mathias Andreasen
    0

    Thanks a lot buddy, i feel silly that i didn't spot that myself :S

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies