Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
sudo: false
language: node_js
node_js:
- "4.0"
- "5.0"
- "6.0"

cache:
directories:
- node_modules
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ $ solid --allow-signup --port 8443 --cert /path/to/cert --key /path/to/key --roo

Your users will have a dedicated folder under `./accounts`. Also, your root domain's website will be in `./accounts/yourdomain.tld`. New users can create accounts on `/accounts/new` and create new certificates on `/accounts/cert`. An easy-to-use sign-up tool is found on `/accounts`.

##### How can send emails to my users with my Gmail?

> To use Gmail you may need to configure ["Allow Less Secure Apps"](https://www.google.com/settings/security/lesssecureapps) in your Gmail account unless you are using 2FA in which case you would have to create an [Application Specific](https://security.google.com/settings/security/apppasswords) password. You also may need to unlock your account with ["Allow access to your Google account"](https://accounts.google.com/DisplayUnlockCaptcha) to use SMTP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason why Gmail is listed here, instead of plain SMTP config? It only makes sense if there was a different way of using the mailer with Gmail.

### Run the Linked Data Platform (intermediate)
If you don't want WebID Authentication and Web Access Control, you can run a simple Linked Data Platform.

Expand Down
17 changes: 17 additions & 0 deletions bin/lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ module.exports = function (program) {
// Prompt to the user
inquirer.prompt(questions)
.then((answers) => {
// setting email
if (answers.useEmail) {
answers.email = {
host: answers['email-host'],
port: answers['email-port'],
secure: true,
auth: {
user: answers['email-auth-user'],
pass: answers['email-auth-pass']
}
}
delete answers['email-host']
delete answers['email-port']
delete answers['email-auth-user']
delete answers['email-auth-pass']
}

// clean answers
Object.keys(answers).forEach((answer) => {
if (answer.startsWith('use')) {
Expand Down
52 changes: 51 additions & 1 deletion bin/lib/options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs')
const path = require('path')

module.exports = [
// {
Expand All @@ -11,7 +12,8 @@ module.exports = [
help: 'Root folder to serve (defaut: \'./\')',
question: 'Path to the folder you want to serve. Default is',
default: './',
prompt: true
prompt: true,
filter: (value) => path.resolve(value)
},
{
name: 'port',
Expand Down Expand Up @@ -162,6 +164,54 @@ module.exports = [
help: 'Enforce same origin policy in the ACL',
flag: true,
prompt: true
},
{
name: 'useEmail',
help: 'Do you want to set up an email service?',
flag: true,
prompt: true,
default: true
},
{
name: 'email-host',
help: 'Host of your email service',
prompt: true,
default: 'smtp.gmail.com',
when: (answers) => {
return answers.useEmail
}
},
{
name: 'email-port',
help: 'Port of your email service',
prompt: true,
default: '465',
when: (answers) => {
return answers.useEmail
}
},
{
name: 'email-auth-user',
help: 'User of your email service',
prompt: true,
when: (answers) => {
return answers.useEmail
},
validate: (value) => {
if (!value || value === '') {
return 'You must enter this information'
}
return true
}
},
{
name: 'email-auth-pass',
help: 'Password of your email service',
type: 'password',
prompt: true,
when: (answers) => {
return answers.useEmail
}
}
]

Expand Down
16 changes: 16 additions & 0 deletions bin/lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ module.exports = function (program) {
}

function bin (argv) {
if (!argv.email) {
argv.email = {
host: argv['emailHost'],
port: argv['emailPort'],
secure: true,
auth: {
user: argv['emailAuthUser'],
pass: argv['emailAuthPass']
}
}
delete argv['emailHost']
delete argv['emailPort']
delete argv['emailAuthUser']
delete argv['emailAuthPass']
}

// Set up --no-*
argv.live = !argv.noLive

Expand Down
8 changes: 7 additions & 1 deletion lib/create-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var proxy = require('./handlers/proxy')
var IdentityProvider = require('./identity-provider')
var vhost = require('vhost')
var path = require('path')
var EmailService = require('./email-service')

var corsSettings = cors({
methods: [
'OPTIONS', 'HEAD', 'GET', 'PATCH', 'POST', 'PUT', 'DELETE'
Expand All @@ -20,7 +22,7 @@ var corsSettings = cors({
origin: true
})

function createApp (argv) {
function createApp (argv = {}) {
var ldp = new LDP(argv)
var app = express()

Expand All @@ -42,6 +44,10 @@ function createApp (argv) {
// Setting options as local variable
app.locals.ldp = ldp

if (argv.email && argv.email.host) {
app.locals.email = new EmailService(argv.email)
}

var sessionSettings = {
secret: ldp.secret || uuid.v1(),
saveUninitialized: false,
Expand Down
25 changes: 25 additions & 0 deletions lib/email-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'

const nodemailer = require('nodemailer')
const extend = require('extend')

class EmailService {
constructor (settings = {}) {
// This reflects nodemailer string option, we allow it
if (typeof settings !== 'string') {
settings = extend(settings, {secure: true})
}
this.mailer = nodemailer.createTransport(settings)

if (settings.sender) {
this.sender = settings.sender
} else if (settings.host) {
this.sender = `no-reply@${settings.host}`
}
}
sendMail (email, callback) {
this.mailer.sendMail(email, callback)
}
}

module.exports = EmailService
17 changes: 17 additions & 0 deletions lib/identity-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ IdentityProvider.prototype.post = function (req, res, next) {
}

var self = this
var email = req.app.locals.email
var options = req.body
options.host = req.get('host')
options.firstUser = res.locals.firstUser
Expand All @@ -531,6 +532,22 @@ IdentityProvider.prototype.post = function (req, res, next) {
function (newCert, callback) {
cert = newCert
self.create(options, cert, callback)
},
function (callback) {
if (email && options.email) {
email.sendMail({
from: `"no-reply" <${email.sender}>`, // sender address
to: options.email,
subject: 'Account created',
text: 'Your account has been created',
html: '<b>Your account has been created</b>'
}, (err) => {
if (err) debug('Error sending email', err)
callback()
})
} else {
callback()
}
}
], function (err) {
if (err) {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"negotiator": "^0.6.0",
"node-forge": "^0.6.38",
"node-uuid": "^1.4.3",
"nodemailer": "^2.3.2",
"nomnom": "^1.8.1",
"rdflib": "^0.6.1",
"request": "^2.72.0",
Expand All @@ -60,6 +61,7 @@
"mocha": "^2.2.5",
"nock": "^7.0.2",
"rsvp": "^3.1.0",
"sinon": "^1.17.4",
"standard": "^6.0.4",
"supertest": "^1.0.1"
},
Expand Down
31 changes: 31 additions & 0 deletions test/email-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const EmailService = require('../lib/email-service')
const sinon = require('sinon')
const expect = require('chai').expect

describe('Email Service', function () {
let email, transport

beforeEach(() => {
transport = {
name: 'testsend',
version: '1',
send: function (data, callback) {
callback()
},
logger: false
}
email = new EmailService(transport)
})

it('should send emails', (done) => {
sinon.stub(transport, 'send').yields(null, 'bep bop')

email.sendMail({
subject: 'test'
}, function (err, info) {
expect(err).to.not.exist
expect(info).to.equal('bep bop')
done()
})
})
})