Lockit CouchDB adapter

CouchDB adapter for Lockit.
Installation
npm install lockit-couchdb-adapter
var adapter = require('lockit-couchdb-adapter');
Configuration
The adapter automatically saves the necessary views to your CouchDB.
You only need the connection string in your config.js
.
exports.db = 'http://127.0.0.1:5984/';
or (long format with custom per-user-db prefix)
exports.db = {
url: 'http://127.0.0.1:5984/',
prefix: 'custom/'
}
Features
1. Create user
adapter.save(name, email, pass, callback)
name
: String - i.e. 'john'email
: String - i.e. 'john@email.com'pass
: String - i.e. 'password123'callback
: Function - callback(err, user)
where user
is the new user now in our database.
The user
object has the following properties
_id
: unique id from CouchDB_rev
: revision from CouchDBpassword_scheme
: pbkdf2iterations
: pbkdf2 iterationsname
: name chosen during sign upemail
: email that was provided at the beginningroles
: Array with roles a user has, default is ['user']
type
: document type for views, default is 'user'signupToken
: unique token sent to user's email for email verificationsignupTimestamp
: Date object to remember when the user signed upsignupTokenExpires
: Date object usually 24h ahead of signupTimestamp
failedLoginAttempts
: save failed login attempts during login process, default is 0
derived_key
: password hash generated by pbkdf2salt
: salt generated by crypto.randomBytes()
adapter.save('john', 'john@email.com', 'secret', function(err, user) {
if (err) console.log(err);
console.log(user);
});
2. Find user
adapter.find(match, query, callback)
match
: String - one of the following: 'name', 'email' or 'signupToken'query
: String - corresponds to match
, i.e. 'john@email.com'callback
: Function - callback(err, user)
adapter.find('name', 'john', function(err, user) {
if (err) console.log(err);
console.log(user);
});
3. Update user
adapter.update(user, callback)
user
: Object - must have _id
and _rev
propertiescallback
: Function - callback(err, user)
- user
is the updated user object
adapter.find('name', 'john', function(err, user) {
if (err) console.log(err);
user.newKey = 'and some value';
user.hasBeenUpdated = true;
adapter.update(user, function(err, user) {
if (err) console.log(err);
});
});
4. Delete user
adapter.remove(name, callback)
name
: Stringcallback
: Function - callback(err, res)
- res
is true
if everything went fine
adapter.remove('john', function(err, res) {
if (err) console.log(err);
console.log(res);
});
Test
grunt
License
Copyright (C) 2013 [Mirco Zeiss](mailto: mirco.zeiss@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.