Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Merge pull request #876 from shane-tomlinson/issue-875-notification-e…
Browse files Browse the repository at this point in the history
…mails

Issue 875 notification emails
  • Loading branch information
rfk committed Jun 18, 2015
2 parents 75573f6 + 34ae5d0 commit dca5a5d
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 15 deletions.
6 changes: 6 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ var conf = convict({
env: 'UNLOCK_URL',
arg: 'unlock-url'
},
initiatePasswordResetUrl: {
doc: 'Deprecated. uses contentServer.url',
format: String,
default: undefined
},
redirectDomain: {
doc: 'Domain that mail urls are allowed to redirect to',
format: String,
Expand Down Expand Up @@ -303,6 +308,7 @@ conf.set('domain', url.parse(conf.get('publicUrl')).host)
conf.set('smtp.verificationUrl', conf.get('contentServer.url') + '/v1/verify_email')
conf.set('smtp.passwordResetUrl', conf.get('contentServer.url') + '/v1/complete_reset_password')
conf.set('smtp.accountUnlockUrl', conf.get('contentServer.url') + '/v1/complete_unlock_account')
conf.set('smtp.initiatePasswordResetUrl', conf.get('contentServer.url') + '/v1/reset_password')

var options = {
strict: true
Expand Down
24 changes: 24 additions & 0 deletions lib/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ module.exports = function (config, log) {
}
))
}
mailer.sendPasswordChangedNotification = function (email, opts) {
return P.resolve(mailer.passwordChangedEmail(
{
email: email,
acceptLanguage: opts.acceptLanguage || defaultLanguage
}
))
}
mailer.sendPasswordResetNotification = function (email, opts) {
return P.resolve(mailer.passwordResetEmail(
{
email: email,
acceptLanguage: opts.acceptLanguage || defaultLanguage
}
))
}
mailer.sendNewSyncDeviceNotification = function (email, opts) {
return P.resolve(mailer.newSyncDeviceEmail(
{
email: email,
acceptLanguage: opts.acceptLanguage || defaultLanguage
}
))
}
return mailer
}
)
Expand Down
19 changes: 19 additions & 0 deletions lib/routes/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,25 @@ module.exports = function (
)
}
)
.then(
function (tokens) {
if (request.payload.service === 'sync' && request.payload.reason === 'signin') {
return mailer.sendNewSyncDeviceNotification(
emailRecord.email,
{
acceptLanguage: request.app.acceptLanguage
}
)
.then(
function () {
return tokens
}
)
}

return tokens
}
)
}
)
.done(
Expand Down
31 changes: 31 additions & 0 deletions lib/routes/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ module.exports = function (
)
}
)
.then(
function () {
return db.account(passwordChangeToken.uid)
.then(
function (account) {
return mailer.sendPasswordChangedNotification(
account.email,
{
acceptLanguage: request.app.acceptLanguage

}
)
}
)
}
)
.then(
function () {
return {}
Expand Down Expand Up @@ -313,6 +329,21 @@ module.exports = function (
if (butil.buffersAreEqual(passwordForgotToken.passCode, code) &&
passwordForgotToken.ttl() > 0) {
db.forgotPasswordVerified(passwordForgotToken)
.then(
function (accountResetToken) {
return mailer.sendPasswordResetNotification(
passwordForgotToken.email,
{
acceptLanguage: request.app.acceptLanguage
}
)
.then(
function () {
return accountResetToken
}
)
}
)
.done(
function (accountResetToken) {
reply(
Expand Down
28 changes: 14 additions & 14 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion test/remote/account_login_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var test = require('../ptaptest')
var url = require('url')
var TestServer = require('../test_server')
var crypto = require('crypto')
var Client = require('../client')
Expand Down Expand Up @@ -96,7 +97,7 @@ TestServer.start(config)
)

test(
'accepts a `reason` and `service`',
'sync signin sends an email',
function (t) {
var email = server.uniqueEmail()
var password = 'abcdef'
Expand All @@ -108,6 +109,14 @@ TestServer.start(config)
)
.then(
function (c) {
return server.mailbox.waitForEmail(email)
}
)
.then(
function (emailData) {
var link = emailData.headers['x-link']
var query = url.parse(link, true).query
t.ok(query.email, 'email is in the link')
}
)
}
Expand Down
10 changes: 10 additions & 0 deletions test/remote/password_change_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var test = require('../ptaptest')
var url = require('url')
var Client = require('../client')
var TestServer = require('../test_server')

Expand Down Expand Up @@ -51,6 +52,15 @@ TestServer.start(config)
function (keys) {
t.deepEqual(keys.kB, kB, 'kB is preserved')
t.deepEqual(keys.kA, kA, 'kA is preserved')

return server.mailbox.waitForEmail(email)
}
)
.then(
function (emailData) {
var link = emailData.headers['x-link']
var query = url.parse(link, true).query
t.ok(query.email, 'email is in the link')
}
)
}
Expand Down
9 changes: 9 additions & 0 deletions test/remote/password_forgot_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ TestServer.start(config)
t.ok(Buffer.isBuffer(keys.kA), 'kA exists, login after password reset')
t.ok(Buffer.isBuffer(keys.wrapKb), 'wrapKb exists, login after password reset')
t.equal(client.kB.length, 32, 'kB exists, has the right length')

return server.mailbox.waitForEmail(email)
}
)
.then(
function (emailData) {
var link = emailData.headers['x-link']
var query = url.parse(link, true).query
t.ok(query.email, 'email is in the link')
}
)
}
Expand Down

0 comments on commit dca5a5d

Please sign in to comment.