Guest User

Untitled

a guest
Oct 8th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. private static void SetupAdminUsers(IKernel kernel)
  2. {
  3. var repository = kernel.Get<IJabbrRepository>();
  4. var chatService = kernel.Get<IChatService>();
  5.  
  6. if (!repository.Users.Any(u => u.IsAdmin))
  7. {
  8. string defaultAdminUserName = System.Configuration.ConfigurationManager.AppSettings["defaultAdminUserName"];
  9. string defaultAdminPassword = System.Configuration.ConfigurationManager.AppSettings["defaultAdminPassword"];
  10.  
  11. if (string.IsNullOrWhiteSpace(defaultAdminUserName) || string.IsNullOrWhiteSpace(defaultAdminPassword))
  12. {
  13. throw new InvalidOperationException("You have not provided a default admin username and/or password");
  14. }
  15.  
  16. ChatUser defaultAdmin = repository.GetUserByName(defaultAdminUserName);
  17.  
  18. if (defaultAdmin == null)
  19. {
  20. defaultAdmin = chatService.AddUser(defaultAdminUserName, null, null, defaultAdminPassword);
  21. }
  22.  
  23. defaultAdmin.IsAdmin = true;
  24. repository.CommitChanges();
  25. }
  26.  
  27. }
Add Comment
Please, Sign In to add comment