mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 17:22:15 +00:00
Jesus.
*looks at the atmosphere with major thoights of the mess he has created*
This commit is contained in:
parent
7e0dfbb778
commit
dbce55459f
6 changed files with 123 additions and 109 deletions
|
@ -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 });
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -209,7 +209,7 @@ git clone https://github.com/MichaelTheShifter/Project-Unite
|
|||
|
||||
@foreach (var user in db.Users.ToArray())
|
||||
{
|
||||
<div class="modal fade" id="u_details_@user.DisplayName">
|
||||
<div class="modal fade" id="u_details_@user.Id">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
|
@ -222,7 +222,7 @@ git clone https://github.com/MichaelTheShifter/Project-Unite
|
|||
@Html.Partial("~/Views/Moderator/UserDetails.cshtml", user)
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal" data-target="#u_details_@user.DisplayName">Close</button>
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal" data-target="#u_details_@user.Id">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -271,7 +271,7 @@ git clone https://github.com/MichaelTheShifter/Project-Unite
|
|||
</td>
|
||||
<td>
|
||||
<a href="@Url.Action("ViewProfile", "Profiles", new { id = user.DisplayName })" class="btn btn-default"><span class="glyphicon glyphicon-user"></span> View Profile</a>
|
||||
<a data-toggle="modal" href="#u_details_@user.DisplayName" class="btn btn-warning"><span class="glyphicon glyphicon-wrench"></span> Moderate</a>
|
||||
<a data-toggle="modal" href="#u_details_@user.Id" class="btn btn-warning"><span class="glyphicon glyphicon-wrench"></span> Moderate</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
|
|
@ -10,22 +10,22 @@
|
|||
|
||||
<ul>
|
||||
<li><strong>Email address: </strong><a href="mailto:@Model.Email">Email @Model.Email</a></li>
|
||||
<li><strong>Display name: </strong>@Model.DisplayName
|
||||
<li><strong>Display name: </strong> <div id="uname_@Model.Id">@Model.DisplayName</div>
|
||||
|
||||
@if (ACL.Granted(User.Identity.Name, "CanEditUsernames"))
|
||||
@if (User.Identity.IsAdmin())
|
||||
{
|
||||
if (ACL.CanManageRole(User.Identity.Name, Model.HighestRole.Id))
|
||||
{
|
||||
<!-- Trigger the modal with a button -->
|
||||
<a data-toggle="modal" data-target="#edit-user" href="#"><span class="glyphicon glyphicon-pencil"></span> Change</a>
|
||||
<a data-toggle="modal" data-target="#edit-user-@Model.Id" href="#"><span class="glyphicon glyphicon-pencil"></span> Change</a>
|
||||
|
||||
<!-- Modal -->
|
||||
<div id="edit-user" class="modal fade" role="dialog">
|
||||
<div id="edit-user-@Model.Id" class="modal fade" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
|
||||
<!-- Modal content-->
|
||||
<div class="modal-content">
|
||||
@using (Html.BeginForm("ChangeUsername", "Moderator", new { id = Model.Id }))
|
||||
@using (Html.BeginForm("ChangeUsername", "Moderator", new { id = Model.Id }, FormMethod.Post, new { name = "changeusername_" + Model.Id }))
|
||||
{
|
||||
@Html.AntiForgeryToken()
|
||||
<div class="modal-header">
|
||||
|
@ -34,11 +34,10 @@
|
|||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Please enter a username for this user.</p>
|
||||
<p><strong>@Html.DisplayNameFor(Model => Model.DisplayName)</strong>: @Html.TextBoxFor(Model => Model.DisplayName)</p>
|
||||
|
||||
<p><strong>@Html.DisplayNameFor(Model => Model.DisplayName)</strong>: @Html.TextBoxFor(Model => Model.DisplayName, new { id="new_username_" + Model.Id, @class = "form-control" })</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<input type="submit" value="Change" class="btn btn-primary" />
|
||||
<a class="btn btn-primary" data-dismiss="modal" href="#" id="submit_username_@Model.Id"><span class="glyphicon glyphicon-ok"></span> Change</a>
|
||||
<a href="#" data-dismiss="modal" class="btn btn-default">Cancel</a>
|
||||
</div>
|
||||
}
|
||||
|
@ -49,10 +48,7 @@
|
|||
}
|
||||
}
|
||||
</li>
|
||||
@if(ACL.Granted(User.Identity.Name, "CanIssueIPBan"))
|
||||
{
|
||||
<li><strong>Last known IP address: </strong>@Model.LastKnownIPAddress</li>
|
||||
}
|
||||
<li><strong>Last known IP address: </strong>@Model.LastKnownIPAddress</li>
|
||||
<li><strong>Banned: </strong>
|
||||
@if (Model.IsBanned)
|
||||
{
|
||||
|
@ -111,6 +107,28 @@
|
|||
<strong>Hobbies:</strong>
|
||||
<p>@Model.Hobbies</p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<a data-toggle="modal" href="#" data-target="#m_succeeded_@Model.Id" id="succeeded_@Model.Id" class="hidden">I'm a callback.</a>
|
||||
|
||||
</ul>
|
||||
<script type="text/javascript">
|
||||
$('#submit_username_@Model.Id').click(function (e) { //Never gets called.
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
cache: true,
|
||||
url: './Moderator/ChangeUsername/@Model.Id?newName=' + encodeURIComponent($('#new_username_!@Model.Id').val()),
|
||||
success: function (msg) {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
cache: true,
|
||||
url: "./Moderator/GetUsername/@Model.Id",
|
||||
success: function (result) {
|
||||
$('#uname_@Model.Id').val(result);
|
||||
$('#new_username_@Model.Id').val(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
|
@ -11,11 +11,41 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
@Scripts.Render("~/Scripts/simplemde.js")
|
||||
@Scripts.Render("~/bundles/modernizr")
|
||||
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
|
||||
|
||||
@if(ViewBag.PageDescription != null)
|
||||
{
|
||||
<meta name="description" content="@ViewBag.PageDescription" />
|
||||
}
|
||||
@Scripts.Render("~/bundles/jquery")
|
||||
@Scripts.Render("~/bundles/bootstrap")
|
||||
<script src="Scripts/jquery.signalR-2.2.2-preview1.min.js"></script>
|
||||
<script src="signalr/hubs"></script>
|
||||
@RenderSection("scripts", required: false)
|
||||
<script type="text/javascript">
|
||||
var mde = new SimpleMDE({forceSync: true});
|
||||
mde.options.forceSync();
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
var notificationHubProxy = $.connection.notificationHub;
|
||||
notificationHubProxy.client.sendMessage = function (message) {
|
||||
$("#notification_body").find("ul").append("<li></li>").html(message);
|
||||
$.ajax({
|
||||
url : "/API/GetNotificationCount",
|
||||
success : function(result){
|
||||
$("#notification_count").html(result);
|
||||
}
|
||||
});
|
||||
var audio = new Audio("/Content/infobox.wav");
|
||||
audio.play();
|
||||
};
|
||||
$.connection.hub.start()
|
||||
.done(function(){ console.log('Now connected, connection ID=' + $.connection.hub.id); })
|
||||
.fail(function(){ console.log('Could not Connect!'); });
|
||||
});
|
||||
</script>
|
||||
|
||||
<title>@ViewBag.Title • ShiftOS</title>
|
||||
@Styles.Render("~/Content/css")
|
||||
|
@ -23,9 +53,6 @@
|
|||
@Styles.Render("~/Content/Site.css")
|
||||
<link rel="stylesheet" href="https://cdn.rawgit.com/xcatliu/simplemde-theme-dark/master/dist/simplemde-theme-dark.min.css" />
|
||||
|
||||
@Scripts.Render("~/Scripts/simplemde.js")
|
||||
@Scripts.Render("~/bundles/modernizr")
|
||||
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar navbar-default">
|
||||
|
@ -164,33 +191,6 @@
|
|||
|
||||
|
||||
|
||||
@Scripts.Render("~/bundles/jquery")
|
||||
@Scripts.Render("~/bundles/bootstrap")
|
||||
<script src="Scripts/jquery.signalR-2.2.2-preview1.min.js"></script>
|
||||
<script src="signalr/hubs"></script>
|
||||
@RenderSection("scripts", required: false)
|
||||
<script type="text/javascript">
|
||||
var mde = new SimpleMDE({forceSync: true});
|
||||
mde.options.forceSync();
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
var notificationHubProxy = $.connection.notificationHub;
|
||||
notificationHubProxy.client.sendMessage = function (message) {
|
||||
$("#notification_body").find("ul").append("<li></li>").html(message);
|
||||
$.ajax({
|
||||
url : "/API/GetNotificationCount",
|
||||
success : function(result){
|
||||
$("#notification_count").html(result);
|
||||
}
|
||||
});
|
||||
var audio = new Audio("/Content/infobox.wav");
|
||||
audio.play();
|
||||
};
|
||||
$.connection.hub.start()
|
||||
.done(function(){ console.log('Now connected, connection ID=' + $.connection.hub.id); })
|
||||
.fail(function(){ console.log('Could not Connect!'); });
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue