smartsocket/dist/smartsocket.helpers.js

28 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-08-07 12:58:20 +00:00
"use strict";
2016-08-07 16:59:39 +00:00
const plugins = require("./smartsocket.plugins");
/**
* authenticate a socket
*/
exports.authenticateSocket = (socketObjectArg) => {
let done = plugins.q.defer();
socketObjectArg.socket.on("dataAuth", dataArg => {
plugins.beautylog.log("received authentication data. now hashing and comparing...");
socketObjectArg.socket.removeListener("dataAuth", () => { });
if ((true)) {
socketObjectArg.alias = dataArg.alias;
socketObjectArg.authenticated = true;
socketObjectArg.role = dataArg.role;
socketObjectArg.socket.emit("authenticated");
plugins.beautylog.ok(`socket with >>alias ${socketObjectArg.alias} >>role ${socketObjectArg.role} is authenticated!`);
done.resolve(socketObjectArg);
}
else {
socketObjectArg.socket.disconnect();
done.reject("not authenticated");
}
;
});
socketObjectArg.socket.emit("requestAuth");
return done.promise;
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzb2NrZXQuaGVscGVycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0c29ja2V0LmhlbHBlcnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLE1BQVksT0FBTyxXQUFNLHVCQUF1QixDQUFDLENBQUE7QUFRakQ7O0dBRUc7QUFDUSwwQkFBa0IsR0FBRyxDQUFDLGVBQThCO0lBQzNELElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFFLENBQUM7SUFDN0IsZUFBZSxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsVUFBVSxFQUFFLE9BQU87UUFDekMsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLENBQUMsNERBQTRELENBQUMsQ0FBQztRQUNwRixlQUFlLENBQUMsTUFBTSxDQUFDLGNBQWMsQ0FBQyxVQUFVLEVBQUUsUUFBUSxDQUF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