Skip to content

Instantly share code, notes, and snippets.

@samandmoore
Created May 8, 2012 19:48
Show Gist options
  • Save samandmoore/2638812 to your computer and use it in GitHub Desktop.
Save samandmoore/2638812 to your computer and use it in GitHub Desktop.
SetupAdmins
private static void SetupAdminUsers(IKernel kernel)
{
var repository = kernel.Get<IJabbrRepository>();
var chatService = kernel.Get<IChatService>();
if (!repository.Users.Any(u => u.IsAdmin))
{
string defaultAdminUserName = System.Configuration.ConfigurationManager.AppSettings["defaultAdminUserName"];
string defaultAdminPassword = System.Configuration.ConfigurationManager.AppSettings["defaultAdminPassword"];
if (string.IsNullOrWhiteSpace(defaultAdminUserName) || string.IsNullOrWhiteSpace(defaultAdminPassword))
{
throw new InvalidOperationException("You have not provided a default admin username and/or password");
}
ChatUser defaultAdmin = repository.GetUserByName(defaultAdminUserName);
if (defaultAdmin == null)
{
defaultAdmin = chatService.AddUser(defaultAdminUserName, null, null, defaultAdminPassword);
}
defaultAdmin.IsAdmin = true;
repository.CommitChanges();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment