Skip to content

Commit

Permalink
web monetize immers pages
Browse files Browse the repository at this point in the history
  • Loading branch information
wmurphyrd committed Oct 25, 2020
1 parent 5c62f19 commit ceb720f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ smtpFrom | From address for emails (match mail domain configured in hubs)
keyPath | Relative path to SSL private key (`privkey.pem`)
certPath | Relative path to SSL certificate (`cert.pem`)
caPath | Relative path to SSL certificate authority (`chain.pem`)
monetizationPointer | Optional. Adding a payment pointer here activates Web Monetization

* Copy `secrets-emplate.json` to `secrets.json` and edit to configure secrets

Expand Down
6 changes: 4 additions & 2 deletions config-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"port": 8081,
"domain": "localhost:8081",
"hub": "localhost:8080",
"homepage": null,
"name": "My Immer",
"dbName": "immers",
"smtpHost": "smtp.example.com",
"smtpPort": 587,
"smtpFrom": "[email protected]",
"keyPath": "certs/server.key",
"certPath": "certs/server.cert"
}
"certPath": "certs/server.cert",
"monetizationPointer": null
}
15 changes: 13 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ const nunjucks = require('nunjucks')
const passport = require('passport')
const auth = require('./src/auth')

const { port, domain, hub, homepage, name, dbName, keyPath, certPath, caPath } = require('./config.json')
const {
port,
domain,
hub,
homepage,
name,
dbName,
keyPath,
certPath,
caPath,
monetizationPointer
} = require('./config.json')
const { sessionSecret } = require('./secrets.json')
const app = express()
const routes = {
Expand Down Expand Up @@ -62,7 +73,7 @@ app.use(apex)
app.options('*', cors())

/// auth related routes
app.get('/auth/login', (req, res) => res.render('login.njk', { domain }))
app.get('/auth/login', (req, res) => res.render('login.njk', { domain, monetizationPointer }))
// local users - send login email; remote users - find redirect url
app.post('/auth/login', auth.homeImmer, passport.authenticate('easy'), (req, res) => {
return res.json({ emailed: true })
Expand Down
2 changes: 1 addition & 1 deletion secrets-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"easySecret": "",
"smtpUser": "",
"smtpPassword": ""
}
}
10 changes: 8 additions & 2 deletions src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const EasyNoPassword = require('easy-no-password').Strategy
const BearerStrategy = require('passport-http-bearer').Strategy
const AnonymousStrategy = require('passport-anonymous').Strategy
const authdb = require('./authdb')
const { domain, name, hub, smtpHost, smtpPort, smtpFrom } = require('../config.json')
const { domain, name, hub, smtpHost, smtpPort, smtpFrom, monetizationPointer } = require('../config.json')
const { easySecret, smtpUser, smtpPassword } = require('../secrets.json')
let transporter
if (process.env.NODE_ENV === 'production') {
Expand Down Expand Up @@ -210,7 +210,13 @@ module.exports = {
return done(null, false)
}),
(request, response) => {
response.render('dialog.njk', { transactionId: request.oauth2.transactionID, user: request.user, client: request.oauth2.client })
const data = {
transactionId: request.oauth2.transactionID,
user: request.user,
client: request.oauth2.client,
monetizationPointer
}
response.render('dialog.njk', data)
}
],
// process result of auth dialog form
Expand Down
3 changes: 3 additions & 0 deletions views/layout.njk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<html style="background-color: #a6549d;">
<head>
<title>{% block title %}immers.space{% endblock %}</title>
{% if monetizationPointer %}
<meta name="monetization" content="{{ monetizationPointer }}">
{% endif %}
<!-- FOUC protection -->
<style>body {display: none;}</style>
<link rel="stylesheet" type="text/css" href="/static/aesthetic.css">
Expand Down

0 comments on commit ceb720f

Please sign in to comment.