diff --git a/core/auth.js b/core/auth.js index 7b3adf93..a9e9069e 100644 --- a/core/auth.js +++ b/core/auth.js @@ -101,6 +101,19 @@ function handler(request, response) { if (formData.register == "1") { if (!account && 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}); account = {password: hashPassword(formData.password)}; gDatabase.set("user:" + formData.name, JSON.stringify(account)); diff --git a/core/core.js b/core/core.js index efdaa54b..d8404d0a 100644 --- a/core/core.js +++ b/core/core.js @@ -172,6 +172,13 @@ async function getProcessBlob(blobId, key, options) { } }, 'user': getUser(process, process), + 'users': function() { + try { + return JSON.parse(new Database('auth').get('users')); + } catch { + return []; + } + }, 'apps': user => getApps(user, process), 'getSockets': getSockets, 'permissionTest': function(permission) {