degmo
degmo

Reputation: 177

Create a sitecore admin website

A sitecore newbie here. We have an existing website that's built using Sitecore 8. It's live in our production environment. I recently joined the company and my background is backend .NET development. I have been asked to write a utility module that allows us to remove registered users that meet certain criteria. The website provides the ability for users to register and the registered users are stored in the core database. My initial thought was to go directly against the DB but quickly learned that the data stored is serialized. I also thought about writing a c# console application to do this but it appears that there are a lot of configuration/setup steps to do this and that it's better to do it from a web app. Does anyone have any tips on how I could set up a simple utility web application to connect to an existing Sitecore database? I expect that I will be asked to add more functions/features down the road.

Upvotes: 0

Views: 361

Answers (2)

Martin Miles
Martin Miles

Reputation: 2096

As i understood, the objective is to be able to remove certain users.

The easiest way to do that would be using Sitecore PowerShell module, but for you as a newbie that would not be probably as easy (and you would need to have module installed). With PowerShell module you don't even need to create user interface.

Here is the documentation how to do use Remove-User with PowerShell

If PowerShell option does not work for you, you can use that from the code utilising Sitecore API, so your Delete method would look something like below:

    public void DeleteUser(string userName)
    {
        try
        {
            Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName(userName, true);
            user.Delete();
        }
        catch (Exception ex)
        {
            Sitecore.Diagnostics.Log.Error(string.Format("Error in Client.Project.Security.UserMaintenance (DeleteUser): Message: {0}; Source:{1}", ex.Message, ex.Source), this);
        }            
    }

So you would just call this method when iterating usernames to be deleted. Depending on which credentials you would run that code, you may need to wrap it with SecurityDisabler to omit permissions check for delete operation:

using (new SecurityDisabler())
{
    // you code to delete here within using block
}

Hope this helps!

Upvotes: 0

Richard Seal
Richard Seal

Reputation: 4266

For an admin function like that, I would be tempted to use Sitecore Powershell Extensions: https://marketplace.sitecore.net/en/Modules/Sitecore_PowerShell_console.aspx

The Get-User command can pull users out of the system: Get-User Documentation

PS master:\> Get-User -Filter "michaellwest@*.com"

Name                     Domain       IsAdministrator IsAuthenticated
----                     ------       --------------- ---------------
sitecore\michael         sitecore     False           False

Then you can use Remove-User to delete them: Remove-User Documentation

There are a lot of great resources on how to use SPE, its awesome for stuff like this.

Upvotes: 1

Related Questions