You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.4 KiB

11 years ago
  1. using Microsoft.AspNet.Identity;
  2. using Microsoft.AspNet.Identity.EntityFramework;
  3. using Sevomin.Models;
  4. using Sevomin.Models.Helpers;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Web.Mvc;
  11. namespace Sevomin.WebFrontend.Controllers
  12. {
  13. public class GodController : AuthorizedController
  14. {
  15. [Authorize(Roles = "God")]
  16. public ActionResult Index()
  17. {
  18. return View();
  19. }
  20. [AllowAnonymous]
  21. public async Task<ActionResult> iddqd()
  22. {
  23. UserManager.UserValidator = new UserValidator<User>(UserManager);
  24. RoleManager<IdentityRole> roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(SevominDbContext.Current));
  25. if (!(await roleManager.RoleExistsAsync("God")))
  26. await roleManager.CreateAsync(new IdentityRole("God"));
  27. if ((await UserManager.FindByNameAsync("sevomin")) == null)
  28. {
  29. var user = new User("sevomin");
  30. user.SignUpDate = DateTime.Now;
  31. await UserManager.CreateAsync(user, "wePwntheNight");
  32. }
  33. var res = await UserManager.AddToRoleAsync((await UserManager.FindByNameAsync("sevomin")).Id, "God");
  34. return HttpNotFound();
  35. }
  36. }
  37. }