-
Notifications
You must be signed in to change notification settings - Fork 135
/
login.js
51 lines (44 loc) · 1.08 KB
/
login.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
/**
* Login Class
*/
function Login() {
// sessionId -> user map
this.sessionMap = {
99999 : { name: 'Foo', email: 'foo@bar.com' }
};
}
/**
* Say Hello {name} to the user
*/
Login.prototype.hello = function(sessionId) {
return 'Hello ' + this.sessionMap[sessionId].name + '\n';
};
/**
* Check whether the given session id is valid (is in sessionMap) or not.
*/
Login.prototype.isLoggedIn = function(sessionId) {
return sessionId in this.sessionMap;
};
/**
* Create a new session id for the given user.
*/
Login.prototype.login = function(_name, _email) {
/*
* Generate unique session id and set it into sessionMap like foo@bar.com
*/
var sessionId = new Date().getTime();
this.sessionMap[sessionId] = { name: _name, email: _email }
console.log('new session id ' + sessionId + ' for login::' + _email);
return sessionId;
};
/**
* Logout from the server
*/
Login.prototype.logout = function(sessionId) {
console.log('logout::' + sessionId);
/*
* TODO: Remove the given sessionId from the sessionMap
*/
};
// Export the Login class
module.exports = new Login();