forked from southlondonmakerspace/control-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmembership.js
More file actions
35 lines (33 loc) · 828 Bytes
/
membership.js
File metadata and controls
35 lines (33 loc) · 828 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
35
var request = require( 'request' ),
crypto = require( 'crypto' ),
config = require( __dirname + '/config.json' );
var Membership = {
validate: function ( tag, device, callback ) {
var response = {
active: false,
valid: false
}
id = Membership.hashCard( tag );
var url = config.api_url + '/api/permission/' + device + '/' + id + '?api_key=' + config.api_key;
request( url, function( err, res, body ) {
if ( res.statusCode == 200 ) {
var data = JSON.parse( body );
callback( {
valid: true,
name: data.name
} );
} else {
callback( {
valid: false
} );
}
} )
},
hashCard: function ( id ) {
var md5 = crypto.createHash( 'md5' );
md5.update( config['secret'] );
md5.update( id.toLowerCase() );
return md5.digest( 'hex' );
}
};
module.exports = Membership;