Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Apr 11, 2011 @ 13:32
    Dan
    0

    Timestamp of member log-ins

    Hi,

    I'm implementing a system which needs to log a timestamp against a member id each time the member logs in.  I might then produce a custom section (or probably more likely a new tab in the members section) containing an output of this data.

    I realise there are several ways that the timestamp log could be done, so I thought I'd ask people's opinion of the best one.  Am I best setting up a custom table, or should I use some kind of custom data type?

    Thoughts welcome...

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Apr 11, 2011 @ 14:18
    Michael Latouche
    1

    Hi Dan,

    Basically, you could just use the default UmbracoMembershipProvider to log the last login date: you can define specific properties of your MemberType to map against the standard "Asp.Net membership Provider" properties. See this link for more info: http://our.umbraco.org/wiki/how-tos/membership-providers/umbracomembershipprovider-properties.

    What you will need to do is define a property on your MemberType, e.g. LastLogin, and then map it to your membership provider definition in the web.config file

     umbracoLastLoginPropertyTypeAlias="LastLogin"

    If you then go to the Members section of the Umbraco admin, you will see that each member has this property defined, and set to his/her last login date. So, as far as I understand your issue, no custom table or data type needed here :-)

    Hope this helps.

    Cheers,

    Michael.

  • Dan 1288 posts 3921 karma points c-trib
    Apr 11, 2011 @ 14:25
    Dan
    0

    Thanks Michael, but isn't that just going to record the last log-in?  What I need is to log each log-in so for each member the administrator can see a list of each log-in that member has made.

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Apr 11, 2011 @ 15:07
    Michael Latouche
    0

    Hi Dan,

    So I did misunderstand your issue :-S It will indeed only hold the last login, not the login history.

    I guess the most "Umbraco-friendly" solution would then be to create (or find an existing) a custom data type that can hold a list of dates or something like that, which you can then assign as property to your member type, and fill in the "logged in" event of your login form.

    Cheers,

    Michael.

  • Dan 1288 posts 3921 karma points c-trib
    Apr 11, 2011 @ 18:26
    Dan
    100

    Just for the record, I found a data-type in uComponents which stores multiple dates as a comma-separated string.  Since I don't actually need the data type (I just need the log) I implemented a basic version of this of my own, just using a string to store comma-separated dates which updates on the membership log-in event.  It's basic, but that's all I need.

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Apr 12, 2011 @ 00:46
    Michael Latouche
    0

    Hi Dan,

    Glad you sorted it out. I had actually thought about something similar, but then thought it might not be enough for what you needed :-)

    Cheers,

    Michael.

  • Lasse Kofoed 49 posts 177 karma points
    Jul 15, 2013 @ 13:47
    Lasse Kofoed
    0

    Hi Dan,

    How did you end up solving this ?

     

  • Dan 1288 posts 3921 karma points c-trib
    Jul 15, 2013 @ 14:14
    Dan
    0

    Hi Lasse,

    I'd happily send you the code but I have no idea which project this was for - it was quite a long time ago.  What it sounds like I did was just create a property on the member type, which was a uComponents multiple-date datatype, and append a new record (date/time stamp) to that each time a member logged in, via the member log-in event.  I'm not a .NET dev so it must have been pretty simple ;)

    If you're having difficulty with this let me know and I'll try to track the code down later this week, but I've had a quick scan and really can't remember where I'd done this (it may even be code that's been superseeded by something else since)

  • Lasse Kofoed 49 posts 177 karma points
    Jul 15, 2013 @ 14:24
    Lasse Kofoed
    1

    Thank you for replying so fast.

    That is exactly what i had plan on doing, from your thoughts above.

    When done i will post the source here, so that others can benefid for your idea. 

    Thanks again

  • Lasse Kofoed 49 posts 177 karma points
    Jul 15, 2013 @ 16:20
    Lasse Kofoed
    1

    Had to do this in a hurry, and there where was no ex. on the http://ucomponents.codeplex.com/wikipage?title=MultipleDates to read or write the control from .net. So ended up just putting it to a string and apending on that.

    Remember to change the provider in the web.config

    Old entry in web.config

      <!--<add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Alumni" passwordFormat="Hashed"  umbracoLastLoginPropertyTypeAlias="last_login" />-->

    New entry

    <add name="UmbracoMembershipProvider" type="Alumni.Web.events.CustomUsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Alumni" passwordFormat="Hashed"  umbracoLastLoginPropertyTypeAlias="last_login" />
    
     

     public class CustomUsersMembershipProvider : umbraco.providers.members.UmbracoMembershipProvider
        {
            public override bool ValidateUser(string username, string password)
            {
                var success = base.ValidateUser(username, password);
     
                if (success)
                {
    /* This is customcode, the AlumniMember object is a Profile member createde i the profile section of the web.config
                    var aMember = new AlumniMember(username, string.Empty);
                    aMember.LoginHistory += DateTime.Now + " | ";
                    aMember.SaveChanges();
                }
     
                return success;
            }
        }
     
     

  • Moran 285 posts 934 karma points
    Dec 14, 2013 @ 10:38
    Moran
    0

    Hi Can you add the code for the member type you created? I am trying to create the same log history and figure out how to do it. Thanks

Please Sign in or register to post replies

Write your reply to:

Draft