Copied to clipboard

Flag this post as spam?

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


  • Patrick Shaun McNicholas 24 posts 206 karma points
    Apr 26, 2022 @ 16:14
    Patrick Shaun McNicholas
    0

    Getting members by userName or Email is not working.

    I've tried several different iterations of this same search query but I cannot find a member based on either userName or email. I assume it has something to do with the @ character in the search. I've also searched google and this forum and can't find anyone who has documented this process. I can find members quickly using any other property value except for the email address in the userName or the email fields.

    Does anyone know how to accomplish this search process? While using email as userName for members? This is my code, and when passing in an exact match for email address I cannot get any of the queries to return a matching member.

    long totalRecords;
    string methodUsed = "GetMembersByPropertyValue email";
    var membersList = memberService.GetMembersByPropertyValue("email",studentEmail.ToString().ToLower().Trim()); 
        membersList = membersList.Count() == 0 ? memberService.GetMembersByPropertyValue("userName",studentEmail.ToString().ToLower().Trim()) : membersList;
    if(firstName != null && firstName != "")
    {
        methodUsed = "GetMembersByPropertyValue firstName";
        membersList = memberService.GetMembersByPropertyValue("firstName",firstName.ToString().ToLower().Trim(), global::Umbraco.Core.Persistence.Querying.StringPropertyMatchType.Contains);
    }
    if(lastName != null && lastName != "")
    {
        methodUsed = "GetMembersByPropertyValue lastName";
        membersList = memberService.GetMembersByPropertyValue("lastName",lastName.ToString().ToLower().Trim(), global::Umbraco.Core.Persistence.Querying.StringPropertyMatchType.Contains);
    }
    if(studentID != null && studentID != "")
    {
        methodUsed = "GetMembersByPropertyValue colleagueId";
        membersList = memberService.GetMembersByPropertyValue("colleagueId",studentID.ToString().ToLower().Trim(), global::Umbraco.Core.Persistence.Querying.StringPropertyMatchType.Contains);
    }
    if(membersList.Count() == 0 && studentEmail != "")
    {
        methodUsed = "GetMembersByPropertyValue userName";
        membersList = memberService.GetMembersByPropertyValue("userName",studentEmail.ToString().ToLower().Trim());
    }
    if(membersList.Count() == 0 && studentEmail != "")
    {
        methodUsed = "GetAllMembers userName || email";
        membersList = memberService.GetAllMembers().Where(x => x.GetValue("userName") == studentEmail || x.GetValue("Email") == studentEmail);
    }
    if(membersList.Count() == 0 && studentEmail != "")
    {
        methodUsed = "GetAll() userName || email";
        membersList = memberService.GetAll(0, 999, out totalRecords).Where(x => x.GetValue("Email") == studentEmail.ToString().ToLower().Trim() || x.GetValue("userName") == studentEmail.ToString().ToLower().Trim());
    }
    <div class="container-fluid">
        <div class="row overflow-auto">
            <h3>@membersList.Count() Members matching @Html.Raw(studentEmail) methodUsed: @methodUsed</h3>
            <table class="table table-striped table-bordered table-hover">
                <thead>
                    <tr>
                        <th>Umbraco ID</th>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>User Name</th>
                        <th>Email</th>
                        <th>Last Update</th>
                        <th>Time</th>
                        <th> </th>
                    </tr>
                </thead>
                <tbody>
                @foreach(var thisMember in membersList)
                {
                    var exsitingMember = Umbraco.MembershipHelper.GetById(thisMember.Id);
                    bool setColleagueId = false;
                    string existingPswd = exsitingMember != null ? exsitingMember.GetProperty("existingPasswordB64").GetValue().ToString() : String.Empty;
                    string existingPswdDecrypt = existingPswd != String.Empty ? FresnoUtilities.Classes.Base64Encode(existingPswd) : String.Empty;
                        <tr>
                            <td><a href="/umbraco/#/member/member/edit/@thisMember.Key" target="_blank">@thisMember.Id</a>
                            </td>
                            <td>
                                @exsitingMember.GetProperty("firstName").GetValue().ToString()
                            </td>
                            <td>
                                @exsitingMember.GetProperty("lastName").GetValue().ToString()
                            </td>
                            <td>
                                @exsitingMember.GetProperty("userName").GetValue().ToString()
                            </td>
                            <td>
                                @exsitingMember.GetProperty("email").GetValue().ToString()
                            </td>
                            <td>
                                @exsitingMember.UpdateDate.ToString("M/dd/yyyy")
                            </td>
                            <td>
                                @exsitingMember.UpdateDate.ToString("hh:mm tt")
                            </td>
                            <td>
                                @if(existingPswdDecrypt != String.Empty)
                                {
                                    <form method="post" target="_blank">
                                        <input type="hidden" name="userName" value="@exsitingMember.GetProperty("email").GetValue().ToString()">
                                        <input type="hidden" name="userPassword" value="@existingPswd">
                                        <input type="submit" name="loginAs" value="Login As">
                                    </form>
                                }
                            </td>
                        </tr>
                        }
                </tbody>
            </table>
        </div>
    </div>
    
  • Patrick Shaun McNicholas 24 posts 206 karma points
    May 06, 2022 @ 00:44
    Patrick Shaun McNicholas
    0

    OK I've had this question up for more than a week.... I can't believe this has received zero replies. Has no-one else needed to find a member using login or email address?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    May 06, 2022 @ 08:54
    Dave Woestenborghs
    0

    Hi Patrick,

    The more details you provide the easier it will be to get an answer.

    Maybe you can tell us which version of Umbraco you are using. And which line in the large code block it is that is not working.

    One thing I can recommend to you is not to use the memberservice. This service is meant to do CRUD operations on members and will bypass all caching Umbraco puts in place. If used incorrectly this can be a real perfomance hit on your website.

    You should be using https://our.umbraco.com/documentation/Reference/Querying/IMemberManager/ (V9) or https://our.umbraco.com/documentation/Reference/Querying/MemberShipHelper/ (V8)

    Both of them have methods to get a member by email.

    Dave

  • Patrick Shaun McNicholas 24 posts 206 karma points
    May 18, 2022 @ 16:29
    Patrick Shaun McNicholas
    0

    Sorry if what I'm asking is unclear. But the problem I am trying to solve is for an administration tool set that I am building for managing members within my site. I am currently running Umbraco version 8.13.0.

    I know with both the MemberService and the MembershipHelper I can Get a member based on an email address. But I am trying to do this using a search method so that I don't need to retrieve thousands of members in a list and then do a comparison between variables. I'm trying to do the comparison within the initial search function. So this line

    var membersList = memberService.GetAllMembers().Where(x.GetValue<string>("userName") != x.GetValue<string>("email")).OrderBy(x => x.UpdateDate);
    

    Should return a matching result when the userName does not match the email address, but I have physically gone in and changed the email address of my own membership profile and it does not return my account as a match and it should. I've taken it a step further and tried to just directly find a matching userName using var membersList = memberService.GetAllMembers().Where(x => x.GetValue<string>("userName") == "[email protected]").OrderBy(x => x.UpdateDate); but even this does not return a match to my membership profile. But it doesn't throw an error, so I assume that it should be able to find a match but it does not.

    This desire is for this to return a list of Members on the site who have given us a new email address on their membership profile page.

    The reason this is required is that our administration staff needs to see when someone does this so that they know to update other database systems within the network with this information.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    May 19, 2022 @ 06:20
    Dave Woestenborghs
    0

    Hi Patrick,

    Can you try this :

    var membersList = memberService.GetAllMembers().Where(x => x.Username != x.Email).OrderBy(x => x.UpdateDate);
    

    Dave

  • Patrick Shaun McNicholas 24 posts 206 karma points
    May 19, 2022 @ 18:23
    Patrick Shaun McNicholas
    0

    Yeah I've tried everything combination I can think of in that kind of comparison... I've found a way to just do a straight SQL query comparison since the members in the database is a plain table its the easiest method for now... just seems like a search based on the UserName should be a pretty straight forward process, you could also loop through all of the members and do a plain login attempt - but the cost is pretty extreme when you have thousands and thousands of members.

    This is the error when using the above x.UserName != x.Email 'IMember' does not contain a definition for 'UserName' and no accessible extension method 'UserName' accepting a first argument of type 'IMember' could be found (are you missing a using directive or an assembly reference?)

  • Patrick Shaun McNicholas 24 posts 206 karma points
    May 19, 2022 @ 19:31
    Patrick Shaun McNicholas
    0

    I just noticed a bug in the version of Umbraco that I'm currently using. In production I'm using Umbraco 8.15.1 Perhaps someone might be able to explain if this is a bug or by design. If I modify the UserName SQL(LoginName) from the Umbraco Admin backend, it doesn't seem to modify the cmsMember table. So if an administrator modifies the MemberShip profile in Umbraco it does appear to modify the property data on the profile, but doesn't modify the SQL table cmsMember

Please Sign in or register to post replies

Write your reply to:

Draft