Lockit SQL adapter
SQL adapter for Lockit.
Installation
npm install lockit-sql-adapter
var adapter = ;
The adapter is built on top of sequelize. The following databases are supported:
- MySQL
- MariaDB (not yet tested but should work)
- SQLite
- PostgreSQL
You have to install the connector for your database of choice manually.
npm install pg # for postgres
npm install mysql # for mysql
npm install sqlite3 # for sqlite
npm install mariasql # for mariasql
Configuration
The following settings are required.
// for postgresexportsdb = url: 'postgres://127.0.0.1:5432/' name: 'users' collection: 'my_user_table' // table name; // for mysql// exports.db = {// url: 'mysql://127.0.0.1:3306/',// name: 'users',// collection: 'my_user_table' // table name// }; // for sqlite// exports.db = {// url: 'sqlite://',// name: ':memory:',// collection: 'my_user_table' // table name// };
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)
whereuser
is the new user now in our database.
The user
object has the following properties
_id
: unique idname
: username chosen during sign upemail
: email that was provided at the beginningsalt
: salt generated bycrypto.randomBytes()
derived_key
: password hash generated by pbkdf2signupTimestamp
: Date object to remember when the user signed upsignupToken
: unique token sent to user's email for email verificationsignupTokenExpires
: Date object usually 24h ahead ofsignupTimestamp
failedLoginAttempts
: save failed login attempts during login process, default is0
adapter;
2. Find user
adapter.find(match, query, callback)
match
: String - one of the following: 'name', 'email' or 'signupToken'query
: String - corresponds tomatch
, i.e. 'john@email.com'callback
: Function -callback(err, user)
adapter;
3. Update user
adapter.update(user, callback)
user
: Object - must have_id
keycallback
: Function -callback(err, user)
-user
is the updated user object
// get a user from db firstadapter;
4. Delete user
adapter.remove(name, callback)
name
: Stringcallback
: Function -callback(err, res)
-res
istrue
if everything went fine
adapter;
Test
grunt
License
MIT