Copied to clipboard

Flag this post as spam?

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


  • Euge 23 posts 130 karma points
    Jun 17, 2013 @ 15:58
    Euge
    0

    List all currently logged in members

    Hi

    What approach would I need to list all currently logged in members?

    I know there is a method that returns the current count

    public override int GetNumberOfUsersOnline()
    {
    return umbraco.cms.businesslogic.member.Member.CachedMembers().Count;
    }

    However I wish to display a list of currently logged in member details

     

    Thanks

     

     

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jun 17, 2013 @ 16:53
    David Brendel
    0

    I think you can do that by using the Membership Api.

    Would be something like that i think:

    List<MembershipUser> onlineUsers =newList<MembershipUser>();
    foreach(MembershipUser user in Membership.GetAllUsers()){ if(user.IsOnline){ onlineUsers.Add(user);}}

    With the ProviderUserKey you can than create the Umbraco Member with: var member = new Member(id);

    Hope that is want you've been looking for.

  • Euge 23 posts 130 karma points
    Jun 18, 2013 @ 12:03
    Euge
    0

    OK thanks for your reply; I tried the following and it appears to list all of my previous logins and not just my current session.

     

        List<MembershipUser> onlineUsers = new List<MembershipUser>();

        foreach (MembershipUser ServiceAdvisorUser in Membership.GetAllUsers())

        {

            if (ServiceAdvisorUser.IsOnline)

            {

                onlineUsers.Add(ServiceAdvisorUser);

            }

        }    

        

        @*loop through and create umbraco members*@

        List<Member> UmbracoLoggedInUsers = new List<Member>();

        foreach(MembershipUser loggedInUser in onlineUsers)

        {

            Member member = new Member((int)loggedInUser.ProviderUserKey); // Umbraco Member class        

            UmbracoLoggedInUsers.Add(member);

        }

     

    In addition I did the same approach using 

     @foreach(Member loggedInMemberToDisplay in umbraco.cms.businesslogic.member.Member.CachedMembers())

    However this is returning zero

     

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jun 18, 2013 @ 13:35
    David Brendel
    0

    I will try it again. But it seems that it should in general work.

    One thing i discovered is that Membershit.GetAllUsers() also returns the users and not only the members.

    So maybe using Member.GetAllAsList().Where(x => x.MemberType == yourmembertype); would be the better choice.

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Jun 19, 2013 @ 09:34
    David Brendel
    0

    Ok after a few hours research and testing here are my results:

    The MembershipUser.IsOnline just checks if the LastActivityDate is greater than current time - OnlyTimeWindow.

    The LastActivityDate is set when using CreateUser, UpdateUser and ValidateUser. Also it can be set by using GetUser(object,bool) where the bool value indicates if the date should be updated.

    After I looked at the umbraco code i saw no point where the boolvalue is actually used, so the LastActivityDate never gets updated.

    Also I tried so set the value manually on login/logout but after 30 minutes the users still was "online".

    So as a result i think the IsOnline property just always returns true.

    Maybe that should be added to the issue tracker.

    If someone else has a working method I would be glad to here it.

  • Euge 23 posts 130 karma points
    Jun 20, 2013 @ 11:05
    Euge
    0

    Thanks for your post David - I will keep digging and post if I come up with a solution.

Please Sign in or register to post replies

Write your reply to:

Draft