Socket
Book a DemoInstallSign in
Socket

account-couch

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

account-couch

Implement the accounts interface using a couchdb backend

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

Account Couch

Implement the account interface using a couchdb backend with the couch-profile module

Build Status Dependency Status Status

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.sh
script/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 = require('account-couch')
var config = require('nconf').defaults({
  couch: {
    host: 'localhost',
    port: 5984,
    database: 'account_couch_test'
  }    
})
var db = require('cradle-nconf')(config)
// create the account object with the cradle db passed as a parameter to the constructor
var account = new Account(db)
var data = {
  email: 'foo@example.com',
  password: 'barPassword',
}
account.register(data, function (err, reply) {
  if (err) {
    inspect(err, 'error registering user account')
    return
  }
  inspect(reply, 'user account created correctly'
})

Login

To login an existing account, pass an object with an email, and a password fields set

var Account = require('account-couch')
var config = require('nconf').defaults({
  couch: {
    host: 'localhost',
    port: 5984,
    database: 'account_couch_test'
  }    
})
var db = require('cradle-nconf')(config)
// create the account object with the cradle db passed as a parameter to the constructor
var account = new Account(db)
var data = {
  email: 'foo@example.com',
  password: 'barPassword',
}
account.login(data, function (err, reply) {
  if (err) {
    inspect(err, 'error performing login for user account')
    return
  }
  inspect(reply, 'user account created correctly'
})

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 = require('account-couch')
var config = require('nconf').defaults({
  couch: {
    host: 'localhost',
    port: 5984,
    database: 'account_couch_test'
  }    
})
var db = require('cradle-nconf')(config)
// create the account object with the cradle db passed as a parameter to the constructor
var account = new Account(db)
var data = {
  email: 'foo@example.com',
  password: 'barPassword',
}
// get the profile by logging in
account.login(data, function (err, profile) {
  if (err) {
    inspect(err, 'error performing login for user account')
    return
  }
  inspect(profile, 'user account profile')
  account.serializeUser(profile, function (err, reply) {
    if (err) {
      inspect(err, 'error performing login for user account')
      return
    }
    inspect(reply, 'profile serialized to _id')
  })
})

Deserialize User

To deserialize an existing user account profile, pass an _id of the profile in the couchdb database

var Account = require('account-couch')
var config = require('nconf').defaults({
  couch: {
    host: 'localhost',
    port: 5984,
    database: 'account_couch_test'
  }    
})
var db = require('cradle-nconf')(config)
// create the account object with the cradle db passed as a parameter to the constructor
var account = new Account(db)
// an _id of a user profile in the couchdb database
var id = 'fooID'
account.deserializeUser(id, function (err, profile) {
  if (err) {
    inspect(err, 'error performing login for user account')
    return
  }
  inspect(profile, 'user account profile')
})

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 = require('account-couch')
var config = require('nconf').defaults({
  couch: {
    host: 'localhost',
    port: 5984,
    database: 'account_couch_test'
  }    
})
var db = require('cradle-nconf')(config)
// create the account object with the cradle db passed as a parameter to the constructor
var account = new Account(db)
var data = {
  email: 'foo@example.com',
  password: 'barPassword',
}
account.removeUser(data, function (err) {
  if (err) {
    inspect(err, 'error removing profile')
    return
  }
  inspect('user account profile removed')
})

Test

To run the test suite execute

# install development dependencies
npm install
# run tests
npm test

Keywords

accounts

FAQs

Package last updated on 01 May 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.