CouchDB adapter for Lockit.
npm install lockit-couchdb-adapter
var adapter = require('lockit-couchdb-adapter');
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/';
adapter.save(name, email, pass, callback)
name
: String - i.e. 'john'email
: String - i.e. '[email protected]'pass
: String - i.e. 'password123'callback
: Function -callback(err, user)
whereuser
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 ofsignupTimestamp
failedLoginAttempts
: save failed login attempts during login process, default is0
derived_key
: password hash generated by pbkdf2salt
: salt generated bycrypto.randomBytes()
adapter.save('john', '[email protected]', 'secret', function(err, user) {
if (err) console.log(err);
console.log(user);
// {
// _id: '8c7cd00c55a25ceb279a8e893d011b3e',
// _rev: '1-530a4cd8e67d51daf74e059899c39cd5',
// password_scheme: 'pbkdf2',
// iterations: 10,
// name: 'john',
// email: '[email protected]',
// roles: [ 'user' ],
// type: 'user',
// signupToken: 'fed26ce9-2628-405a-b9fa-285d4a66f4c3',
// signupTimestamp: '2013-09-21T10:10:50.357Z',
// signupTokenExpires: '2014-01-15T15:27:29.020Z',
// failedLoginAttempts: 0,
// derived_key: '0a2b1714d6017e7efdc1154ee34c805dea29c06a',
// salt: '3a213c87b6a33c70fec767acea697994'
// }
});
adapter.find(match, query, callback)
match
: String - one of the following: 'name', 'email' or 'signupToken'query
: String - corresponds tomatch
, i.e. '[email protected]'callback
: Function -callback(err, user)
adapter.find('name', 'john', function(err, user) {
if (err) console.log(err);
console.log(user);
// {
// _id: '8c7cd00c55a25ceb279a8e893d011b3e',
// _rev: '1-530a4cd8e67d51daf74e059899c39cd5',
// password_scheme: 'pbkdf2',
// iterations: 10,
// name: 'john',
// email: '[email protected]',
// roles: [ 'user' ],
// type: 'user',
// signupToken: 'fed26ce9-2628-405a-b9fa-285d4a66f4c3',
// signupTimestamp: '2013-09-21T10:10:50.357Z',
// signupTokenExpires: '2014-01-15T15:27:29.020Z',
// failedLoginAttempts: 0,
// derived_key: '0a2b1714d6017e7efdc1154ee34c805dea29c06a',
// salt: '3a213c87b6a33c70fec767acea697994'
// }
});
adapter.update(user, callback)
user
: Object - must have_id
and_rev
propertiescallback
: Function -callback(err, user)
-user
is the updated user object
// get a user from db first
adapter.find('name', 'john', function(err, user) {
if (err) console.log(err);
// add some new properties to our existing user
user.newKey = 'and some value';
user.hasBeenUpdated = true;
// save updated user to db
adapter.update(user, function(err, user) {
if (err) console.log(err);
// ...
});
});
adapter.remove(name, callback)
name
: Stringcallback
: Function -callback(err, res)
-res
istrue
if everything went fine
adapter.remove('john', function(err, res) {
if (err) console.log(err);
console.log(res);
// true
});
grunt
Copyright (C) 2013 [Mirco Zeiss](mailto: [email protected])
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.