Redis adapter for Lockit.
npm install lockit-redis-adapter
var adapter = require('lockit-redis-adapter');
The following settings are required.
exports.db = 'redis';
exports.dbip = '127.0.0.1';
exports.dbport = 6379;
exports.dbpass = 'mypassword'; //Optional
exports.dbPrefix = 'users';
exports.signupTokenExpiration = 259200000; // 5 days
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)
whereuser
is the new user now in our database.
The user
object has the following properties
-
email
: email that was provided at the beginning -
hash
: hashed password using bcrypt -
signupTimestamp
: Date object to remember when the user signed up -
signupToken
: unique token sent to user's email for email verification -
signupTokenExpires
: Date object usually 24h ahead ofsignupTimestamp
-
username
: username chosen during sign up -
failedLoginAttempts
: save failed login attempts during login process, default is0
adapter.save('john', 'john@email.com', 'secret', function(err, user) {
if (err) console.log(err);
console.log(user);
// {
// username: 'john',
// email: 'john@email.com',
// signupToken: 'ef32a95a-d6ee-405a-8e4b-515b235f7c54',
// signupTimestamp: Wed Jan 15 2014 19:08:27 GMT+0100 (CET),
// signupTokenExpires: Wed Jan 15 2014 19:08:27 GMT+0100 (CET),
// failedLoginAttempts: 0,
// hash: '$2a$10$1IpbBVnhaNNAymV3HXO/z.632Knz27Od.oKpO1YoFnLlUjJMNcCEO',
// }
});
adapter.find(match, query, callback)
-
match
: String - one of the following: 'username', 'email' or 'signupToken' -
query
: String - corresponds tomatch
, i.e. 'john@email.com' -
callback
: Function -callback(err, user)
adapter.find('username', 'john', function(err, user) {
if (err) console.log(err);
console.log(user);
// {
// username: 'john',
// email: 'john@email.com',
// signupToken: 'fe1a14ca-e614-4eb5-9dff-d5d947b5ba19',
// signupTimestamp: Wed Jan 15 2014 19:10:53 GMT+0100 (CET),
// signupTokenExpires: Wed Jan 15 2014 19:10:53 GMT+0100 (CET),
// failedLoginAttempts: 0,
// hash: '$2a$10$jFcGpdDKk/hqhP93VQGcce5zgoWVPGi7bQvpjupaOUKqIVBV.yI1e',
// }
});
adapter.update(user, callback)
-
user
: Object - must have_id
and_rev
properties -
callback
: Function -callback(err, user)
-user
is the updated user object
// get a user from db first
adapter.find('username', '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(match, query, callback)
-
match
: String - one of the following: 'username', 'email' or 'signupToken' -
query
: String - corresponds tomatch
, i.e.john@email.com
-
callback
: Function -callback(err, res)
-res
istrue
if everything went fine
adapter.remove('username', 'john', function(err, res) {
if (err) console.log(err);
console.log(res);
// true
});
grunt