Dark mode improvements, add user delete confirmation
This commit is contained in:
parent
c88a0d0b11
commit
30228bb4a4
|
@ -75,7 +75,7 @@
|
|||
}
|
||||
else {
|
||||
<button class="btn btn-dark" onclick="prepareSetPasswordModal('@user.Username')">Set Password</button>
|
||||
<button onclick="ajax_and_reload('user_delete', '@user.Username')" class="btn btn-danger">Delete</button>
|
||||
<button onclick="prepareDeleteUserModal('@user.Username')" class="btn btn-danger">Delete</button>
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -115,6 +115,11 @@ function prepareSetPasswordModal(target) {
|
|||
document.getElementById('setPasswordTarget').value = target;
|
||||
$('#setPasswordModal').modal();
|
||||
}
|
||||
function prepareDeleteUserModal(target) {
|
||||
document.getElementById('deleteUserModalLabel').innerHTML = 'Delete user: ' + target;
|
||||
document.getElementById('deleteUserTarget').value = target;
|
||||
$('#deleteUserModal').modal();
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="modal fade" id="setPasswordModal" tabindex="-1" aria-labelledby="setPasswordModalLabel" aria-hidden="true">
|
||||
|
@ -142,3 +147,26 @@ function prepareSetPasswordModal(target) {
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="deleteUserModal" tabindex="-1" aria-labelledby="setPasswordModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="deleteUserModalLabel">Delete user</h5>
|
||||
<button role="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<form method="POST">
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<input type="hidden" value="user_delete" name="action">
|
||||
<input type="hidden" value="" name="target" id="deleteUserTarget">
|
||||
<button role="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-danger">Do it</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -6,62 +6,62 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
|
|||
using RTMPDash.DataModels;
|
||||
using RTMPDash.DataModels.Tables;
|
||||
|
||||
namespace RTMPDash.Pages {
|
||||
public class AdminModel : PageModel {
|
||||
public void OnGet() { }
|
||||
namespace RTMPDash.Pages;
|
||||
|
||||
public void OnPost() {
|
||||
if (string.IsNullOrEmpty(HttpContext.Session.GetString("authenticatedUser"))
|
||||
|| !new AppDb.DbConn().Users
|
||||
.First(p => p.Username == HttpContext.Session.GetString("authenticatedUser"))
|
||||
.IsAdmin)
|
||||
return;
|
||||
public class AdminModel : PageModel {
|
||||
public void OnGet() { }
|
||||
|
||||
if (!Request.HasFormContentType || string.IsNullOrWhiteSpace(Request.Form["action"]))
|
||||
return;
|
||||
public void OnPost() {
|
||||
if (string.IsNullOrEmpty(HttpContext.Session.GetString("authenticatedUser"))
|
||||
|| !new AppDb.DbConn().Users.First(p => p.Username == HttpContext.Session.GetString("authenticatedUser")).IsAdmin)
|
||||
return;
|
||||
|
||||
var db = new AppDb.DbConn();
|
||||
if (!Request.HasFormContentType || string.IsNullOrWhiteSpace(Request.Form["action"]))
|
||||
return;
|
||||
|
||||
if (Request.Form["action"] == "invite_generate")
|
||||
db.Insert(new Invite {Code = Guid.NewGuid().ToString()});
|
||||
var db = new AppDb.DbConn();
|
||||
|
||||
if (Request.Form["action"] == "invite_revoke")
|
||||
db.Delete(db.Invites.First(p => p.Code == Request.Form["target"]));
|
||||
if (Request.Form["action"] == "invite_generate")
|
||||
db.Insert(new Invite { Code = Guid.NewGuid().ToString() });
|
||||
|
||||
if (Request.Form["action"] == "restream_allow") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
user.AllowRestream = true;
|
||||
db.Update(user);
|
||||
}
|
||||
if (Request.Form["action"] == "invite_revoke")
|
||||
db.Delete(db.Invites.First(p => p.Code == Request.Form["target"]));
|
||||
|
||||
if (Request.Form["action"] == "restream_revoke") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
user.AllowRestream = false;
|
||||
db.Update(user);
|
||||
}
|
||||
if (Request.Form["action"] == "restream_allow") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
user.AllowRestream = true;
|
||||
db.Update(user);
|
||||
}
|
||||
|
||||
if (Request.Form["action"] == "admin_grant") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
user.IsAdmin = true;
|
||||
db.Update(user);
|
||||
}
|
||||
if (Request.Form["action"] == "restream_revoke") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
user.AllowRestream = false;
|
||||
db.Update(user);
|
||||
}
|
||||
|
||||
if (Request.Form["action"] == "admin_revoke") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
user.IsAdmin = false;
|
||||
db.Update(user);
|
||||
}
|
||||
if (Request.Form["action"] == "admin_grant") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
user.IsAdmin = true;
|
||||
db.Update(user);
|
||||
}
|
||||
|
||||
if (Request.Form["action"] == "user_delete") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
db.Delete(user);
|
||||
}
|
||||
if (Request.Form["action"] == "admin_revoke") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
user.IsAdmin = false;
|
||||
db.Update(user);
|
||||
}
|
||||
|
||||
if (Request.Form["action"] == "user_setpass") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
user.Password = Request.Form["value"].ToString().Sha256();
|
||||
db.Update(user);
|
||||
}
|
||||
if (Request.Form["action"] == "user_delete") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
db.Delete(user);
|
||||
Response.Redirect("/Admin");
|
||||
}
|
||||
|
||||
if (Request.Form["action"] == "user_setpass") {
|
||||
var user = db.Users.First(p => p.Username == Request.Form["target"]);
|
||||
user.Password = Request.Form["value"].ToString().Sha256();
|
||||
db.Update(user);
|
||||
Response.Redirect("/Admin");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
@page
|
||||
@inject IAntiforgery Antiforgery
|
||||
@inject IAntiforgery _antiforgery
|
||||
@using Microsoft.AspNetCore.Antiforgery
|
||||
@using Microsoft.AspNetCore.Http
|
||||
@using RTMPDash.DataModels
|
||||
@model DashboardModel
|
||||
@{
|
||||
ViewData["Title"] = "Dashboard";
|
||||
var tokenSet = Antiforgery.GetAndStoreTokens(HttpContext);
|
||||
var tokenSet = _antiforgery.GetAndStoreTokens(HttpContext);
|
||||
}
|
||||
|
||||
@if (string.IsNullOrWhiteSpace(HttpContext.Session.GetString("authenticatedUser"))) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* Licensed under MIT (https://github.com/coliff/dark-mode-switch/blob/main/LICENSE)
|
||||
*/
|
||||
|
||||
[data-theme="dark"] {
|
||||
[data-theme="dark"], [data-theme="dark"] .modal-content {
|
||||
background-color: #222 !important;
|
||||
color: #eee;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
|||
}
|
||||
|
||||
[data-theme="dark"] a.btn {
|
||||
color: #fff;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
[data-theme="dark"] a.nav-link.text-dark, [data-theme="dark"] label.custom-control-label {
|
||||
|
@ -72,6 +72,24 @@
|
|||
border-color: #4f4f4f;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .modal-header {
|
||||
border-bottom: 1px solid #383838;
|
||||
color: #b6b6b6;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .modal-footer {
|
||||
border-top: 1px solid #383838;
|
||||
color: #b6b6b6;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .close {
|
||||
color: #bebdbd;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .close:hover {
|
||||
color: #d5d5d5;
|
||||
}
|
||||
|
||||
.notransition, .notransition::before, .notransition::after {
|
||||
-webkit-transition: none !important;
|
||||
-moz-transition: none !important;
|
||||
|
|
Loading…
Reference in a new issue