tthew / hapi-account

Tiny hapi server with a front-end account API, backed by CouchDB

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hapi-account

Account REST and front-end API

Scope

  1. Expose a RESTful API for all common account functionality for both, users and admins
  2. Expose a client API, wrapping the RESTful API.
  3. Allow both to be configured at once (e.g. validation)

Current state

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.

User client

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()

Built-in request types

hapi-accounts comes with handlers for two requests:

  1. 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'})
  2. 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

Full specifications

Server API

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:

About

Tiny hapi server with a front-end account API, backed by CouchDB