Skip to content

Commit 4bbf131

Browse files
Make views/ customizable like templates
1 parent 73d3c23 commit 4bbf131

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ inbox
1111
.acl
1212
config.json
1313
config/templates
14-
config/apps
14+
config/views
1515
settings
1616
.db/
1717
.nyc_output
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>Select Provider</title>
7+
<link rel="stylesheet" href="/common/css/bootstrap.min.css">
8+
</head>
9+
<body>
10+
<div class="container">
11+
<div>
12+
<h2>Select Provider</h2>
13+
</div>
14+
</div>
15+
<div class="container">
16+
<form method="post" action="/api/auth/discover">
17+
<div class="form-group">
18+
<label for="webid">WebID or server URL:</label>
19+
<input type="text" class="form-control" name="webid" id="webid" placeholder="databox.me" />
20+
<input type="hidden" name="returnToUrl" id="returnToUrl" value="" />
21+
</div>
22+
<button type="submit" class="btn btn-primary" id="discover">Submit</button>
23+
</form>
24+
</div>
25+
</body>
26+
</html>

lib/api/authn/webid-oidc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function middleware (oidc) {
3636

3737
// User-facing Authentication API
3838
router.get('/api/auth/discover', (req, res) => {
39-
res.sendFile('discover-provider.html', { root: './static/oidc/' })
39+
res.render('auth/select-provider')
4040
})
4141
router.post('/api/auth/discover', bodyParser, discoverProvider)
4242

lib/create-app.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ function createApp (argv = {}) {
5050
// Serve the public 'common' directory (for shared CSS files, etc)
5151
app.use('/common', express.static('common'))
5252

53+
const viewsPath = initDefaultViews(configPath)
54+
app.set('views', viewsPath)
55+
app.engine('.hbs', handlebars({ extname: '.hbs' }))
56+
app.set('view engine', '.hbs')
57+
5358
initAppLocals(app, argv, ldp)
5459

5560
initHeaders(app)
@@ -116,6 +121,15 @@ function initConfigPath (argv) {
116121
return configPath
117122
}
118123

124+
function initDefaultViews (configPath) {
125+
let defaultViewsPath = path.resolve('./default-views')
126+
let viewsPath = path.join(configPath, 'views')
127+
128+
ensureDirCopy(defaultViewsPath, viewsPath)
129+
130+
return viewsPath
131+
}
132+
119133
function initTemplateDirs (configPath) {
120134
let accountTemplatePath = ensureDirCopy(
121135
'./default-templates/new-account',
@@ -194,7 +208,6 @@ function initAuthentication (argv, app) {
194208

195209
// This is where the OIDC-enabled signup/signin apps live
196210
app.use('/', express.static(path.join(__dirname, '../static/oidc')))
197-
initAuthTemplates(app)
198211

199212
// Initialize the WebId-OIDC authentication routes/api, including:
200213
// user-facing Solid endpoints (/login, /logout, /api/auth/discover)
@@ -211,17 +224,6 @@ function initAuthentication (argv, app) {
211224
}
212225
}
213226

214-
/**
215-
* Sets up Handlebars to be used for auth-related views.
216-
*
217-
* @param app {Function} Express.js app instance
218-
*/
219-
function initAuthTemplates (app) {
220-
app.set('views', path.join(__dirname, '../views'))
221-
app.engine('.hbs', handlebars({ extname: '.hbs' }))
222-
app.set('view engine', '.hbs')
223-
}
224-
225227
/**
226228
* Sets up headers common to all Solid requests (CORS-related, Allow, etc).
227229
*

0 commit comments

Comments
 (0)