2024-09-28 01:31:46 +01:00
|
|
|
import AdminBadgesViewModel from "../models/admin/AdminBadgesViewModel";
|
|
|
|
import AdminBadgeViewModel from "../models/admin/AdminBadgeViewModel";
|
|
|
|
import AdminDeleteBadgeModel from "../models/admin/AdminDeleteBadgeModel";
|
2024-09-28 14:31:02 +01:00
|
|
|
import AdminDeletePartyModel from "../models/admin/AdminDeletePartyModel";
|
|
|
|
import AdminExpireSessionModel from "../models/admin/AdminExpireSessionModel";
|
2024-09-26 00:47:08 +01:00
|
|
|
import AdminIndexViewModel from "../models/admin/AdminIndexViewModel";
|
|
|
|
import AdminPartiesViewModel from "../models/admin/AdminPartiesViewModel";
|
2024-09-28 14:31:02 +01:00
|
|
|
import AdminPartyViewModel from "../models/admin/AdminPartyViewModel";
|
2024-09-26 00:47:08 +01:00
|
|
|
import AdminUsersViewModel from "../models/admin/AdminUsersViewModel";
|
2024-09-28 14:31:02 +01:00
|
|
|
import AdminUserViewModel from "../models/admin/AdminUserViewModel";
|
|
|
|
import AdminWebSessionsViewModel from "../models/admin/AdminWebSessionsViewModel";
|
|
|
|
import AdminWsSessionsViewModel from "../models/admin/AdminWsSessionsViewModel";
|
|
|
|
import Session from "../objects/Session";
|
|
|
|
import WsData from "../objects/WsData";
|
2024-09-28 01:31:46 +01:00
|
|
|
import BadgeService from "../services/BadgeService";
|
2024-09-26 00:47:08 +01:00
|
|
|
import PartyService from "../services/PartyService";
|
|
|
|
import UserService from "../services/UserService";
|
|
|
|
import Controller from "./Controller";
|
|
|
|
|
|
|
|
export default class AdminController_Auth$Admin extends Controller {
|
|
|
|
public async Index_Get() {
|
|
|
|
const adminIndexViewModel: AdminIndexViewModel = {
|
|
|
|
userCount: await UserService.GetUserCount(),
|
2024-09-28 14:31:02 +01:00
|
|
|
partyCount: await PartyService.GetPartyCount(),
|
|
|
|
badgeCount: await BadgeService.GetBadgeCount()
|
2024-09-26 00:47:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return this.view(adminIndexViewModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Users_Get() {
|
|
|
|
const adminUsersViewModel: AdminUsersViewModel = {
|
|
|
|
users: await UserService.GetAll()
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.view(adminUsersViewModel);
|
|
|
|
}
|
|
|
|
|
2024-09-28 14:31:02 +01:00
|
|
|
public async User_Get(adminUserViewModel: AdminUserViewModel) {
|
|
|
|
const user = adminUserViewModel.id ? await UserService.GetUser(parseInt(adminUserViewModel.id)) : null;
|
|
|
|
if (typeof(adminUserViewModel.id) !== "undefined" && user) {
|
|
|
|
adminUserViewModel.username = user.Username;
|
|
|
|
adminUserViewModel.userLevel = String(user.UserLevel);
|
|
|
|
} else {
|
|
|
|
adminUserViewModel.username = "";
|
|
|
|
adminUserViewModel.userLevel = "0";
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.view(adminUserViewModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async User_Post(adminUserViewModel: AdminUserViewModel) {
|
|
|
|
if (typeof(adminUserViewModel.id) === "undefined") {
|
|
|
|
return this.badRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
const user = await UserService.SaveUser(this.session.userId, parseInt(adminUserViewModel.id), adminUserViewModel.username ?? "", parseInt(adminUserViewModel.userLevel ?? ""));
|
|
|
|
if (!user) {
|
|
|
|
adminUserViewModel.message = "A user with that username already exists.";
|
|
|
|
return this.view(adminUserViewModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.redirectToAction("users");
|
|
|
|
}
|
|
|
|
|
2024-09-26 00:47:08 +01:00
|
|
|
public async Parties_Get() {
|
|
|
|
const adminPartiesViewModel: AdminPartiesViewModel = {
|
|
|
|
parties: await PartyService.GetAll()
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.view(adminPartiesViewModel);
|
|
|
|
}
|
2024-09-28 01:31:46 +01:00
|
|
|
|
2024-09-28 14:31:02 +01:00
|
|
|
public async Party_Get(adminPartyViewModel: AdminPartyViewModel) {
|
|
|
|
const party = adminPartyViewModel.id ? await PartyService.GetParty(parseInt(adminPartyViewModel.id)) : null;
|
|
|
|
if (typeof(adminPartyViewModel.id) !== "undefined" && party) {
|
|
|
|
adminPartyViewModel.partyRef = party.PartyRef;
|
|
|
|
adminPartyViewModel.name = party.Name;
|
|
|
|
} else {
|
|
|
|
adminPartyViewModel.partyRef = "";
|
|
|
|
adminPartyViewModel.name = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.view(adminPartyViewModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Party_Post(adminPartyViewModel: AdminPartyViewModel) {
|
|
|
|
if (typeof(adminPartyViewModel.id) === "undefined") {
|
|
|
|
return this.badRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
await PartyService.SaveParty(this.session.userId, parseInt(adminPartyViewModel.id), adminPartyViewModel.name ?? "", adminPartyViewModel.partyRef ?? "");
|
|
|
|
|
|
|
|
return this.redirectToAction("parties");
|
|
|
|
}
|
|
|
|
|
|
|
|
public async DeleteParty_Get(adminDeletePartyModel: AdminDeletePartyModel) {
|
|
|
|
if (typeof(adminDeletePartyModel.id) === "undefined" || typeof(adminDeletePartyModel.id) !== "string") {
|
|
|
|
return this.badRequest();
|
|
|
|
}
|
|
|
|
const partyId = parseInt(adminDeletePartyModel.id);
|
|
|
|
|
|
|
|
await PartyService.DeletePartyAdmin(this.session.userId, partyId);
|
|
|
|
|
|
|
|
return this.redirectToAction("parties");
|
|
|
|
}
|
|
|
|
|
2024-09-29 21:35:36 +01:00
|
|
|
public async Badges_Get_Auth$BadgeEditor() {
|
2024-09-28 01:31:46 +01:00
|
|
|
const adminBadgesViewModel: AdminBadgesViewModel = {
|
|
|
|
badges: await BadgeService.LoadAll()
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.view(adminBadgesViewModel);
|
|
|
|
}
|
|
|
|
|
2024-09-29 21:35:36 +01:00
|
|
|
public async Badge_Get_Auth$BadgeEditor(adminBadgeViewModel: AdminBadgeViewModel) {
|
2024-09-28 01:31:46 +01:00
|
|
|
const badge = adminBadgeViewModel.id ? await BadgeService.LoadBadge(parseInt(adminBadgeViewModel.id)) : null;
|
|
|
|
if (typeof(adminBadgeViewModel.id) !== "undefined" && badge) {
|
|
|
|
adminBadgeViewModel.name = badge.Name;
|
|
|
|
adminBadgeViewModel.description = badge.Description;
|
|
|
|
adminBadgeViewModel.imageUrl = badge.ImageUrl;
|
|
|
|
adminBadgeViewModel.forUrl = badge.ForUrl;
|
2024-10-08 11:04:46 +01:00
|
|
|
adminBadgeViewModel.isSecret = badge.IsSecret;
|
2024-09-28 01:31:46 +01:00
|
|
|
} else {
|
|
|
|
adminBadgeViewModel.name = "";
|
|
|
|
adminBadgeViewModel.description = "";
|
|
|
|
adminBadgeViewModel.imageUrl = "";
|
|
|
|
adminBadgeViewModel.forUrl = "";
|
2024-10-08 11:04:46 +01:00
|
|
|
adminBadgeViewModel.isSecret = false;
|
2024-09-28 01:31:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.view(adminBadgeViewModel);
|
|
|
|
}
|
|
|
|
|
2024-09-29 21:35:36 +01:00
|
|
|
public async Badge_Post_Auth$BadgeEditor(adminBadgeViewModel: AdminBadgeViewModel) {
|
2024-09-28 01:31:46 +01:00
|
|
|
if (typeof(adminBadgeViewModel.id) === "undefined") {
|
|
|
|
return this.badRequest();
|
|
|
|
}
|
|
|
|
|
2024-10-08 11:04:46 +01:00
|
|
|
await BadgeService.SaveBadge(this.session.userId, parseInt(adminBadgeViewModel.id), adminBadgeViewModel.name ?? "", adminBadgeViewModel.description ?? "", adminBadgeViewModel.imageUrl ?? "", adminBadgeViewModel.forUrl ?? "", (adminBadgeViewModel.isSecret?.toString() ?? "") === "on");
|
2024-09-28 01:31:46 +01:00
|
|
|
|
|
|
|
return this.redirectToAction("badges");
|
|
|
|
}
|
|
|
|
|
2024-09-29 21:35:36 +01:00
|
|
|
public async DeleteBadge_Get_Auth$BadgeEditor(adminDeleteBadgeModel: AdminDeleteBadgeModel) {
|
2024-09-28 01:31:46 +01:00
|
|
|
if (typeof(adminDeleteBadgeModel.id) === "undefined" || typeof(adminDeleteBadgeModel.id) !== "string") {
|
|
|
|
return this.badRequest();
|
|
|
|
}
|
|
|
|
const badgeId = parseInt(adminDeleteBadgeModel.id);
|
|
|
|
|
|
|
|
await BadgeService.DeleteBadge(this.session.userId, badgeId);
|
|
|
|
|
|
|
|
return this.redirectToAction("badges");
|
|
|
|
}
|
2024-09-28 14:31:02 +01:00
|
|
|
|
|
|
|
public async WebSessions_Get() {
|
|
|
|
const adminWebSessionsViewModel: AdminWebSessionsViewModel = {
|
|
|
|
sessions: Session.Sessions
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.view(adminWebSessionsViewModel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async ExpireSession_Get(adminExpireSessionModel: AdminExpireSessionModel) {
|
|
|
|
if (typeof(adminExpireSessionModel.key) === "undefined" || typeof(adminExpireSessionModel.key) !== "string") {
|
|
|
|
return this.badRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
Session.Sessions.remove(adminExpireSessionModel.key);
|
|
|
|
|
|
|
|
return this.redirectToAction("websessions");
|
|
|
|
}
|
|
|
|
|
|
|
|
public async WsSessions_Get() {
|
|
|
|
const adminWsSessionsViewModel: AdminWsSessionsViewModel = {
|
|
|
|
users: WsData.users
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.view(adminWsSessionsViewModel);
|
|
|
|
}
|
2024-09-26 00:47:08 +01:00
|
|
|
}
|