diff --git a/src/mail_templates/password_reset.ejs b/src/mail_templates/password_reset.ejs index ddc50d6b4..1b397311f 100644 --- a/src/mail_templates/password_reset.ejs +++ b/src/mail_templates/password_reset.ejs @@ -1,6 +1,6 @@ <%if (format === 'text') { %> -Dear <%= username %>, +Dear <%= user.username || user.email %>, Someone, hopefully you, has requested your <%= fqdn %>'s account password be reset. If you did not request this reset, please ignore this message. diff --git a/src/mail_templates/user_event.ejs b/src/mail_templates/user_event.ejs index 4f9ddd388..580e59f70 100644 --- a/src/mail_templates/user_event.ejs +++ b/src/mail_templates/user_event.ejs @@ -2,7 +2,7 @@ Dear Admin, -User with name '<%= username %>' (<%= email %>) <%= event %> in the Cloudron at <%= fqdn %>. +User '<%= user.username %> <%= user.email %> <%= event %> in the Cloudron at <%= fqdn %>. You are receiving this email because you are an Admin of the Cloudron at <%= fqdn %>. diff --git a/src/mailer.js b/src/mailer.js index eb2cf9dbc..8c6131dc3 100644 --- a/src/mailer.js +++ b/src/mailer.js @@ -219,8 +219,8 @@ function mailUserEventToAdmins(user, event) { var mailOptions = { from: config.adminEmail(), to: adminEmails.join(', '), - subject: util.format('%s %s in Cloudron %s', user.username, event, config.fqdn()), - text: render('user_event.ejs', { fqdn: config.fqdn(), username: user.username, email: user.email, event: event, format: 'text' }), + subject: util.format('%s %s in Cloudron %s', user.username || user.email, event, config.fqdn()), + text: render('user_event.ejs', { fqdn: config.fqdn(), user: user, event: event, format: 'text' }), }; enqueue(mailOptions); @@ -276,12 +276,12 @@ function userAdded(user, inviteSent) { }); } -function userRemoved(username) { - assert.strictEqual(typeof username, 'string'); +function userRemoved(user) { + assert.strictEqual(typeof user, 'object'); - debug('Sending mail for userRemoved'); + debug('Sending mail for userRemoved.', user.id, user.email); - mailUserEventToAdmins({ username: username }, 'was removed'); + mailUserEventToAdmins(user, 'was removed'); } function adminChanged(user, admin) { @@ -296,7 +296,7 @@ function adminChanged(user, admin) { function passwordReset(user) { assert.strictEqual(typeof user, 'object'); - debug('Sending mail for password reset for user %s.', user.username); + debug('Sending mail for password reset for user %s.', user.email, user.id); var resetLink = config.adminOrigin() + '/api/v1/session/password/reset.html?reset_token=' + user.resetToken; @@ -304,7 +304,7 @@ function passwordReset(user) { from: config.adminEmail(), to: user.email, subject: 'Password Reset Request', - text: render('password_reset.ejs', { fqdn: config.fqdn(), username: user.username, resetLink: resetLink, format: 'text' }) + text: render('password_reset.ejs', { fqdn: config.fqdn(), user: user, resetLink: resetLink, format: 'text' }) }; enqueue(mailOptions); diff --git a/src/routes/user.js b/src/routes/user.js index 0f56b6968..ca93f4e77 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -169,11 +169,16 @@ function removeUser(req, res, next) { if (req.user.id === req.params.userId) return next(new HttpError(403, 'Not allowed to remove yourself.')); - user.remove(req.params.userId, function (error) { - if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'User not found')); + user.get(req.params.userId, function (error, userObject) { + if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'No such user')); if (error) return next(new HttpError(500, error)); - next(new HttpSuccess(204)); + user.remove(userObject, function (error) { + if (error && error.reason === UserError.NOT_FOUND) return next(new HttpError(404, 'No such user')); + if (error) return next(new HttpError(500, error)); + + next(new HttpSuccess(204)); + }); }); } diff --git a/src/user.js b/src/user.js index 47290b02e..2ad9de03a 100644 --- a/src/user.js +++ b/src/user.js @@ -209,17 +209,17 @@ function verifyWithEmail(email, password, callback) { }); } -function removeUser(userId, callback) { - assert.strictEqual(typeof userId, 'string'); +function removeUser(user, callback) { + assert.strictEqual(typeof user, 'object'); assert.strictEqual(typeof callback, 'function'); - userdb.del(userId, function (error) { + userdb.del(user, function (error) { if (error && error.reason === DatabaseError.NOT_FOUND) return callback(new UserError(UserError.NOT_FOUND)); if (error) return callback(new UserError(UserError.INTERNAL_ERROR, error)); callback(null); - mailer.userRemoved(userId); + mailer.userRemoved(user); }); }