Created
May 8, 2012 19:48
-
-
Save samandmoore/2638812 to your computer and use it in GitHub Desktop.
SetupAdmins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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