The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AdminController.cs 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using Teknik.Areas.Admin.ViewModels;
  7. using Teknik.Areas.Users.Models;
  8. using Teknik.Areas.Users.Utility;
  9. using Teknik.Attributes;
  10. using Teknik.Controllers;
  11. using Teknik.Models;
  12. using Teknik.Utilities;
  13. using Teknik.ViewModels;
  14. namespace Teknik.Areas.Admin.Controllers
  15. {
  16. [TeknikAuthorize(Roles = "Admin")]
  17. public class AdminController : DefaultController
  18. {
  19. private TeknikEntities db = new TeknikEntities();
  20. [HttpGet]
  21. public ActionResult Dashboard()
  22. {
  23. DashboardViewModel model = new DashboardViewModel();
  24. return View(model);
  25. }
  26. [HttpGet]
  27. public ActionResult UserSearch()
  28. {
  29. UserSearchViewModel model = new UserSearchViewModel();
  30. return View(model);
  31. }
  32. [HttpGet]
  33. public ActionResult UserInfo(string username)
  34. {
  35. if (UserHelper.UserExists(db, username))
  36. {
  37. User user = UserHelper.GetUser(db, username);
  38. UserInfoViewModel model = new UserInfoViewModel();
  39. model.Username = user.Username;
  40. model.AccountType = user.AccountType;
  41. model.AccountStatus = user.AccountStatus;
  42. return View(model);
  43. }
  44. return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
  45. }
  46. [HttpGet]
  47. public ActionResult UploadSearch()
  48. {
  49. UploadSearchViewModel model = new UploadSearchViewModel();
  50. return View(model);
  51. }
  52. [HttpPost]
  53. public ActionResult GetUserSearchResults(string query)
  54. {
  55. List<UserResultViewModel> models = new List<UserResultViewModel>();
  56. var results = db.Users.Where(u => u.Username.Contains(query)).ToList();
  57. if (results != null)
  58. {
  59. foreach (User user in results)
  60. {
  61. try
  62. {
  63. UserResultViewModel model = new UserResultViewModel();
  64. model.Username = user.Username;
  65. if (Config.EmailConfig.Enabled)
  66. {
  67. model.Email = string.Format("{0}@{1}", user.Username, Config.EmailConfig.Domain);
  68. }
  69. model.JoinDate = user.JoinDate;
  70. model.LastSeen = UserHelper.GetLastAccountActivity(db, Config, user);
  71. models.Add(model);
  72. }
  73. catch (Exception ex)
  74. {
  75. // Skip this result
  76. }
  77. }
  78. }
  79. return Json(new { result = new { html = PartialView("~/Areas/Admin/Views/Admin/UserResults.cshtml", models) } });
  80. }
  81. [HttpPost]
  82. public ActionResult GetUploadSearchResults(string url)
  83. {
  84. Upload.Models.Upload foundUpload = db.Uploads.Where(u => u.Url == url).FirstOrDefault();
  85. if (foundUpload != null)
  86. {
  87. UploadResultViewModel model = new UploadResultViewModel();
  88. model.Url = foundUpload.Url;
  89. model.ContentType = foundUpload.ContentType;
  90. model.ContentLength = foundUpload.ContentLength;
  91. model.DateUploaded = foundUpload.DateUploaded;
  92. model.Downloads = foundUpload.Downloads;
  93. model.DeleteKey = foundUpload.DeleteKey;
  94. return Json(new { result = new { html = PartialView("~/Areas/Admin/Views/Admin/UploadResult.cshtml", model) } });
  95. }
  96. return Json(new { error = new { message = "Upload does not exist" } });
  97. }
  98. [HttpPost]
  99. [ValidateAntiForgeryToken]
  100. public ActionResult EditUserAccountType(string username, AccountType accountType)
  101. {
  102. if (UserHelper.UserExists(db, username))
  103. {
  104. // Edit the user's account type
  105. UserHelper.EditAccountType(db, Config, username, accountType);
  106. return Json(new { result = new { success = true } });
  107. }
  108. return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
  109. }
  110. [HttpPost]
  111. [ValidateAntiForgeryToken]
  112. public ActionResult EditUserAccountStatus(string username, AccountStatus accountStatus)
  113. {
  114. if (UserHelper.UserExists(db, username))
  115. {
  116. // Edit the user's account type
  117. UserHelper.EditAccountStatus(db, Config, username, accountStatus);
  118. return Json(new { result = new { success = true } });
  119. }
  120. return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
  121. }
  122. [HttpPost]
  123. [ValidateAntiForgeryToken]
  124. public ActionResult CreateInviteCode(string username)
  125. {
  126. if (UserHelper.UserExists(db, username))
  127. {
  128. User user = UserHelper.GetUser(db, username);
  129. InviteCode inviteCode = db.InviteCodes.Create();
  130. inviteCode.Active = true;
  131. inviteCode.Code = Guid.NewGuid().ToString();
  132. inviteCode.Owner = user;
  133. db.InviteCodes.Add(inviteCode);
  134. db.SaveChanges();
  135. return Json(new { result = new { code = inviteCode.Code } });
  136. }
  137. return Redirect(Url.SubRouteUrl("error", "Error.Http404"));
  138. }
  139. }
  140. }