Copied to clipboard

Flag this post as spam?

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


  • Colin Asquith 3 posts 35 karma points
    Mar 30, 2018 @ 11:55
    Colin Asquith
    0

    Loading unapproved Members and approving by token

    I'm using MemberService to create members for a website, which was working. I have a new requirement to add token based validation of a user, so the account is created setting IsApproved = false, waiting for a hit a Surface Controller with a valid token to approve the user.

    If the user is set IsApproved = false, then I can't load them up with memberService.GetByUsername(). I can load up the member with the MembershipHelper, but this provides me read-only access to member data.

    I can get around this by adding my own property IsValidated, but think that I am duplicating the work that Umbraco is already doing, so I think I am missing something. Is there a way to programmatically set IsApproved for existing members and use the in-built functionality?

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 30, 2018 @ 12:04
    Michaël Vanbrabandt
    100

    Hi Colin,

    when a members property IsApproved is set to false, it normally will also be taken by the method ´GetByUsername()´. If I look into the source code I don't see any checks for only returning the Member when he is approved.

    So normally using this code it would work:

    private IMemberService MemberService
    {
        get
        {
            return Services.MemberService;
        }
    }
    
    public void SetMemberApproved(string username) {
        var member = MemberService.GetByUsername(username);
    
        member.IsApproved = true;
    
        MemberService.Save(member);
    }
    

    Hope this helps.

    /Michaël

  • Colin Asquith 3 posts 35 karma points
    Mar 30, 2018 @ 12:08
    Colin Asquith
    1

    Thanks Michaël, looking further it seems to be some confusion between the properties that I was using for Login and Email which were two different values. I think my debugging lead me to a false conclusion, I've managed to get this working now.

    C

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Mar 30, 2018 @ 12:12
    Michaël Vanbrabandt
    0

    Colin,

    glad that you have solved it!

    Have a nice day and enjoy Umbraco!

    /Michaël

Please Sign in or register to post replies

Write your reply to:

Draft