This commit is contained in:
parent
2e376269c2
commit
c65967acd6
2 changed files with 43 additions and 14 deletions
|
|
@ -630,31 +630,35 @@ void RealmController::updateRealm(const HttpRequestPtr &req,
|
||||||
}
|
}
|
||||||
>> DB_ERROR_MSG(callback, "update retention", "Failed to update retention");
|
>> DB_ERROR_MSG(callback, "update retention", "Failed to update retention");
|
||||||
} else if (json->isMember("name")) {
|
} else if (json->isMember("name")) {
|
||||||
// Update realm name
|
// Update realm name (display name with optional uppercase)
|
||||||
std::string newName = (*json)["name"].asString();
|
std::string displayName = (*json)["name"].asString();
|
||||||
|
|
||||||
// Validate name format
|
// Validate display name format
|
||||||
if (!validateRealmName(newName)) {
|
if (!validateRealmDisplayName(displayName)) {
|
||||||
callback(jsonError("Invalid realm name. Use 3-30 lowercase letters, numbers, and hyphens only."));
|
callback(jsonError("Invalid realm name. Use 3-30 letters, numbers, and hyphens only."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if name is already taken by another realm
|
// Generate lowercase slug for URL
|
||||||
|
std::string newSlug = toSlug(displayName);
|
||||||
|
|
||||||
|
// Check if slug is already taken by another realm
|
||||||
*dbClient << "SELECT id FROM realms WHERE name = $1 AND id != $2"
|
*dbClient << "SELECT id FROM realms WHERE name = $1 AND id != $2"
|
||||||
<< newName << id
|
<< newSlug << id
|
||||||
>> [callback, dbClient, id, user, newName](const Result& nameCheck) {
|
>> [callback, dbClient, id, user, displayName, newSlug](const Result& nameCheck) {
|
||||||
if (!nameCheck.empty()) {
|
if (!nameCheck.empty()) {
|
||||||
callback(jsonError("Realm name is already taken"));
|
callback(jsonError("Realm name is already taken"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*dbClient << "UPDATE realms SET name = $1 WHERE id = $2 AND user_id = $3"
|
*dbClient << "UPDATE realms SET name = $1, display_name = $2 WHERE id = $3 AND user_id = $4"
|
||||||
<< newName << id << user.id
|
<< newSlug << displayName << id << user.id
|
||||||
>> [callback, newName](const Result&) {
|
>> [callback, displayName, newSlug](const Result&) {
|
||||||
Json::Value resp;
|
Json::Value resp;
|
||||||
resp["success"] = true;
|
resp["success"] = true;
|
||||||
resp["message"] = "Realm renamed successfully";
|
resp["message"] = "Realm renamed successfully";
|
||||||
resp["name"] = newName;
|
resp["name"] = newSlug;
|
||||||
|
resp["displayName"] = displayName;
|
||||||
callback(jsonResp(resp));
|
callback(jsonResp(resp));
|
||||||
}
|
}
|
||||||
>> DB_ERROR_MSG(callback, "rename realm", "Failed to rename realm");
|
>> DB_ERROR_MSG(callback, "rename realm", "Failed to rename realm");
|
||||||
|
|
|
||||||
|
|
@ -1619,8 +1619,20 @@
|
||||||
|
|
||||||
async function loadUberbannedFingerprints() {
|
async function loadUberbannedFingerprints() {
|
||||||
try {
|
try {
|
||||||
|
// Fetch JWT token for chat-service authentication
|
||||||
|
const tokenResp = await fetch('/api/user/token', { credentials: 'include' });
|
||||||
|
if (!tokenResp.ok) {
|
||||||
|
console.error('Failed to load uberbanned fingerprints');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const tokenData = await tokenResp.json();
|
||||||
|
const token = tokenData.token;
|
||||||
|
|
||||||
const response = await fetch('/api/chat/uberbanned', {
|
const response = await fetch('/api/chat/uberbanned', {
|
||||||
credentials: 'include'
|
credentials: 'include',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
|
@ -1639,9 +1651,22 @@
|
||||||
if (!confirm(`Remove uberban for fingerprint ${truncated}?\n\nThis will allow this device to access the site again.`)) return;
|
if (!confirm(`Remove uberban for fingerprint ${truncated}?\n\nThis will allow this device to access the site again.`)) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Fetch JWT token for chat-service authentication
|
||||||
|
const tokenResp = await fetch('/api/user/token', { credentials: 'include' });
|
||||||
|
if (!tokenResp.ok) {
|
||||||
|
error = 'Failed to authenticate';
|
||||||
|
setTimeout(() => { error = ''; }, 3000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const tokenData = await tokenResp.json();
|
||||||
|
const token = tokenData.token;
|
||||||
|
|
||||||
const response = await fetch('/api/chat/unuberban', {
|
const response = await fetch('/api/chat/unuberban', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': `Bearer ${token}`
|
||||||
|
},
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
body: JSON.stringify({ fingerprint })
|
body: JSON.stringify({ fingerprint })
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue