Skip to content

Commit c8e9109

Browse files
Add support for external WebIDs registering with username & password
1 parent 1c09007 commit c8e9109

File tree

8 files changed

+713
-649
lines changed

8 files changed

+713
-649
lines changed

default-templates/new-account/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ <h3>Solid User Profile</h3>
1414
<div class="row">
1515
<div class="col-md-12">
1616
<p style="margin-top: 3em; margin-bottom: 3em;">
17-
Welcome to your Solid user profile.
17+
Welcome.
1818
</p>
1919
<p>
20-
Your Web ID is:<br />
20+
Web ID:<br />
2121

2222
<code>{{webId}}</code>
2323
</p>

default-templates/new-account/profile/card

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
<>
88
a foaf:PersonalProfileDocument ;
9-
foaf:maker <#me> ;
10-
foaf:primaryTopic <#me> .
9+
foaf:maker <{{webId}}> ;
10+
foaf:primaryTopic <{{webId}}> .
1111

12-
<#me>
12+
<{{webId}}>
1313
a foaf:Person ;
1414
a schema:Person ;
1515

@@ -18,6 +18,7 @@
1818
solid:account </> ; # link to the account uri
1919
pim:storage </> ; # root storage
2020

21+
solid:inbox </inbox/> ;
2122
ldp:inbox </inbox/> ;
2223

2324
pim:preferencesFile </settings/prefs.ttl> ; # private settings/preferences

default-views/account/register-form.hbs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,42 @@
88
</div>
99
{{/if}}
1010
<div class="row">
11-
<div class="col-md-12">
11+
<div class="col-md-6">
1212
<label for="username">Username:</label>
1313
<input type="text" class="form-control" name="username" id="username" placeholder="alice" />
1414
</div>
15+
<div class="col-md-6">&nbsp;</div>
1516
</div>
1617
<div class="row">
17-
<div class="col-md-12">
18+
<div class="col-md-6">
1819
<label for="password">Password:</label>
1920
<input type="password" class="form-control" name="password" id="password" />
2021
</div>
22+
<div class="col-md-6">&nbsp;</div>
2123
</div>
2224
<div class="row">
23-
<div class="col-md-12">
25+
<div class="col-md-6">
2426
<label for="name">Name:</label>
25-
<input type="name" class="form-control" name="name" id="name" />
27+
<input type="text" class="form-control" name="name" id="name" />
2628
</div>
29+
<div class="col-md-6">&nbsp;</div>
2730
</div>
2831
<div class="row">
29-
<div class="col-md-12">
32+
<div class="col-md-6">
3033
<label for="email">Email:</label>
34+
<p>Your email will only used for account recovery</p>
3135
<input type="email" class="form-control" name="email" id="email" />
3236
</div>
37+
<div class="col-md-6">&nbsp;</div>
38+
</div>
39+
<div class="row">
40+
<div class="col-md-6">
41+
<label for="externalWebId">(Optional) External WebID:</label>
42+
<p>We will generate a Web ID when you register, but if you
43+
already have a Web ID hosted elsewhere, enter it here</p>
44+
<input type="text" class="form-control" name="externalWebId" id="externalWebId" />
45+
</div>
46+
<div class="col-md-6">&nbsp;</div>
3347
</div>
3448
<input type="hidden" name="returnToUrl" value="{{returnToUrl}}" />
3549
</div>

lib/handlers/error-pages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const SELECT_PROVIDER_AUTH_METHODS = ['oidc']
1515
* @param next {Function}
1616
*/
1717
function handler (err, req, res, next) {
18-
debug('Error page because of ' + err)
18+
debug('Error page because of:', err)
1919

2020
let locals = req.app.locals
2121
let authMethod = locals.authMethod

lib/models/account-manager.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,16 +346,32 @@ class AccountManager {
346346
email: userData.email,
347347
name: userData.name,
348348
externalWebId: userData.externalWebId,
349-
webId: userData.webid || userData.webId ||
350-
this.accountWebIdFor(userData.username)
349+
localAccountId: userData.localAccountId,
350+
webId: userData.webid || userData.webId || userData.externalWebId
351351
}
352352

353-
if (!userConfig.username) {
354-
if (!userConfig.webId) {
353+
try {
354+
userConfig.webId = userConfig.webId || this.accountWebIdFor(userConfig.username)
355+
} catch (err) {
356+
if (err.message === 'Cannot construct uri for blank account name') {
355357
throw new Error('Username or web id is required')
358+
} else {
359+
throw err
356360
}
361+
}
357362

358-
userConfig.username = this.usernameFromWebId(userConfig.webId)
363+
if (userConfig.username) {
364+
if (userConfig.externalWebId && !userConfig.localAccountId) {
365+
// External Web ID exists, derive the local account id from username
366+
userConfig.localAccountId = this.accountWebIdFor(userConfig.username)
367+
.split('//')[1] // drop the https://
368+
}
369+
} else { // no username - derive it from web id
370+
if (userConfig.externalWebId) {
371+
userConfig.username = userConfig.externalWebId
372+
} else {
373+
userConfig.username = this.usernameFromWebId(userConfig.webId)
374+
}
359375
}
360376

361377
return UserAccount.from(userConfig)

lib/models/user-account.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ class UserAccount {
1313
* @param [options.webId] {string}
1414
* @param [options.name] {string}
1515
* @param [options.email] {string}
16+
* @param [options.externalWebId] {string}
17+
* @param [options.localAccountId] {string}
1618
*/
1719
constructor (options = {}) {
1820
this.username = options.username
1921
this.webId = options.webId
2022
this.name = options.name
2123
this.email = options.email
24+
this.externalWebId = options.externalWebId
25+
this.localAccountId = options.localAccountId
2226
}
2327

2428
/**

0 commit comments

Comments
 (0)