-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.js
More file actions
35 lines (28 loc) · 816 Bytes
/
test.js
File metadata and controls
35 lines (28 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var modella = require('modella');
var memory = require('modella-memory');
var auth = require('./index.js');
var assert = require('assert');
// Create model
var User = modella('user')
.attr('id')
.attr('email')
.attr('pass');
// Use middleware
User.use(memory());
User.use(auth({password: 'pass'}));
// creating
User()
.email('a@b.com')
.pass('secretz')
.save(function (err, res) {
res.pass(); // salted password
res.salt(); // hash
User.authenticate(res, '1234', function (err, user) {
if (err) assert.fail(err, false, 'something went wrong');
assert.equal(user, false); // not authorized
});
User.authenticate(res, 'secretz', function (err, user) {
if (err) assert.fail(err, false, 'something went wrong');
assert.ok(user); // authorized
});
});