Added option to send user metadata to the server session
This commit is contained in:
@@ -87,7 +87,8 @@ Example code below:
|
|||||||
// This should of course be replaced with your preferred auth system
|
// This should of course be replaced with your preferred auth system
|
||||||
function checkuserpass(username, password, callback) {
|
function checkuserpass(username, password, callback) {
|
||||||
if (username === 'foo' && password === 'bar') {
|
if (username === 'foo' && password === 'bar') {
|
||||||
callback(null, true);
|
// The last parameter is just user meta data that will be attached to the session as "userData" and is optional
|
||||||
|
callback(null, true, {'username': 'foo', 'userId': 123});
|
||||||
} else {
|
} else {
|
||||||
callback(null, false);
|
callback(null, false);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-1
@@ -38,7 +38,7 @@ function login(pduObj) {
|
|||||||
|
|
||||||
// If there is a checkuserpass(), use it to check system_id and password from the PDU
|
// If there is a checkuserpass(), use it to check system_id and password from the PDU
|
||||||
if (typeof this.options.checkuserpass === 'function') {
|
if (typeof this.options.checkuserpass === 'function') {
|
||||||
this.options.checkuserpass(pduObj.params.system_id, pduObj.params.password, function(err, res) {
|
this.options.checkuserpass(pduObj.params.system_id, pduObj.params.password, function(err, res, userData) {
|
||||||
if (err) {
|
if (err) {
|
||||||
that.closeSocket();
|
that.closeSocket();
|
||||||
return;
|
return;
|
||||||
@@ -54,6 +54,12 @@ function login(pduObj) {
|
|||||||
|
|
||||||
log.verbose('larvitsmpp: lib/server.js: serverSession() - login() - Login successful! Connected host: ' + that.sock.remoteAddress + ':' + that.sock.remotePort + ' system_id: "' + pduObj.params.system_id + '"');
|
log.verbose('larvitsmpp: lib/server.js: serverSession() - login() - Login successful! Connected host: ' + that.sock.remoteAddress + ':' + that.sock.remotePort + ' system_id: "' + pduObj.params.system_id + '"');
|
||||||
that.loggedIn = true;
|
that.loggedIn = true;
|
||||||
|
|
||||||
|
// Set additional user data to the session
|
||||||
|
if (userData !== undefined) {
|
||||||
|
that.userData = userData;
|
||||||
|
}
|
||||||
|
|
||||||
that.sock.resume();
|
that.sock.resume();
|
||||||
that.sendReturn(pduObj);
|
that.sendReturn(pduObj);
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@
|
|||||||
"url": "https://github.com/larvit/larvitsmpp",
|
"url": "https://github.com/larvit/larvitsmpp",
|
||||||
"type": "git"
|
"type": "git"
|
||||||
},
|
},
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"readmeFilename": "README.md",
|
"readmeFilename": "README.md",
|
||||||
"readme": "larvitsmpp",
|
"readme": "larvitsmpp",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
|||||||
Reference in New Issue
Block a user