-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Lockit MongoDB adapter | ||
|
||
[![Build Status](https://travis-ci.org/zeMirco/lockit-mongodb-adapter.png)](https://travis-ci.org/zeMirco/lockit-mongodb-adapter) [![NPM version](https://badge.fury.io/js/lockit-mongodb-adapter.png)](http://badge.fury.io/js/lockit-mongodb-adapter) | ||
[![Build Status](https://travis-ci.org/zeMirco/lockit-mongodb-adapter.svg?branch=master)](https://travis-ci.org/zeMirco/lockit-mongodb-adapter) [![NPM version](https://badge.fury.io/js/lockit-mongodb-adapter.svg)](http://badge.fury.io/js/lockit-mongodb-adapter) | ||
|
||
MongoDB adapter for [Lockit](https://github.com/zeMirco/lockit). | ||
|
||
|
@@ -34,26 +34,29 @@ exports.dbCollection = 'users'; | |
|
||
The `user` object has the following properties | ||
|
||
- `name`: username chosen during sign up | ||
- `email`: email that was provided at the beginning | ||
- `hash`: hashed password using [bcrypt](https://github.com/ncb000gt/node.bcrypt.js/) | ||
- `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 of `signupTimestamp` | ||
- `username`: username chosen during sign up | ||
- `failedLoginAttempts`: save failed login attempts during login process, default is `0` | ||
- `salt`: salt generated by `crypto.randomBytes()` | ||
- `derived_key`: password hash generated by pbkdf2 | ||
- `_id`: document id | ||
|
||
```js | ||
adapter.save('john', '[email protected]', 'secret', function(err, user) { | ||
if (err) console.log(err); | ||
console.log(user); | ||
// { | ||
// username: 'john', | ||
// name: 'john', | ||
// email: '[email protected]', | ||
// 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', | ||
// salt: '48cf9da376703199c30ba5c274580c98', | ||
// derived_key: '502967e5a6e55091f4c2c80e7989623f051070fd', | ||
// _id: 52d6ce9b651b4d825351641f | ||
// } | ||
}); | ||
|
@@ -63,23 +66,24 @@ adapter.save('john', '[email protected]', 'secret', function(err, user) { | |
|
||
`adapter.find(match, query, callback)` | ||
|
||
- `match`: String - one of the following: 'username', 'email' or 'signupToken' | ||
- `match`: String - one of the following: 'name', 'email' or 'signupToken' | ||
- `query`: String - corresponds to `match`, i.e. '[email protected]' | ||
- `callback`: Function - `callback(err, user)` | ||
|
||
```js | ||
adapter.find('username', 'john', function(err, user) { | ||
adapter.find('name', 'john', function(err, user) { | ||
if (err) console.log(err); | ||
console.log(user); | ||
// { | ||
// username: 'john', | ||
// email: '[email protected]', | ||
// 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', | ||
// _id: 52d6cf2d0ed24a865323739d | ||
// name: 'john', | ||
// email: '[email protected]', | ||
// signupToken: '3a7f0f54-32f0-44f7-97c6-f1470b94c170', | ||
// signupTimestamp: Fri Apr 11 2014 21:31:54 GMT+0200 (CEST), | ||
// signupTokenExpires: Sat Apr 12 2014 21:31:54 GMT+0200 (CEST), | ||
// failedLoginAttempts: 0, | ||
// salt: '753981e8d8e30e8047cf5685d1f0a0d4', | ||
// derived_key: '18ce03eddab6729aeaaf76729c90cb31f16a863c', | ||
// _id: 5348432a98a8a6a4fef1f595 | ||
// } | ||
}); | ||
``` | ||
|
@@ -93,7 +97,7 @@ adapter.find('username', 'john', function(err, user) { | |
|
||
```js | ||
// get a user from db first | ||
adapter.find('username', 'john', function(err, user) { | ||
adapter.find('name', 'john', function(err, user) { | ||
if (err) console.log(err); | ||
|
||
// add some new properties to our existing user | ||
|
@@ -110,9 +114,9 @@ adapter.find('username', 'john', function(err, user) { | |
|
||
### 4. Remove user | ||
|
||
`adapter.remove(username, callback)` | ||
`adapter.remove(name, callback)` | ||
|
||
- `username`: String | ||
- `name`: String | ||
- `callback`: Function - `callback(err, res)` - `res` is `true` if everything went fine | ||
|
||
```js | ||
|
@@ -129,10 +133,4 @@ adapter.remove('john', function(err, res) { | |
|
||
## License | ||
|
||
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. | ||
MIT |