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