diff --git a/src/cloudron.js b/src/cloudron.js index ce409ec58..1fbbd0cbd 100644 --- a/src/cloudron.js +++ b/src/cloudron.js @@ -38,7 +38,6 @@ var apps = require('./apps.js'), progress = require('./progress.js'), safe = require('safetydance'), settings = require('./settings.js'), - SettingsError = settings.SettingsError, shell = require('./shell.js'), subdomains = require('./subdomains.js'), superagent = require('superagent'), @@ -149,43 +148,35 @@ function setTimeZone(ip, callback) { }); } -function activate(username, password, email, name, ip, callback) { +function activate(username, password, email, ip, callback) { assert.strictEqual(typeof username, 'string'); assert.strictEqual(typeof password, 'string'); assert.strictEqual(typeof email, 'string'); assert.strictEqual(typeof ip, 'string'); - assert(!name || typeof name, 'string'); assert.strictEqual(typeof callback, 'function'); debug('activating user:%s email:%s', username, email); setTimeZone(ip, function () { }); // TODO: get this from user. note that timezone is detected based on the browser location and not the cloudron region - if (!name) name = settings.getDefaultSync(settings.CLOUDRON_NAME_KEY); - - settings.setCloudronName(name, function (error) { - if (error && error.reason === SettingsError.BAD_FIELD) return callback(new CloudronError(CloudronError.BAD_NAME)); + user.createOwner(username, password, email, function (error, userObject) { + if (error && error.reason === UserError.ALREADY_EXISTS) return callback(new CloudronError(CloudronError.ALREADY_PROVISIONED)); + if (error && error.reason === UserError.BAD_USERNAME) return callback(new CloudronError(CloudronError.BAD_USERNAME)); + if (error && error.reason === UserError.BAD_PASSWORD) return callback(new CloudronError(CloudronError.BAD_PASSWORD)); + if (error && error.reason === UserError.BAD_EMAIL) return callback(new CloudronError(CloudronError.BAD_EMAIL)); if (error) return callback(new CloudronError(CloudronError.INTERNAL_ERROR, error)); - user.createOwner(username, password, email, function (error, userObject) { - if (error && error.reason === UserError.ALREADY_EXISTS) return callback(new CloudronError(CloudronError.ALREADY_PROVISIONED)); - if (error && error.reason === UserError.BAD_USERNAME) return callback(new CloudronError(CloudronError.BAD_USERNAME)); - if (error && error.reason === UserError.BAD_PASSWORD) return callback(new CloudronError(CloudronError.BAD_PASSWORD)); - if (error && error.reason === UserError.BAD_EMAIL) return callback(new CloudronError(CloudronError.BAD_EMAIL)); + clientdb.getByAppIdAndType('webadmin', clientdb.TYPE_ADMIN, function (error, result) { if (error) return callback(new CloudronError(CloudronError.INTERNAL_ERROR, error)); - clientdb.getByAppIdAndType('webadmin', clientdb.TYPE_ADMIN, function (error, result) { + // Also generate a token so the admin creation can also act as a login + var token = tokendb.generateToken(); + var expires = Date.now() + 24 * 60 * 60 * 1000; // 1 day + + tokendb.add(token, tokendb.PREFIX_USER + userObject.id, result.id, expires, '*', function (error) { if (error) return callback(new CloudronError(CloudronError.INTERNAL_ERROR, error)); - // Also generate a token so the admin creation can also act as a login - var token = tokendb.generateToken(); - var expires = Date.now() + 24 * 60 * 60 * 1000; // 1 day - - tokendb.add(token, tokendb.PREFIX_USER + userObject.id, result.id, expires, '*', function (error) { - if (error) return callback(new CloudronError(CloudronError.INTERNAL_ERROR, error)); - - callback(null, { token: token, expires: expires }); - }); + callback(null, { token: token, expires: expires }); }); }); }); diff --git a/src/routes/cloudron.js b/src/routes/cloudron.js index 249b326a6..77cfb8ecf 100644 --- a/src/routes/cloudron.js +++ b/src/routes/cloudron.js @@ -44,22 +44,19 @@ function activate(req, res, next) { if (typeof req.body.username !== 'string') return next(new HttpError(400, 'username must be string')); if (typeof req.body.password !== 'string') return next(new HttpError(400, 'password must be string')); if (typeof req.body.email !== 'string') return next(new HttpError(400, 'email must be string')); - if ('name' in req.body && typeof req.body.name !== 'string') return next(new HttpError(400, 'name must be a string')); var username = req.body.username; var password = req.body.password; var email = req.body.email; - var name = req.body.name || null; var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; debug('activate: username:%s ip:%s', username, ip); - cloudron.activate(username, password, email, name, ip, function (error, info) { + cloudron.activate(username, password, email, ip, function (error, info) { if (error && error.reason === CloudronError.ALREADY_PROVISIONED) return next(new HttpError(409, 'Already setup')); if (error && error.reason === CloudronError.BAD_USERNAME) return next(new HttpError(400, 'Bad username')); if (error && error.reason === CloudronError.BAD_PASSWORD) return next(new HttpError(400, 'Bad password')); if (error && error.reason === CloudronError.BAD_EMAIL) return next(new HttpError(400, 'Bad email')); - if (error && error.reason === CloudronError.BAD_NAME) return next(new HttpError(400, 'Bad name')); if (error) return next(new HttpError(500, error)); // Now let the api server know we got activated