This repository has been archived by the owner on Jan 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauthentication.js
93 lines (78 loc) · 2.21 KB
/
authentication.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const fs = require("fs");
/**
* Load renderer modules from a given directory
* @param {String} dir
*/
const requireAuthenticationModule = function()
{
try
{
if (fs.existsSync(__dirname + "/authentication") && fs.existsSync(__dirname + "/authentication/authentication-file.js"))
{
const pAuthMod = require(__dirname + "/authentication/authentication-file.js");
console.info("Authentication module is available.");
return new pAuthMod();
}
}
catch (errIgnore)
{
/** ignore any errors */
}
console.info("No authentication module necessary.");
const Authentication = require("./authenticator");
return new Authentication();
};
const pInstance = requireAuthenticationModule();
module.exports = {
showLoginPage : function(req, res, next)
{
let data = pInstance.getLoginPageData();
if (data === "")
res.status(404).send();
else
res.status(200).send(data);
},
signIn : (req, res) => pInstance.signIn(req, res),
isSignedInPlay : function(req, res, next)
{
if (pInstance.isSignedInPlay(req))
next();
else
res.status(403).send(pInstance.getLoginPageData());
},
isSignedInCards : function(req, res, next)
{
if (pInstance.isSignedInCards(req))
next();
else
res.status(403).send(pInstance.getLoginPageData());
},
isSignedInDeckbuilder : function(req, res, next)
{
if (pInstance.isSignedInDeckbuilder(req))
next();
else
res.status(403).send(pInstance.getLoginPageData());
},
isSignedInMap : function(req, res, next)
{
if (pInstance.isSignedInMap(req))
next();
else
res.status(403).send(pInstance.getLoginPageData());
},
signInFromPWA : function(req, res, next)
{
if (!pInstance.isSignedInPlay(req))
pInstance.signInFromPWA(res);
next();
},
isSignedInPWA : function(req)
{
return pInstance.isSignedInPWA(req);
},
isSignedIn: function(req)
{
return pInstance.isSignedIn(req);
}
};