Account Couch
Implement the account interface using a couchdb backend with the couch-profile module
Installation
Install the module by executing
npm install -S account-couch
You will also need the views provided by the couch-profile module. You can add these to your couchdb database using the couchdb-update-views module.
# create a couchdb database named account_couch_test curl -X PUT localhost:5984/account_couch_test# install the couchdb-update-views module globally so the couchdb-update-views command is available on the command line npm install -g couchdb-update-views# add the couch-profile views to the newly created account_couch_test database couchdb-update-views --config test/config.json --docsDir node_modules/couch-profile/docs
You can perform the steps listed above by executing the travis before_install script with the command
script/createDatabase.shscript/createViews.sh
Usage
The account couch module implements and exports the following interface functions:
login
register
serializeUser
deserializeUser
removeUser
Register
To register a new account, pass an object with an email
, and a password
var Account = var config = var db = config// create the account object with the cradle db passed as a parameter to the constructorvar account = dbvar data = email: 'foo@example.com' password: 'barPassword'account
Login
To login an existing account, pass an object with an email
, and a password
fields set
var Account = var config = var db = config// create the account object with the cradle db passed as a parameter to the constructorvar account = dbvar data = email: 'foo@example.com' password: 'barPassword'account
Serialize User
To serialize an existing user account profile, pass a profile object to the serializeUser method. You will get back the _id
of the profile in the couchdb database
var Account = var config = var db = config// create the account object with the cradle db passed as a parameter to the constructorvar account = dbvar data = email: 'foo@example.com' password: 'barPassword'// get the profile by logging inaccount
Deserialize User
To deserialize an existing user account profile, pass an _id
of the profile in the couchdb database
var Account = var config = var db = config// create the account object with the cradle db passed as a parameter to the constructorvar account = db// an _id of a user profile in the couchdb databasevar id = 'fooID'account
Remove User
To completly remove an existing user account profile from the couchdb database, pass an object containing the email
and password
of the user account profile to be removed from the couchdb database
var Account = var config = var db = config// create the account object with the cradle db passed as a parameter to the constructorvar account = dbvar data = email: 'foo@example.com' password: 'barPassword'account
Test
To run the test suite execute
# install development dependencies npm install# run tests npm test