tokens: async'ify

This commit is contained in:
Girish Ramakrishnan
2021-06-04 09:28:40 -07:00
parent 593038907c
commit 7bee7b9ef8
16 changed files with 517 additions and 727 deletions
+12 -11
View File
@@ -137,23 +137,24 @@ function activate(username, password, email, displayName, ip, auditSource, callb
debug('activating user:%s email:%s', username, email);
users.createOwner(username, password, email, displayName, auditSource, function (error, userObject) {
users.createOwner(username, password, email, displayName, auditSource, async function (error, userObject) {
if (error && error.reason === BoxError.ALREADY_EXISTS) return callback(new BoxError(BoxError.CONFLICT, 'Already activated'));
if (error) return callback(error);
tokens.add(tokens.ID_WEBADMIN, userObject.id, Date.now() + constants.DEFAULT_TOKEN_EXPIRATION_MSECS, {}, function (error, result) {
if (error) return callback(error);
const token = { clientId: tokens.ID_WEBADMIN, identifier: userObject.id, expires: Date.now() + constants.DEFAULT_TOKEN_EXPIRATION_MSECS };
let result;
[error, result] = await safe(tokens.add(token));
if (error) return callback(error);
eventlog.add(eventlog.ACTION_ACTIVATE, auditSource, { });
eventlog.add(eventlog.ACTION_ACTIVATE, auditSource, { });
callback(null, {
userId: userObject.id,
token: result.accessToken,
expires: result.expires
});
setImmediate(cloudron.onActivated.bind(null, {}, NOOP_CALLBACK)); // hack for now to not block the above http response
callback(null, {
userId: userObject.id,
token: result.accessToken,
expires: result.expires
});
setImmediate(cloudron.onActivated.bind(null, {}, NOOP_CALLBACK)); // hack for now to not block the above http response
});
}