Skip to content

Instantly share code, notes, and snippets.

@cubehouse
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cubehouse/5a5cbb831ef630c482e9 to your computer and use it in GitHub Desktop.
Save cubehouse/5a5cbb831ef630c482e9 to your computer and use it in GitHub Desktop.
Prosody Node.JS Auth Template
// create readline interface (standard NodeJS module)
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// listen for anything supplied on stdin
rl.on('line', function (cmd) {
// default result is 0
var result = 0;
if (cmd)
{
// split (to a max of 4 pieces)
cmd = cmd.split(":", 4);
// grab standard command parameters
var command = cmd[0];
var username = cmd[1];
var domain = cmd[2];
if (typeof(username) != "undefined" && typeof(domain) != "undefined")
{
// switch on supplied command
switch(command)
{
case "auth":
// auth
var password = cmd[3];
if (typeof(password) != "undefined" && password != "")
{
result = 1;
}
break;
case "isuser":
// does user exist in auth system?
break;
case "setpass":
// set new user password
var password = cmd[3];
if (typeof(password) != "undefined" && password != "")
{
result = 1;
}
break;
}
}
}
// return result (0 or 1) to Prosody
console.log(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment