location -> loginLocations

This commit is contained in:
Girish Ramakrishnan
2021-04-30 10:07:04 -07:00
parent 44027f61e6
commit 6fe8974a2d
4 changed files with 16 additions and 18 deletions

View File

@@ -32,7 +32,7 @@ var assert = require('assert'),
// the avatar field is special and not added here to reduce response sizes
const USERS_FIELDS = [ 'id', 'username', 'email', 'fallbackEmail', 'password', 'salt', 'createdAt', 'resetToken', 'displayName',
'twoFactorAuthenticationEnabled', 'twoFactorAuthenticationSecret', 'active', 'source', 'role', 'resetTokenCreationTime', 'locationJson' ].join(',');
'twoFactorAuthenticationEnabled', 'twoFactorAuthenticationSecret', 'active', 'source', 'role', 'resetTokenCreationTime', 'loginLocationsJson' ].join(',');
const APP_PASSWORD_FIELDS = [ 'id', 'name', 'userId', 'identifier', 'hashedPassword', 'creationTime' ].join(',');
@@ -42,10 +42,8 @@ function postProcess(result) {
result.twoFactorAuthenticationEnabled = !!result.twoFactorAuthenticationEnabled;
result.active = !!result.active;
// we remove the JSON first locations property, it is only there to have a valid JSON, no toplevel array
const tmp = safe.JSON.parse(result.locationJson) || { locations: [] };
result.locations = tmp.locations || [];
delete result.locationJson;
result.loginLocations = safe.JSON.parse(result.loginLocationsJson) || [];
delete result.loginLocationsJson;
return result;
}
@@ -244,7 +242,7 @@ function update(userId, user, callback) {
assert(!('twoFactorAuthenticationEnabled' in user) || (typeof user.twoFactorAuthenticationEnabled === 'boolean'));
assert(!('role' in user) || (typeof user.role === 'string'));
assert(!('active' in user) || (typeof user.active === 'boolean'));
assert(!('locations' in user) || (Array.isArray(user.locations)));
assert(!('loginLocations' in user) || (Array.isArray(user.loginLocations)));
var args = [ ];
var fields = [ ];
@@ -252,9 +250,9 @@ function update(userId, user, callback) {
if (k === 'twoFactorAuthenticationEnabled' || k === 'active') {
fields.push(k + ' = ?');
args.push(user[k] ? 1 : 0);
} else if (k === 'locations') {
fields.push('locationJson = ?');
args.push(JSON.stringify({ locations: user[k] || []}));
} else if (k === 'loginLocations') {
fields.push('loginLocationsJson = ?');
args.push(JSON.stringify({ loginLocations: user[k] }));
} else {
fields.push(k + ' = ?');
args.push(user[k]);