Skip to content

Commit ba19269

Browse files
committed
adding signup route
1 parent 1f0a7d2 commit ba19269

5 files changed

Lines changed: 85 additions & 8 deletions

File tree

bin/ldnode.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ var argv = require('nomnom')
103103
help: 'URI to use as a default app for resources (default: https://linkeddata.github.io/warp/#/list/)'
104104
})
105105
.option('signup', {
106-
help: 'Creates a WebID and sets it as owner'
106+
help: 'Creates a WebID and sets it as owner',
107+
flag: true
107108
})
108109
.parse();
109110

lib/create-app.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,26 @@ function createApp (argv) {
5050
}
5151

5252
// Adding Multi-user support
53-
if (ldp.idp) {
53+
if (ldp.idp || ldp.signup) {
5454
var idp = IdentityProvider({
5555
store: ldp,
5656
suffixAcl: ldp.suffixAcl
5757
})
5858
app.use('/accounts', idp.middleware(corsSettings));
5959
app.use('/', corsSettings, idp.get.bind(idp))
60+
}
61+
62+
if (ldp.idp) {
6063
app.use(vhost('*', LdpMiddleware(corsSettings)));
6164
}
6265

63-
// Setting up routes
66+
if (ldp.signup) {
67+
app.get('/', function (req, res) {
68+
res.set('Content-Type', 'text/html');
69+
res.sendFile('../static/signup.html');
70+
});
71+
}
72+
6473
app.use('/', LdpMiddleware(corsSettings));
6574

6675
return app;

lib/ldp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function LDP(argv) {
3131
ldp.root += '/';
3232
}
3333
ldp.secret = argv.secret;
34+
ldp.signup = argv.signup;
3435
ldp.webid = argv.webid;
3536
ldp.idp = argv.idp;
3637
ldp.leavePatchConnectionOpen = false;

static/signup.html

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Ldnode: Admin Signup</title>
5+
</head>
6+
7+
<body>
8+
9+
<form id="accounts">
10+
<input type="email">
11+
</form>
12+
13+
<form id="cert" method="POST" action='/accounts/cert' target="spkacResult">
14+
<keygen name="spkac" >
15+
<input name="webid">
16+
<button onclick='createGen()'></button>
17+
</form>
18+
19+
<script type="text/javascript">
20+
21+
var email = document.querySelector("#email").value
22+
23+
function createAccount (email, callback) {
24+
var hostname = location.hostname
25+
var url = '/accounts/new'
26+
var data = "email=" + email;
27+
28+
var http = new XMLHttpRequest()
29+
http.open('POST', url)
30+
http.withCredentials = true
31+
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
32+
http.onreadystatechange = function() {
33+
if (this.readyState !== this.DONE
34+
|| this.status !== 200) {
35+
return callback(new Error('Request failed'))
36+
}
37+
var webid = this.getResponseHeader("User")
38+
if (!webid || webid.length === 0) {
39+
return callback(new Error('WebID is not set in User'))
40+
}
41+
42+
callback(null, webid)
43+
// Account is created
44+
}
45+
http.send(data);
46+
}
47+
48+
function createGen () {
49+
var iframe = document.createElement('iframe')
50+
iframe.name = 'spkacResult'
51+
iframe.style.visibility = 'none'
52+
iframe.style.width = '0px'
53+
iframe.style.height = '0px'
54+
document.querySelector('body').appendChild(iframe)
55+
56+
iframe.onload = function () {
57+
var done = document.createElement('div')
58+
done.innerHTML = '<p>restart your server without --signup</p>'
59+
document.querySelector('body').appendChild(done)
60+
}
61+
}
62+
63+
document.querySelector('#cert').style.display = 'none'
64+
createAccount(email, function (err, webid) {
65+
document.querySelector('#accounts').style.display = 'none'
66+
document.querySelector('#cert').style.display = ''
67+
document.querySelector('#webid').value = webid
68+
})
69+
</script>
70+
</body>
71+
</html>

test/identity-provider.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,6 @@ describe('Identity Provider', function () {
116116
rm('accounts/nicola.localhost')
117117
})
118118

119-
it('should return 406 if username is not given', function (done) {
120-
var subdomain = supertest('https://nicola.' + host)
121-
subdomain.post('/accounts/new')
122-
.expect(406, done)
123-
})
124119
it('should return create WebID if only username is given', function (done) {
125120
var subdomain = supertest('https://nicola.' + host)
126121
subdomain.post('/accounts/new')

0 commit comments

Comments
 (0)