Developer forum

Forum » Templates » When was extranet user last logged in prior to this login

When was extranet user last logged in prior to this login

Hans Ravnsfjall
Hans Ravnsfjall
Reply

Hi

Is it possible to get info about a current logged in extranet user, and when he/she was last logged in, prior to this current session?

Is it possible to get this info, in a template? If so, how can this be achieved?

/Hans


Replies

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Is this possible? :)

 
Nicolai Pedersen
Reply

You can find it in [StatExtranet] table in the database.

If you are using the new "Tracking" feature in DW, you can find it in "TrackingEvent" table with the EventName being "User.Login" and the [TrackingEventEntityKey] being the userid.

 

 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Ok, perfect

How could I implement this in Template?

Any example on how this could be accessed?

/Hans

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Something like this:

@{ 
        if(Model.CurrentUser != null)
        {
            DateTime? lastlogin = null;
            using (var reader = Dynamicweb.Data.Database.CreateDataReader(String.Format("SELECT TOP (1) [StatExtranetTimeStamp] FROM [StatExtranet] where [StatExtranetAccessUserID] = {0} order by [StatExtranetTimeStamp] desc", Model.CurrentUser.ID)))
            {
                if (reader.Read())
                {
                    lastlogin = Dynamicweb.Core.Converter.ToNullableDateTime(reader["StatExtranetTimeStamp"], null);
                }
            }
            if (lastlogin.HasValue)
            {
                <span>User last logged in: @lastlogin.Value.ToString("g")</span>
            }
            else
            {
                <span>Seems like you have never logged in before. Welcome!</span>
            }
        }
    }
Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Fantastic Nicolai, thank you 👍🏻

 

You must be logged in to post in the forum