I want to disable all Umbraco users, that are inactive for a certain periode of time. Like 3 months etc. Is doesn't look like there are any login timestamps in the database. Users logins are registered in the logfiles.
Is this the only way?
I've created a small powershell snippet to extract user IDs of users logged in, and build up a query to disable all others.
Is this really the only way?? (Works fine btw.)
Script:
$DiscoveredUserIds = @()
$value = 0
$LoginEvents = Get-ChildItem "UmbracoTraceLog.txt.2015-08-18" | Get-Content | Where { ($_).Contains("User Id:") }
Foreach ($LoginEvent in $LoginEvents)
{
Write-Host "Testing $LoginEvent"
$found = $LoginEvent -match '.*User Id: (\d+) logged in.*'
if ($found)
{
if ( [int]::TryParse( $matches[1], [ref]$value ) )
{
$DiscoveredUserIds += [int]$matches[1]
}
}
}
$ValidUsers = $DiscoveredUserIds | Sort-Object -Unique
$Query = "UPDATE [umbracoUser] SET userDisabled = 1, userNoConsole = 1 WHERE id NOT IN (0,"+ ($ValidUsers -Join ",")+ ")"
$Query
Output
PS E:\temp\kbrandenburg\umbracolog> C:\Users\kbrandenburg\Desktop\PowershellDisableUmbraco_users.ps1
Testing 2015-08-18 10:58:53,664 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 125] User Id: 5 logged in
Testing 2015-08-18 13:04:14,037 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 69] User Id: 5 logged in
Testing 2015-08-18 13:07:26,456 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 67] User Id: 4 logged in
Testing 2015-08-18 13:33:42,150 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 70] User Id: 4 logged in
Testing 2015-08-18 13:40:16,132 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 32] User Id: 10 logged in
Testing 2015-08-18 14:44:05,649 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 69] User Id: 4 logged in
UPDATE [umbracoUser] SET userDisabled = 1, userNoConsole = 1 WHERE id NOT IN (0,4,5,10)
Looking at that table it seems you are version lower than 7 because the defaultToLiveEditing column has been removed in that version.
I think in old versions there was also a table called umbracoUserLogins
Maybe you can get the information from there. I think loggins were also logged in the umbracoLog table in older versions. Maybe it's worth checking that as well.
umbracoUserLogins is empty. Found a github request, on that where the dev-team explained it was deprecated table, to be removed in future versions.
I'm fine with traversing logfiles for users, but how about actually disabling them. Doing a SQL query into the DB behind the app seems like a nasty solution. Is there an API i can use?
Disable inactive users
Hi,
I want to disable all Umbraco users, that are inactive for a certain periode of time. Like 3 months etc. Is doesn't look like there are any login timestamps in the database. Users logins are registered in the logfiles.
Is this the only way?
I've created a small powershell snippet to extract user IDs of users logged in, and build up a query to disable all others.
Is this really the only way?? (Works fine btw.)
Script:
Output
PS E:\temp\kbrandenburg\umbracolog> C:\Users\kbrandenburg\Desktop\PowershellDisableUmbraco_users.ps1 Testing 2015-08-18 10:58:53,664 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 125] User Id: 5 logged in Testing 2015-08-18 13:04:14,037 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 69] User Id: 5 logged in Testing 2015-08-18 13:07:26,456 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 67] User Id: 4 logged in Testing 2015-08-18 13:33:42,150 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 70] User Id: 4 logged in Testing 2015-08-18 13:40:16,132 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 32] User Id: 10 logged in Testing 2015-08-18 14:44:05,649 [10] INFO Umbraco.Web.Security.WebSecurity - [Thread 69] User Id: 4 logged in UPDATE [umbracoUser] SET userDisabled = 1, userNoConsole = 1 WHERE id NOT IN (0,4,5,10)
no response, really??
Hi Kasper,
Actually the umbracoUser table contains a column called [lastLoginDate]. This contains the last login date of the user.
Dave
Ours do not, the in the columns in UmbracoUser
[id] ,[userDisabled] ,[userNoConsole] ,[userType] ,[startStructureID] ,[startMediaID] ,[userName] ,[userLogin] ,[userPassword] ,[userEmail] ,[userDefaultPermissions] ,[userLanguage] ,[defaultToLiveEditing]
Looking at that table it seems you are version lower than 7 because the defaultToLiveEditing column has been removed in that version.
I think in old versions there was also a table called umbracoUserLogins
Maybe you can get the information from there. I think loggins were also logged in the umbracoLog table in older versions. Maybe it's worth checking that as well.
Dave
umbracoUserLogins is empty. Found a github request, on that where the dev-team explained it was deprecated table, to be removed in future versions.
I'm fine with traversing logfiles for users, but how about actually disabling them. Doing a SQL query into the DB behind the app seems like a nasty solution. Is there an API i can use?
What version are you using ? Depends on what version you are using.
Dave
is working on a reply...