-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.cpu.js
59 lines (57 loc) · 1.43 KB
/
auth.cpu.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
/**
CPU - auth`
Dependency: core
**/
(function() {
var modulename = "auth";
var Module = (function(modulename) {
function Module(options) {
this.name = modulename;
options = options || {};
if (!options["cpu"]) {
console.log("Can't load module \"" + this.name + "\"! You need to pass the cpu object.");
return;
}
this.cpu = options["cpu"];
this.credentials = {};
this.auth = {}
}
Module.prototype.loadCreds = function(creds) {
this.credentials = creds;
};
Module.prototype.addClient = function (id) {
if (!this.auth.hasOwnProperty(id)) {
this.auth[id] = false;
}
};
Module.prototype.login = function(id, username, passwd) {
this.addClient(id);
if (this.credentials.hasOwnProperty(username)) {
if (this.credentials[username] == passwd) {
this.auth[id] = true;
}
}
};
Module.prototype.logout = function(id) {
if (this.auth.hasOwnProperty(id)) {
this.auth[id] = false;
}
};
Module.prototype.isLogin = function(id) {
if (this.auth.hasOwnProperty(id)) {
return this.auth[id];
} else {
return false;
}
};
return Module;
})(modulename);
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = Module;
} else {
if (!window.cpumodules) {
window.cpumodules = {};
}
window.cpumodules[modulename] = Module;
}
})();