forked from MicrosoftDX/Vorlonjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vorlon.authentication.ts
36 lines (31 loc) · 1.19 KB
/
vorlon.authentication.ts
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
import fs = require("fs");
import path = require("path");
import config = require("../config/vorlon.configprovider");
export module VORLON {
export class Authentication {
public static ActivateAuth: boolean = false;
public static UserName: string;
public static Password: string;
public static ensureAuthenticated(req, res, next) {
if (!Authentication.ActivateAuth || req.isAuthenticated()) { return next(); }
res.redirect('/login');
}
public static loadAuthConfig(): void {
fs.readFile(config.VORLON.ConfigProvider.getConfigPath(), "utf8",(err, catalogdata) => {
if (err) {
return;
}
var catalog = JSON.parse(catalogdata.replace(/^\uFEFF/, ''));
if(catalog.activateAuth){
Authentication.ActivateAuth = catalog.activateAuth;
}
if(catalog.username){
Authentication.UserName = catalog.username;
}
if(catalog.password){
Authentication.Password = catalog.password;
}
});
}
}
};