Track / expose a list of registered users.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3949 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-08-04 00:07:12 +00:00
parent 6628a5c420
commit 353f2ccc13
2 changed files with 20 additions and 0 deletions

View File

@ -101,6 +101,19 @@ function handler(request, response) {
if (formData.register == "1") { if (formData.register == "1") {
if (!account && if (!account &&
formData.password == formData.confirm) { formData.password == formData.confirm) {
let users = new Set();
let users_original = gDatabase.get('users');
try {
users = new Set(JSON.parse(users_original));
} catch {
}
if (!users.has(formData.name)) {
users.add(formData.name);
}
users = JSON.stringify([...users].sort());
if (users !== users_original) {
gDatabase.set('users', users);
}
writeSession(session, {name: formData.name}); writeSession(session, {name: formData.name});
account = {password: hashPassword(formData.password)}; account = {password: hashPassword(formData.password)};
gDatabase.set("user:" + formData.name, JSON.stringify(account)); gDatabase.set("user:" + formData.name, JSON.stringify(account));

View File

@ -172,6 +172,13 @@ async function getProcessBlob(blobId, key, options) {
} }
}, },
'user': getUser(process, process), 'user': getUser(process, process),
'users': function() {
try {
return JSON.parse(new Database('auth').get('users'));
} catch {
return [];
}
},
'apps': user => getApps(user, process), 'apps': user => getApps(user, process),
'getSockets': getSockets, 'getSockets': getSockets,
'permissionTest': function(permission) { 'permissionTest': function(permission) {