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?
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 :-)
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.
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.
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.
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)
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; } }
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...
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
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.
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.
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.
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.
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.
Hi Dan,
How did you end up solving this ?
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)
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
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
New entry
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; } }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
is working on a reply...