-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplicite-session.js
76 lines (76 loc) · 2.65 KB
/
simplicite-session.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module.exports = function(RED) {
function SimpliciteSession(config) {
RED.nodes.createNode(this,config);
const node = this;
this.on('input', function(msg) {
let params = msg.payload;
if (!params)
params = {};
this.server = RED.nodes.getNode(config.server);
if (this.server) {
const session = this.server.session;
let action = '';
if (config.action)
action = config.action;
if (params.action)
action = params.action;
if (action == '' || action == 'login') {
session.login(params.parameters).then(user => {
msg.payload = user;
node.send(msg);
}, e => {
msg.payload = { error: { message: e.message ? e.message : e } };
node.send(msg);
});
} else if (action == 'user' || action == 'grant') {
session.getGrant(params.parameters).then(grant => {
msg.payload = grant;
node.send(msg);
}, e => {
msg.payload = { error: { message: e.message ? e.message : e } };
node.send(msg);
});
} else if (action == 'appinfo') {
node.server.session.getAppInfo(params.parameters).then(appinfo => {
msg.payload = appinfo;
node.send(msg);
}, e => {
msg.payload = { error: { message: e.message ? e.message : e } };
node.send(msg);
});
} else if (action == 'sysinfo') {
node.server.session.getSysInfo(params.parameters).then(sysinfo => {
msg.payload = sysinfo;
node.send(msg);
}, e => {
msg.payload = { error: { message: e.message ? e.message : e } };
node.send(msg);
});
} else if (action == 'news') {
this.server.session.getNews(params.parameters).then(news => {
msg.payload = news;
node.send(msg);
}, e => {
msg.payload = { error: { message: e.message ? e.message : e } };
node.send(msg);
});
} else if (action == 'logout') {
session.logout(params.parameters).then(res => {
msg.payload = res;
node.send(msg);
}, e => {
msg.payload = { error: { message: e.message ? e.message : e } };
node.send(msg);
});
} else {
msg.payload = { error: { message: `Unknow action ${action}` } };
node.send(msg);
}
} else {
msg.payload = { error: { message: 'No configuration' } };
node.send(msg);
}
});
}
RED.nodes.registerType('simplicite-session', SimpliciteSession);
};