Account REST and front-end API
- Expose a RESTful API for all common account functionality for both, users and admins
- Expose a client API, wrapping the RESTful API.
- Allow both to be configured at once (e.g. validation)
This is all Dream Code at this point, nothing is implemented yet. Let us know what you think! At at least the front-end API needs to be fixed by August 1st, when we start with the implementation.
To load the hapi-account
front-end client, add <script src="/account.js"></script>
to
your HTML page. The account
object becomes available, with the following properties and
methods:
account.username
account.isSignedIn()
account.signUp()
account.confirm()
account.signIn()
account.signOut()
account.request()
account.get()
account.fetch()
account.update()
account.validate()
hapi-accounts
comes with handlers for two requests:
-
passwordreset
Request a token to reset a password. Requires
email
(String) property.POST /requests { "type": "passwordreset", "email": "john@example.com" }
or via account user client
account.request('passwordreset', {email: 'john@example.co'})
-
confirmation
Request email with confirmation token, in case it didn't arrive when sent on sign up. Requires
email
(String) property.POST /requests { "type": "confirmation", "email": "john@example.com" }
or via account user client
account.request('confirmation', {email: 'john@example.co'})
Custom request handlers can be can be defined in the server API. The notification templates can be configured in options.notifications.templates
var Hapi = require('hapi')
var hapiAccount = require('hapi-account')
var options = {
adapter: {
couchDb: 'http://admin:secret@localhost:5984'
}
})
server.register({register: hapiAccount}, options, function (error) {
// server is ready
});
server.connection({
port: 8000
});
server.start(function () {
console.log('Server running at %s', server.info.uri);
});
Full specifications: