diff --git a/Project-Unite/ACL.cs b/Project-Unite/ACL.cs index c0567d9..5155573 100644 --- a/Project-Unite/ACL.cs +++ b/Project-Unite/ACL.cs @@ -169,7 +169,7 @@ public static IHtmlString UserLink(this HtmlHelper hpr, string userId) userRoles.Add(db.Roles.FirstOrDefault(r => r.Id == usrRole.RoleId) as Role); } var userRole = userRoles.OrderByDescending(m => m.Priority).FirstOrDefault(); - return hpr.ActionLink(usr.DisplayName, "ViewProfile", "Profiles", new { id = usr.DisplayName }, new { style = userRole == null ? "color:white;" : @"color: " + userRole.ColorHex }); + return hpr.ActionLink(usr.DisplayName, "ViewProfile", "Profiles", new { id = usr.DisplayName }, new { id="uname_" + usr.Id, style = userRole == null ? "color:white;" : @"color: " + userRole.ColorHex }); } } diff --git a/Project-Unite/Controllers/ModeratorController.cs b/Project-Unite/Controllers/ModeratorController.cs index 99ef8b7..04e40de 100644 --- a/Project-Unite/Controllers/ModeratorController.cs +++ b/Project-Unite/Controllers/ModeratorController.cs @@ -104,24 +104,18 @@ public ActionResult Unmute(string id, string returnUrl = "") return Redirect(returnUrl); } - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult ChangeUserName(string id, ApplicationUser model, string returnUrl = "") + public ActionResult ChangeUserName(string id, string newName) { var db = new ApplicationDbContext(); var usr = db.Users.FirstOrDefault(x => x.Id == id); if (usr == null) return new HttpStatusCodeResult(404); - usr.DisplayName = model.DisplayName; + usr.DisplayName = newName; db.SaveChanges(); - if (string.IsNullOrWhiteSpace(returnUrl)) - return RedirectToAction("Users"); - else - return Redirect(returnUrl); - + return new HttpStatusCodeResult(200); } public ActionResult Lock(string id) diff --git a/Project-Unite/Global.asax.cs b/Project-Unite/Global.asax.cs index 41208ad..79df7eb 100644 --- a/Project-Unite/Global.asax.cs +++ b/Project-Unite/Global.asax.cs @@ -37,59 +37,6 @@ protected void Application_BeginRequest(object sender, EventArgs e) migrator.Update(); - string raw_url = Request.Url.ToString().Replace("//", "\\\\"); - - string[] split = raw_url.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries); - - string actionname = "Index"; - string controllername = "Home"; - - if(split.Length > 1) - { - controllername = split[1]; - if (split.Length == 3) - actionname = split[2]; - } - - var asm = Assembly.GetExecutingAssembly(); - var ctl = asm.GetTypes().FirstOrDefault(x => x.Name == controllername + "Controller"); - var adm = ctl.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresAdmin); - var mod = ctl.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresModerator); - var dev = ctl.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresDeveloper); - - bool fail = false; - - if (adm != null) - fail = (bool)!User.Identity?.IsAdmin(); - if (mod != null) - fail = (bool)!User.Identity?.IsModerator(); - if (dev != null) - fail = (bool)!User.Identity?.IsDeveloper(); - - var act = ctl.GetMethods(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(x => x.Name == actionname); - - adm = act.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresAdmin); - mod = act.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresModerator); - dev = act.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresDeveloper); - - bool? fail2 = true; - - if (adm != null) - fail2 = User.Identity?.IsAdmin(); - if (mod != null) - fail2 = User.Identity?.IsModerator(); - if (dev != null) - fail2 = User.Identity?.IsDeveloper(); - - if (fail2 != null) - fail = fail || !(bool)fail2; - - if (fail == true) - { - string url = "http://" + this.Request.Url.Host.Replace("http://", "").Replace("https://", "") + "/Home/AccessDenied"; - Response.Redirect(url, true); - return; - } var addr = HttpContext.Current.Request.UserHostAddress; var db = new ApplicationDbContext(); @@ -107,6 +54,61 @@ protected void Application_BeginRequest(object sender, EventArgs e) protected void Application_EndRequest(object s, EventArgs e) { + string raw_url = Request.Url.ToString().Replace("//", "\\\\"); + + string[] split = raw_url.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries); + + string actionname = "Index"; + string controllername = "Home"; + + if (split.Length > 1) + { + controllername = split[1]; + if (split.Length == 3) + actionname = split[2]; + } + + var asm = Assembly.GetExecutingAssembly(); + var ctl = asm.GetTypes().FirstOrDefault(x => x.Name == controllername + "Controller"); + var adm = ctl.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresAdmin); + var mod = ctl.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresModerator); + var dev = ctl.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresDeveloper); + + bool? fail = false; + + if (adm != null) + fail = !User?.Identity?.IsAdmin(); + if (mod != null) + fail = !User?.Identity?.IsModerator(); + if (dev != null) + fail = !User?.Identity?.IsDeveloper(); + + var act = ctl.GetMethods(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(x => x.Name == actionname); + + adm = act.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresAdmin); + mod = act.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresModerator); + dev = act.GetCustomAttributes(false).FirstOrDefault(x => x is RequiresDeveloper); + + bool? fail2 = true; + + if (adm != null) + fail2 = User?.Identity?.IsAdmin(); + if (mod != null) + fail2 = User?.Identity?.IsModerator(); + if (dev != null) + fail2 = User?.Identity?.IsDeveloper(); + + bool realfail = (fail == null) ? true : (bool)fail; + bool realfail2 = (fail2 == null) ? true : (bool)fail2; + + realfail = realfail || !realfail2; + + if (realfail == true) + { + string url = "http://" + this.Request.Url.Host.Replace("http://", "").Replace("https://", "") + "/Home/AccessDenied"; + Response.Redirect(url, true); + return; + } var db = new ApplicationDbContext(); if (Request.IsAuthenticated) { diff --git a/Project-Unite/Views/Admin/Index.cshtml b/Project-Unite/Views/Admin/Index.cshtml index 552f80c..4839e31 100644 --- a/Project-Unite/Views/Admin/Index.cshtml +++ b/Project-Unite/Views/Admin/Index.cshtml @@ -209,7 +209,7 @@ git clone https://github.com/MichaelTheShifter/Project-Unite @foreach (var user in db.Users.ToArray()) { -