In an attempt to keep track of when users have last logged in, I've put together a script that sets the date&time a user accesses the home page (view_49).
The "all users" object (object_4) is expanded with a short text field called "last login" (field_43).
// Set date & time a user accesses the home page // http://helpdesk.knackhq.com/support/solutions/articles/5000528001-working-with-the-logged-in-user#remote $(document).on("knack-view-render.view_49", function(event, view) { var user_rec_id=Knack.getUserAttributes().id; var api_url="https://api.knackhq.com/v1/objects/object_4/records/"+user_rec_id; var str=new Date().toString(); var data={field_43: str};$.ajax({
url: api_url,
type: “PUT”,
headers: {“X-Knack-Application-Id”:Knack_App_ID,“X-Knack-REST-API-Key”:API_Key},
data: data,
success: function(data, textStatus, xhr) {
console.log("Date set: "+data.field_43);
},
error: function(xhr) {
console.log("Error ! Status: “+xhr.status+” "+xhr.statusText);
}
}); // ajax
});
Â
So the script doesn’t actually track the last login but merely updates the “last login” field when a user accesses the home page. So is an indication only.
What are other people using to record last login ? Has anyone had more success ?
Cheers
Bart