Files
minisrv/zefie_wtvp_minisrv/ServiceVault/wtv-setup/validate-remove-users.js
zefie b89e0e932c v0.9.35
- numerous bug fixes
 - wtv-news goodies, ready for local testing
   - custom patched nntp-server node module with support for POSTing
   - should be able to post locally
   - 4 groups are made by default
   - can override in user_config.json (look at the config.json changes but dont do them there)
   - can sync down from an upstream server with sync_nntp.js
   - sync does not push new posts to upstream yet
2022-11-29 08:29:31 -05:00

73 lines
2.5 KiB
JavaScript

var minisrv_service_file = true;
var errpage;
if (Object.keys(session_data.listPrimaryAccountUsers()).length == 1) {
errpage = wtvshared.doErrorPage(400, "There are no more users to remove.");
}
else if (session_data.user_id != 0) errpage = wtvshared.doErrorPage(400, "You are not authorized to remove users from this account.");
var usersToRemove = [];
Object.keys(request_headers.query).forEach(function (k) {
if (k.substr(0, 4) === "user" && request_headers.query[k] === "on") {
usersToRemove.push(parseInt(k.replace("user", "")));
}
});
if (usersToRemove.length === 0) errpage = wtvshared.doErrorPage(400, "No users were specified for removal.");
if (errpage) {
headers = errpage[0];
data = errpage[1];
} else {
if (!request_headers.query.confirm_remove) {
var message = '';
if (usersToRemove.length == 1) {
var userSession = new WTVClientSessionData(minisrv_config, socket.ssid);
userSession.switchUserID(usersToRemove[0]);
var userName = userSession.getSessionData("subscriber_username");
message = `Removing <b>${userName}</b> will permanently remove all of <b>${userName}</b>'s e-mail and favorites as well. You will not be able to restore <b>${userName}</b>.`;
} else {
message = "Removing the selected users will permanently remove their e-mail and favorites as well. You will not be able to restore the users.";
}
var removeurl = request_headers.request_url;
if (removeurl.indexOf('?') >= 0) {
removeurl = removeurl.substring(0, removeurl.indexOf('?'));
}
removeurl += "?";
Object.keys(usersToRemove).forEach(function (k) {
removeurl += "user" + usersToRemove[k] + "=on&";
});
removeurl += "confirm_remove=true";
var confirmAlert = new clientShowAlert({
'image': minisrv_config.config.service_logo,
'message': message,
'buttonlabel1': "Don't Remove",
'buttonaction1': "client:donothing",
'buttonlabel2': "Remove",
'buttonaction2': removeurl,
'noback': true,
}).getURL();
headers = `300 OK
Connection: Keep-Alive
Content-Type: text/html
wtv-expire-all: wtv-setup:/remove-users
wtv-expire-all: wtv-setup:/accounts
Location: ${confirmAlert}`
} else {
Object.keys(usersToRemove).forEach(function (k) {
session_data.removeUser(usersToRemove[k]);
})
var num_accounts = session_data.getNumberOfUserAccounts();
var gourl = "wtv-setup:/remove-users?";
if (num_accounts == 1) gourl = "wtv-setup:/accounts?";
headers = `300 OK
Connection: Keep-Alive
Content-Type: text/html
wtv-expire-all: wtv-setup:/remove-users
wtv-expire-all: wtv-setup:/accounts
Location: ${gourl}`
}
}