Skip to content

Commit f482c6f

Browse files
committed
adding command line for email
1 parent f893bc4 commit f482c6f

5 files changed

Lines changed: 88 additions & 0 deletions

File tree

bin/lib/init.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ module.exports = function (program) {
3131
// Prompt to the user
3232
inquirer.prompt(questions)
3333
.then((answers) => {
34+
// setting email
35+
if (answers.useEmail) {
36+
answers.email = {
37+
host: answers['email-host'],
38+
port: answers['email-port'],
39+
secure: true,
40+
auth: {
41+
user: answers['email-auth-user'],
42+
pass: answers['email-auth-pass']
43+
}
44+
}
45+
delete answers['email-host']
46+
delete answers['email-port']
47+
delete answers['email-auth-user']
48+
delete answers['email-auth-pass']
49+
}
50+
3451
// clean answers
3552
Object.keys(answers).forEach((answer) => {
3653
if (answer.startsWith('use')) {

bin/lib/options.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,54 @@ module.exports = [
162162
help: 'Enforce same origin policy in the ACL',
163163
flag: true,
164164
prompt: true
165+
},
166+
{
167+
name: 'useEmail',
168+
help: 'Do you want to set up an email service?',
169+
flag: true,
170+
prompt: true,
171+
default: true
172+
},
173+
{
174+
name: 'email-host',
175+
help: 'Host of your email service',
176+
prompt: true,
177+
default: 'smtp.gmail.com',
178+
when: (answers) => {
179+
return answers.useEmail
180+
}
181+
},
182+
{
183+
name: 'email-port',
184+
help: 'Port of your email service',
185+
prompt: true,
186+
default: '465',
187+
when: (answers) => {
188+
return answers.useEmail
189+
}
190+
},
191+
{
192+
name: 'email-auth-user',
193+
help: 'User of your email service',
194+
prompt: true,
195+
when: (answers) => {
196+
return answers.useEmail
197+
},
198+
validate: (value) => {
199+
if (!value || value === '') {
200+
return 'You must enter this information'
201+
}
202+
return true
203+
}
204+
},
205+
{
206+
name: 'email-auth-pass',
207+
help: 'Password of your email service',
208+
type: 'password',
209+
prompt: true,
210+
when: (answers) => {
211+
return answers.useEmail
212+
}
165213
}
166214
]
167215

bin/lib/start.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = function (program) {
4444
}
4545

4646
function bin (argv) {
47+
4748
// Set up --no-*
4849
argv.live = !argv.noLive
4950

lib/email-service.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ class EmailService {
1010
settings = extend(settings, {secure: true})
1111
}
1212
this.mailer = nodemailer.createTransport(settings)
13+
14+
if (settings.sender) {
15+
this.sender = settings.sender
16+
} else if (settings.host) {
17+
this.sender = `no-reply@${settings.host}`
18+
}
1319
}
1420
sendMail (email, callback) {
1521
console.log(this.mailer)

lib/identity-provider.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ IdentityProvider.prototype.post = function (req, res, next) {
508508
}
509509

510510
var self = this
511+
var email = req.app.locals.email
511512
var options = req.body
512513
options.host = req.get('host')
513514
options.firstUser = res.locals.firstUser
@@ -531,8 +532,23 @@ IdentityProvider.prototype.post = function (req, res, next) {
531532
function (newCert, callback) {
532533
cert = newCert
533534
self.create(options, cert, callback)
535+
},
536+
function (callback) {
537+
if (email) {
538+
email.sendEmail({
539+
from: `"no-reply" <${email.sender}>`, // sender address
540+
to: options.email,
541+
subject: 'Account created',
542+
text: 'Your account has been created',
543+
html: '<b>Your account has been created</b>'
544+
}, callback)
545+
} else {
546+
callback()
547+
}
534548
}
535549
], function (err) {
550+
// TODO at the moment this will collect the email error
551+
// maybe we don't need to do so
536552
if (err) {
537553
err.status = err.status || 500
538554
debug('Error creating ' + options.user + ': ' + err.message)

0 commit comments

Comments
 (0)