2016-08-07 12:58:20 +00:00
|
|
|
import * as plugins from "./smartsocket.plugins";
|
|
|
|
|
2016-08-08 16:20:00 +00:00
|
|
|
// classes
|
|
|
|
import { Smartsocket } from "./smartsocket.classes.smartsocket";
|
2016-08-12 01:22:36 +00:00
|
|
|
import { SocketFunction, allSocketFunctions } from "./smartsocket.classes.socketfunction";
|
2016-08-16 02:48:42 +00:00
|
|
|
import { SocketConnection, ISocketConnectionAuthenticationObject } from "./smartsocket.classes.socketconnection";
|
2016-08-12 03:17:13 +00:00
|
|
|
import { SocketRequest, allSocketRequests, TSocketRequestSide } from "./smartsocket.classes.socketrequest";
|
2016-08-08 16:20:00 +00:00
|
|
|
import { SocketRole, allSocketRoles } from "./smartsocket.classes.socketrole";
|
2016-08-07 12:58:20 +00:00
|
|
|
|
2016-08-16 02:48:42 +00:00
|
|
|
// SocketConnection helpers
|
|
|
|
export let checkPasswordForRole = (dataArg: ISocketConnectionAuthenticationObject): boolean => {
|
|
|
|
let targetPasswordHash = getSocketRoleByName(dataArg.role).passwordHash;
|
|
|
|
let computedCompareHash = plugins.nodehash.sha256FromStringSync(dataArg.password);
|
|
|
|
return targetPasswordHash === computedCompareHash;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-12 01:22:36 +00:00
|
|
|
// SocketFunction helpers
|
2016-08-16 02:48:42 +00:00
|
|
|
export let getSocketFunctionByName = (functionNameArg: string): SocketFunction => {
|
2016-08-12 03:17:13 +00:00
|
|
|
return allSocketFunctions.find((socketFunctionArg) => { return socketFunctionArg.name === functionNameArg });
|
2016-08-12 01:22:36 +00:00
|
|
|
}
|
|
|
|
|
2016-08-12 03:17:13 +00:00
|
|
|
// SocketRequest helpers
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get corresponding Socketrequest instance by shortId
|
|
|
|
*/
|
2016-08-16 02:48:42 +00:00
|
|
|
export let getSocketRequestById = (shortIdArg: string, requestSide?: TSocketRequestSide): SocketRequest => {
|
|
|
|
return allSocketRequests.find((socketRequestArg) => { return socketRequestArg.shortid === shortIdArg })
|
2016-08-12 03:17:13 +00:00
|
|
|
}
|
2016-08-07 12:58:20 +00:00
|
|
|
|
2016-08-08 16:20:00 +00:00
|
|
|
// SocketRole helpers
|
2016-08-12 01:22:36 +00:00
|
|
|
|
|
|
|
/**
|
2016-08-12 03:17:13 +00:00
|
|
|
* get corresponding SocketRole instance by name
|
2016-08-12 01:22:36 +00:00
|
|
|
*/
|
|
|
|
export let getSocketRoleByName = (socketRoleNameArg: string): SocketRole => {
|
2016-08-08 16:20:00 +00:00
|
|
|
return allSocketRoles.find((socketRoleArg) => { return socketRoleArg.name === socketRoleNameArg })
|
|
|
|
};
|
2016-08-07 12:58:20 +00:00
|
|
|
|