Mercurial > gemma
annotate client/src/lib/session.js @ 483:27502291e564
docs: Added comments on non trivial parts of the code
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Fri, 24 Aug 2018 10:50:58 +0200 |
parents | 4bf2173748f3 |
children |
rev | line source |
---|---|
483
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
1 /** |
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
2 * Compares whether session is current |
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
3 * based on the expiry information and the |
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
4 * current date |
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
5 * |
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
6 * @param {number} expiresFromPastSession |
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
7 */ |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
8 function sessionStillActive(expiresFromPastSession) { |
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
9 if (!expiresFromPastSession) return false; |
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
10 const now = Date.now(); |
165
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
163
diff
changeset
|
11 const stillActive = now < expiresFromPastSession; |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
12 return stillActive; |
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
diff
changeset
|
13 } |
483
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
14 /** |
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
15 * Converts a given unix time to Milliseconds |
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
16 * |
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
17 * @param {string} timestring |
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
18 */ |
165
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
163
diff
changeset
|
19 function toMillisFromString(timestring) { |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
163
diff
changeset
|
20 return timestring * 1000; |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
163
diff
changeset
|
21 } |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
163
diff
changeset
|
22 |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
163
diff
changeset
|
23 export { sessionStillActive, toMillisFromString }; |