November Happy Hour will be moved to Thursday December 5th.

Find and delete inactive users

Vote:
 

Hi!

I am wondering if there is a smart way to find users who haven't logged in for, say, 1 year and delete these users programatically (Relate 2.0)?

What I've found so far is the OnlineStatusHandler.Instance.GetLastLogin() which takes a user as parameter However getting all users, looping through them and doing this check on each users feels inefficient. I was hoping there would be a way to query users based on their last login?

Thanks!
/Daniel

#77774
Nov 26, 2013 10:16
Vote:
 

I suppose you will need to query DB for that (this is pseudo code)..

1) collect all user ids who were loggedin just before your time window of interest

SELECT [intUserID] FROM [dbEPiCoopCommon].[dbo].[tblEPiServerCommunityOnlineStatus] WHERE datLoginDate < '2012-11-28'

    

2) Loop through and remove those

collectionOfIds.ForEach(id =>
{
    CommunitySystem.CurrentContext.DefaultSecurity.RemoveUser(
        CommunitySystem.CurrentContext.DefaultSecurity.GetUser(id));
})

    

You will need to do it on regular basis for sure to remove proper inactive users.

#77879
Nov 27, 2013 23:45
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.