rtmpdash/Pages/Dashboard.cshtml.cs

88 lines
2.5 KiB
C#
Raw Normal View History

2021-01-24 04:04:16 +01:00
using System;
using System.Linq;
using LinqToDB;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RTMPDash.DataModels;
2022-02-04 04:48:04 +01:00
namespace RTMPDash.Pages;
2021-01-24 04:04:16 +01:00
2022-02-04 04:48:04 +01:00
public class DashboardModel : PageModel {
public void OnGet() { }
2021-01-24 04:04:16 +01:00
2022-02-04 04:48:04 +01:00
public void OnPost() {
if (!Request.HasFormContentType || string.IsNullOrWhiteSpace(Request.Form["action"]) || string.IsNullOrWhiteSpace(HttpContext.Session.GetString("authenticatedUser")))
return;
2021-01-24 04:04:16 +01:00
2022-02-04 04:48:04 +01:00
using var db = new AppDb.DbConn();
var user = db.Users.FirstOrDefault(p => p.Username == HttpContext.Session.GetString("authenticatedUser"));
if (Request.Form["action"] == "password_change") {
var newPass = Request.Form["pass"];
user!.Password = newPass.ToString().Sha256();
db.Update(user);
Response.Redirect("/Logout");
}
if (Request.Form["action"] == "chaturl_set") {
user!.ChatUrl = Request.Form["value"];
db.Update(user);
Response.Redirect("/Dashboard");
}
2021-01-24 04:04:16 +01:00
2022-02-04 04:48:04 +01:00
if (Request.Form["action"] == "announceurl_set") {
user!.AnnouncementUrl = Request.Form["value"];
db.Update(user);
Response.Redirect("/Dashboard");
}
if (user!.AllowRestream) {
if (Request.Form["action"] == "restream_urls_set") {
user!.RestreamUrls = Request.Form["value"];
2021-01-24 04:04:16 +01:00
db.Update(user);
Response.Redirect("/Dashboard");
}
2022-02-04 04:48:04 +01:00
if (Request.Form["action"] == "restream_targets_set") {
var newtgts = Request.Form["value"].ToString();
if (newtgts.Contains("localhost") || newtgts.Contains("127.0.0.1") || newtgts.Contains(user.StreamKey))
return;
user!.RestreamTargets = newtgts;
2021-01-24 04:04:16 +01:00
db.Update(user);
Response.Redirect("/Dashboard");
}
2022-02-04 04:48:04 +01:00
}
2021-01-24 04:04:16 +01:00
2022-02-04 04:48:04 +01:00
if (Request.Form["action"] == "pronoun_subj_set") {
var target = string.IsNullOrWhiteSpace(Request.Form["value"]) ? "they" : Request.Form["value"].ToString();
user!.PronounSubject = target.ToLowerInvariant();
db.Update(user);
Response.Redirect("/Dashboard");
}
2021-01-24 04:04:16 +01:00
2022-02-04 04:48:04 +01:00
if (Request.Form["action"] == "pronoun_poss_set") {
var target = string.IsNullOrWhiteSpace(Request.Form["value"]) ? "their" : Request.Form["value"].ToString();
user!.PronounPossessive = target.ToLowerInvariant();
db.Update(user);
Response.Redirect("/Dashboard");
}
2021-01-24 04:04:16 +01:00
2022-02-04 04:48:04 +01:00
if (Request.Form["action"] == "streamkey_reset") {
user!.StreamKey = Guid.NewGuid().ToString();
db.Update(user);
}
2021-01-24 04:04:16 +01:00
2022-02-04 04:48:04 +01:00
if (Request.Form["action"] == "private_toggle") {
if (user.IsPrivate) {
user!.IsPrivate = false;
2021-01-24 04:04:16 +01:00
}
2022-02-04 04:48:04 +01:00
else {
user!.PrivateAccessKey = Guid.NewGuid().ToString();
user!.IsPrivate = true;
2021-01-24 04:04:16 +01:00
}
2022-02-04 04:48:04 +01:00
db.Update(user);
2021-01-24 04:04:16 +01:00
}
}
}