jcc-express-mvc 1.3.16 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +6 -2
- package/index.d.ts.map +1 -1
- package/index.js +21 -1
- package/lib/App.d.ts.map +1 -1
- package/lib/App.js +5 -2
- package/lib/Auth/AuthMiddleware.d.ts +2 -1
- package/lib/Auth/AuthMiddleware.d.ts.map +1 -1
- package/lib/Auth/AuthMiddleware.js +21 -4
- package/lib/Auth/index.d.ts +1 -1
- package/lib/Auth/index.d.ts.map +1 -1
- package/lib/Auth/index.js +28 -28
- package/lib/Error/AppErrorHandler.js +3 -3
- package/lib/Error/DisplayErrorCode.d.ts +1 -1
- package/lib/Error/DisplayErrorCode.d.ts.map +1 -1
- package/lib/Error/DisplayErrorCode.js +11 -2
- package/lib/Error/public/error.html +191 -53
- package/lib/Interface/index.d.ts +36 -0
- package/lib/Interface/index.d.ts.map +1 -1
- package/lib/Mail/index.d.ts +28 -0
- package/lib/Mail/index.d.ts.map +1 -0
- package/lib/Mail/index.js +62 -0
- package/lib/Mail/interface/Mailer.d.ts +9 -0
- package/lib/Mail/interface/Mailer.d.ts.map +1 -0
- package/lib/Mail/interface/Mailer.js +2 -0
- package/lib/Mail/interface/index.d.ts +14 -0
- package/lib/Mail/interface/index.d.ts.map +1 -0
- package/lib/Mail/interface/index.js +2 -0
- package/lib/Middlewares/index.d.ts +1 -4
- package/lib/Middlewares/index.d.ts.map +1 -1
- package/lib/Middlewares/index.js +4 -12
- package/lib/Passport/config.d.ts.map +1 -1
- package/lib/Passport/config.js +18 -19
- package/lib/Request/FormRequest.js +1 -1
- package/lib/Routes/RouteBuilder.d.ts +5 -3
- package/lib/Routes/RouteBuilder.d.ts.map +1 -1
- package/lib/Routes/RouteBuilder.js +54 -0
- package/lib/Routes/Router.d.ts +6 -3
- package/lib/Routes/Router.d.ts.map +1 -1
- package/lib/Routes/Router.js +19 -0
- package/lib/Templating-engine/engineHelper.d.ts +7 -0
- package/lib/Templating-engine/engineHelper.d.ts.map +1 -1
- package/lib/Templating-engine/engineHelper.js +81 -5
- package/lib/Templating-engine/expressions.d.ts +3 -0
- package/lib/Templating-engine/expressions.d.ts.map +1 -1
- package/lib/Templating-engine/expressions.js +4 -0
- package/lib/Templating-engine/index.d.ts +8 -3
- package/lib/Templating-engine/index.d.ts.map +1 -1
- package/lib/Templating-engine/index.js +40 -6
- package/lib/Type/index.d.ts +3 -2
- package/lib/Type/index.d.ts.map +1 -1
- package/lib/Validation/validate.d.ts.map +1 -1
- package/lib/Validation/validate.js +7 -1
- package/lib/util/index.d.ts +6 -0
- package/lib/util/index.d.ts.map +1 -1
- package/lib/util/index.js +18 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { config as appConfig } from "./lib/Config/Config";
|
|
2
2
|
import Kernel from "./lib/HttpKernel/HttpKernel";
|
|
3
3
|
import Authentication from "./lib/Auth";
|
|
4
|
-
import { bcrypt as appBcrypt, verifyHash as appVerifyHash, jwtSign as appJwtSign, jwtVerify as appjwtVerify } from "./lib/util";
|
|
4
|
+
import { bcrypt as appBcrypt, verifyHash as appVerifyHash, jwtSign as appJwtSign, jwtVerify as appjwtVerify, loadRoute as apploadRoute } from "./lib/util";
|
|
5
5
|
export declare const HttpKernel: typeof Kernel;
|
|
6
6
|
export declare const config: typeof appConfig;
|
|
7
7
|
export declare const Auth: typeof Authentication;
|
|
8
8
|
export declare const auth: (request: import("./http").Request, response: import("./http").Response, next: import("./http").Next) => any;
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const guest: (req: import("./http").Request, res: import("./http").Response, next: import("./http").Next) => any;
|
|
10
|
+
export declare const apiAuth: (request: import("./http").Request, response: import("./http").Response, next: import("./http").Next) => Promise<any>;
|
|
10
11
|
export declare const bcrypt: typeof appBcrypt;
|
|
11
12
|
export declare const jwtSign: typeof appJwtSign;
|
|
12
13
|
export declare const jwtVerify: typeof appjwtVerify;
|
|
13
14
|
export declare const verifyHash: typeof appVerifyHash;
|
|
15
|
+
export declare const loadRoute: typeof apploadRoute;
|
|
16
|
+
export * from "./lib/Mail/index";
|
|
17
|
+
export * from "./lib/Mail/interface/Mailer";
|
|
14
18
|
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../framework/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,MAAM,MAAM,6BAA6B,CAAC;AACjD,OAAO,cAAc,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../framework/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,MAAM,MAAM,6BAA6B,CAAC;AACjD,OAAO,cAAc,MAAM,YAAY,CAAC;AAKxC,OAAO,EACL,MAAM,IAAI,SAAS,EACnB,UAAU,IAAI,aAAa,EAC3B,OAAO,IAAI,UAAU,EACrB,SAAS,IAAI,YAAY,EACzB,SAAS,IAAI,YAAY,EAC1B,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,UAAU,eAAS,CAAC;AACjC,eAAO,MAAM,MAAM,EAAE,OAAO,SAAqB,CAAC;AAClD,eAAO,MAAM,IAAI,EAAE,OAAO,cAA+B,CAAC;AAC1D,eAAO,MAAM,IAAI,8GAAsB,CAAC;AACxC,eAAO,MAAM,KAAK,qGAAuB,CAAC;AAC1C,eAAO,MAAM,OAAO,uHAAyB,CAAC;AAC9C,eAAO,MAAM,MAAM,EAAE,OAAO,SAAqB,CAAC;AAClD,eAAO,MAAM,OAAO,EAAE,OAAO,UAAuB,CAAC;AACrD,eAAO,MAAM,SAAS,EAAE,OAAO,YAA2B,CAAC;AAC3D,eAAO,MAAM,UAAU,EAAE,OAAO,aAA6B,CAAC;AAC9D,eAAO,MAAM,SAAS,EAAE,OAAO,YAA2B,CAAC;AAC3D,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC"}
|
package/index.js
CHANGED
|
@@ -1,20 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
18
|
};
|
|
5
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.verifyHash = exports.jwtVerify = exports.jwtSign = exports.bcrypt = exports.apiAuth = exports.auth = exports.Auth = exports.config = exports.HttpKernel = void 0;
|
|
20
|
+
exports.loadRoute = exports.verifyHash = exports.jwtVerify = exports.jwtSign = exports.bcrypt = exports.apiAuth = exports.guest = exports.auth = exports.Auth = exports.config = exports.HttpKernel = void 0;
|
|
7
21
|
const Config_1 = require("./lib/Config/Config");
|
|
8
22
|
const HttpKernel_1 = __importDefault(require("./lib/HttpKernel/HttpKernel"));
|
|
9
23
|
const Auth_1 = __importDefault(require("./lib/Auth"));
|
|
10
24
|
const AuthMiddleware_1 = require("./lib/Auth/AuthMiddleware");
|
|
25
|
+
// import { Mail as AppMail } from "./lib/Mail";
|
|
26
|
+
// import { Mailer as } from "./lib/Mail/interface/Mailer";
|
|
11
27
|
const util_1 = require("./lib/util");
|
|
12
28
|
exports.HttpKernel = HttpKernel_1.default;
|
|
13
29
|
exports.config = Config_1.config;
|
|
14
30
|
exports.Auth = Auth_1.default;
|
|
15
31
|
exports.auth = AuthMiddleware_1.authMiddleware.auth;
|
|
32
|
+
exports.guest = AuthMiddleware_1.authMiddleware.guest;
|
|
16
33
|
exports.apiAuth = AuthMiddleware_1.authMiddleware.apiAuth;
|
|
17
34
|
exports.bcrypt = util_1.bcrypt;
|
|
18
35
|
exports.jwtSign = util_1.jwtSign;
|
|
19
36
|
exports.jwtVerify = util_1.jwtVerify;
|
|
20
37
|
exports.verifyHash = util_1.verifyHash;
|
|
38
|
+
exports.loadRoute = util_1.loadRoute;
|
|
39
|
+
__exportStar(require("./lib/Mail/index"), exports);
|
|
40
|
+
__exportStar(require("./lib/Mail/interface/Mailer"), exports);
|
package/lib/App.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../framework/lib/App.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,cAAM,GAAI,SAAQ,SAAS;IAGlB,SAAS,mBAA0B;;IAS1C,OAAO,CAAC,iBAAiB;IAQlB,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC;IAQ/B;;;OAGG;IACI,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC;IAQ/B;;;OAGG;IACI,UAAU,IAAI,GAAG;
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../framework/lib/App.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,cAAM,GAAI,SAAQ,SAAS;IAGlB,SAAS,mBAA0B;;IAS1C,OAAO,CAAC,iBAAiB;IAQlB,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC;IAQ/B;;;OAGG;IACI,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC;IAQ/B;;;OAGG;IACI,UAAU,IAAI,GAAG;CAezB;AAED,eAAO,MAAM,GAAG,KAAY,CAAC"}
|
package/lib/App.js
CHANGED
|
@@ -20,8 +20,8 @@ class App extends Server_1.HttpSever {
|
|
|
20
20
|
initiateProviders(providers) {
|
|
21
21
|
providers.forEach((Provider) => {
|
|
22
22
|
const provider = new Provider(this.container);
|
|
23
|
-
provider.boot();
|
|
24
23
|
provider.register();
|
|
24
|
+
provider.boot();
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
webRoutes() {
|
|
@@ -50,9 +50,12 @@ class App extends Server_1.HttpSever {
|
|
|
50
50
|
const server = this.server(Number(Config_1.config.get(Constants_1.PORT, "3000")));
|
|
51
51
|
const httpErrors = this.httpErrors;
|
|
52
52
|
const app = this.app;
|
|
53
|
+
const { RouteServiceProvider } = (0, util_1.getProvider)("RouteServiceProvider");
|
|
54
|
+
const routeService = new RouteServiceProvider(this.container);
|
|
53
55
|
return {
|
|
54
56
|
listen() {
|
|
55
|
-
|
|
57
|
+
routeService.register();
|
|
58
|
+
routeService.boot();
|
|
56
59
|
httpErrors(app);
|
|
57
60
|
return server;
|
|
58
61
|
},
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AppNext, AppRequest, AppResponse } from "../Interface";
|
|
2
2
|
declare class AuthMiddleware {
|
|
3
|
-
apiAuth(request: AppRequest, response: AppResponse, next: AppNext): any
|
|
3
|
+
apiAuth(request: AppRequest, response: AppResponse, next: AppNext): Promise<any>;
|
|
4
4
|
auth(request: AppRequest, response: AppResponse, next: AppNext): any;
|
|
5
|
+
guest(req: AppRequest, res: AppResponse, next: AppNext): any;
|
|
5
6
|
}
|
|
6
7
|
export declare const authMiddleware: AuthMiddleware;
|
|
7
8
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthMiddleware.d.ts","sourceRoot":"","sources":["../../../framework/lib/Auth/AuthMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthMiddleware.d.ts","sourceRoot":"","sources":["../../../framework/lib/Auth/AuthMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAIhE,cAAM,cAAc;IACL,OAAO,CAClB,OAAO,EAAE,UAAU,EACnB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,GAAG,CAAC;IAqCR,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,GAAG,GAAG;IAWpE,KAAK,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO;CAQ9D;AAED,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.authMiddleware = void 0;
|
|
4
4
|
const util_1 = require("../util");
|
|
5
|
+
const { User } = (0, util_1.getModel)("User");
|
|
5
6
|
class AuthMiddleware {
|
|
6
|
-
apiAuth(request, response, next) {
|
|
7
|
+
async apiAuth(request, response, next) {
|
|
7
8
|
let token;
|
|
8
9
|
if (request.headers.authorization &&
|
|
9
10
|
request.headers.authorization.startsWith("Bearer")) {
|
|
@@ -19,9 +20,18 @@ class AuthMiddleware {
|
|
|
19
20
|
return response.json({ message: "Not authorize" }).status(401);
|
|
20
21
|
}
|
|
21
22
|
try {
|
|
22
|
-
request.id =
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// request.id = jwtVerify(token);
|
|
24
|
+
const id = (0, util_1.jwtVerify)(token);
|
|
25
|
+
let user;
|
|
26
|
+
if (process.env.DB_CONNECTION === "mongodb") {
|
|
27
|
+
//
|
|
28
|
+
user = await User.findById(id);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
User.hidden = User.hidden.filter((value) => value !== "password", 0);
|
|
32
|
+
user = await User.where("id", id).first();
|
|
33
|
+
}
|
|
34
|
+
request.user = user;
|
|
25
35
|
next();
|
|
26
36
|
}
|
|
27
37
|
catch (err) {
|
|
@@ -39,5 +49,12 @@ class AuthMiddleware {
|
|
|
39
49
|
? next()
|
|
40
50
|
: response.redirect(url ? `/login?redirect=${url}` : "/login");
|
|
41
51
|
}
|
|
52
|
+
guest(req, res, next) {
|
|
53
|
+
res.locals.Auth = req.user || {};
|
|
54
|
+
if (req.isAuthenticated()) {
|
|
55
|
+
return res.redirectBack();
|
|
56
|
+
}
|
|
57
|
+
return next();
|
|
58
|
+
}
|
|
42
59
|
}
|
|
43
60
|
exports.authMiddleware = new AuthMiddleware();
|
package/lib/Auth/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare module "express-session" {
|
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
declare class Authentication {
|
|
9
|
-
static login(data?: {}
|
|
9
|
+
static login(data?: {}): Promise<false | Error | undefined>;
|
|
10
10
|
static isAdmin(req: AppRequest, res: AppResponse, next: AppNext): Promise<AppResponse | undefined>;
|
|
11
11
|
static verifyEmail(req: AppRequest, res: AppResponse, next: AppNext): Promise<AppResponse | undefined>;
|
|
12
12
|
static attempt(req: AppRequest, res: AppResponse, next: AppNext): any;
|
package/lib/Auth/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../framework/lib/Auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKhE,OAAO,QAAQ,iBAAiB,CAAC;IAC/B,UAAU,WAAW;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../framework/lib/Auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKhE,OAAO,QAAQ,iBAAiB,CAAC;IAC/B,UAAU,WAAW;QACnB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,OAAO,CAAC;KACtB;CACF;AAED,cAAM,cAAc;WAEL,KAAK,CAAC,IAAI,KAAK;WAcf,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO;WAgCxD,WAAW,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO;IAkBzE,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO;WAmBjD,MAAM,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO;CAQtE;AAED,eAAe,cAAc,CAAC"}
|
package/lib/Auth/index.js
CHANGED
|
@@ -3,30 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const passport_1 = __importDefault(require("passport"));
|
|
7
|
-
const util_1 = require("../util");
|
|
8
|
-
const User = (0, util_1.getModel)("User");
|
|
6
|
+
const passport_1 = __importDefault(require("passport"));
|
|
7
|
+
const util_1 = require("../util");
|
|
8
|
+
const { User } = (0, util_1.getModel)("User");
|
|
9
9
|
class Authentication {
|
|
10
10
|
// Method to authenticate user login
|
|
11
|
-
static async login(data = {}
|
|
11
|
+
static async login(data = {}) {
|
|
12
12
|
try {
|
|
13
|
-
const user = await User.findOne(data); //.select("+password");
|
|
13
|
+
const user = await User.findOne(data); //.select("+password");
|
|
14
14
|
if (!user) {
|
|
15
|
-
return false;
|
|
15
|
+
return false;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
true ? user : false; // Verify password hash and return user if successful, otherwise false
|
|
17
|
+
true ? user : false;
|
|
19
18
|
}
|
|
20
19
|
catch (error) {
|
|
21
|
-
return new Error(error.message);
|
|
20
|
+
return new Error(error.message);
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
// Middleware to check if user is an admin
|
|
25
24
|
static async isAdmin(req, res, next) {
|
|
26
25
|
try {
|
|
27
|
-
const user = await User.findById(req.id);
|
|
26
|
+
const user = await User.findById(req.id);
|
|
28
27
|
if (!user) {
|
|
29
|
-
return res.json({ message: "Not authorized" })
|
|
28
|
+
return res.status(403).json({ message: "Not authorized" });
|
|
30
29
|
}
|
|
31
30
|
// Check if user has admin privileges
|
|
32
31
|
if (!user.role ||
|
|
@@ -39,47 +38,48 @@ class Authentication {
|
|
|
39
38
|
user.isAdmin === true ||
|
|
40
39
|
user.isAdmin === "admin" ||
|
|
41
40
|
user.isAdmin === "Admin")) {
|
|
42
|
-
return res.json({ message: "Not authorized" })
|
|
41
|
+
return res.status(403).json({ message: "Not authorized" });
|
|
43
42
|
}
|
|
44
|
-
next();
|
|
43
|
+
next();
|
|
45
44
|
}
|
|
46
45
|
catch (error) {
|
|
47
|
-
next(error);
|
|
46
|
+
next(error);
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
49
|
// Middleware to verify user email
|
|
51
50
|
static async verifyEmail(req, res, next) {
|
|
52
51
|
try {
|
|
53
|
-
const user = await User.findById(req?.id);
|
|
52
|
+
const user = await User.findById(req?.id);
|
|
54
53
|
if (!user) {
|
|
55
|
-
return res.json({ message: "Not authorized" }).status(403);
|
|
54
|
+
return res.json({ message: "Not authorized" }).status(403);
|
|
56
55
|
}
|
|
57
|
-
// Check if user's email is verified
|
|
58
56
|
if (!user.verify_email && !user.verifyEmail) {
|
|
59
|
-
return res.json({ message: "Please verify your email" }).status(403);
|
|
57
|
+
return res.json({ message: "Please verify your email" }).status(403);
|
|
60
58
|
}
|
|
61
|
-
next();
|
|
59
|
+
next();
|
|
62
60
|
}
|
|
63
61
|
catch (error) {
|
|
64
|
-
next(error);
|
|
62
|
+
next(error);
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
65
|
// Method to handle authentication attempt
|
|
68
66
|
static attempt(req, res, next) {
|
|
67
|
+
const { RouteServiceProvider } = (0, util_1.getProvider)("RouteServiceProvider");
|
|
69
68
|
try {
|
|
70
69
|
let redirectBack = req.previsiousUrls[1];
|
|
71
70
|
// Retrieve the previous URL
|
|
72
|
-
const appRedirect = req.session["appRedirect"];
|
|
73
|
-
const redirectPath = appRedirect
|
|
74
|
-
|
|
71
|
+
const appRedirect = req.session["appRedirect"];
|
|
72
|
+
const redirectPath = appRedirect
|
|
73
|
+
? appRedirect
|
|
74
|
+
: RouteServiceProvider?.HOME || "";
|
|
75
75
|
return passport_1.default.authenticate("local", {
|
|
76
|
-
successRedirect: redirectPath,
|
|
77
|
-
failureRedirect: `${redirectBack ? redirectBack : "/login"}`,
|
|
78
|
-
failureFlash: true,
|
|
79
|
-
})(req, res, next);
|
|
76
|
+
successRedirect: redirectPath,
|
|
77
|
+
failureRedirect: `${redirectBack ? redirectBack : "/login"}`,
|
|
78
|
+
failureFlash: true,
|
|
79
|
+
})(req, res, next);
|
|
80
80
|
}
|
|
81
81
|
catch (error) {
|
|
82
|
-
next(error);
|
|
82
|
+
next(error);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
static logout(req, res, next) {
|
|
@@ -46,7 +46,7 @@ class AppErrorHandler {
|
|
|
46
46
|
let error = { ...err };
|
|
47
47
|
if (err.type === error_1.VALIDATION_ERROR) {
|
|
48
48
|
error.message = err.message;
|
|
49
|
-
|
|
49
|
+
console.log("object");
|
|
50
50
|
return res.status(400).redirectBack();
|
|
51
51
|
}
|
|
52
52
|
if (err.type === error_1.API_VALIDATION_ERROR) {
|
|
@@ -55,11 +55,11 @@ class AppErrorHandler {
|
|
|
55
55
|
if (err.error_action === "database") {
|
|
56
56
|
const errArray = err.stack?.split(/\n/g) || [];
|
|
57
57
|
const errorPath = this.extractErrorPath(errArray);
|
|
58
|
-
return DisplayErrorCode_1.DisplayError.show(errorPath, err.message, res);
|
|
58
|
+
return DisplayErrorCode_1.DisplayError.show(errorPath, err.message, res, req);
|
|
59
59
|
}
|
|
60
60
|
const errArray = err.stack?.split(/\n/g) || [];
|
|
61
61
|
const errorPath = this.extractErrorPath(errArray, true);
|
|
62
|
-
return DisplayErrorCode_1.DisplayError.show(errorPath, err.message, res);
|
|
62
|
+
return DisplayErrorCode_1.DisplayError.show(errorPath, err.message, res, req);
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -7,7 +7,7 @@ export declare class DisplayError extends ErrorHighLighter {
|
|
|
7
7
|
* @param res The Express response object.
|
|
8
8
|
* @returns The response after sending the error HTML.
|
|
9
9
|
*/
|
|
10
|
-
static show(errorPath: string, message: any, res: any): any;
|
|
10
|
+
static show(errorPath: string, message: any, res: any, req?: any): any;
|
|
11
11
|
/**
|
|
12
12
|
* Renders the error HTML response.
|
|
13
13
|
* @param res The Express response object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisplayErrorCode.d.ts","sourceRoot":"","sources":["../../../framework/lib/Error/DisplayErrorCode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,qBAAa,YAAa,SAAQ,gBAAgB;IAChD;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"DisplayErrorCode.d.ts","sourceRoot":"","sources":["../../../framework/lib/Error/DisplayErrorCode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErD,qBAAa,YAAa,SAAQ,gBAAgB;IAChD;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG;IAqChE;;;;;;;OAOG;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG;CAMlE"}
|
|
@@ -15,12 +15,19 @@ class DisplayError extends ErrorHightLight_1.ErrorHighLighter {
|
|
|
15
15
|
* @param res The Express response object.
|
|
16
16
|
* @returns The response after sending the error HTML.
|
|
17
17
|
*/
|
|
18
|
-
static show(errorPath, message, res) {
|
|
18
|
+
static show(errorPath, message, res, req) {
|
|
19
19
|
try {
|
|
20
20
|
const pathParts = errorPath.replace(/\(|\)/g, "").split(/\//g);
|
|
21
21
|
const lastIndex = pathParts.length - 1;
|
|
22
22
|
const [actualPath, startLine, endLine] = pathParts[lastIndex].split(/\:/);
|
|
23
23
|
pathParts[lastIndex] = actualPath;
|
|
24
|
+
//if request is an API request, return JSON response
|
|
25
|
+
if (req.url.includes("/api")) {
|
|
26
|
+
return res.status(500).json({
|
|
27
|
+
stack: pathParts.join("/").trim() + ` on line ${startLine}:${endLine}`,
|
|
28
|
+
error: ` ${message} `,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
24
31
|
const code = fs_1.default.readFileSync(pathParts.join("/"), "utf8");
|
|
25
32
|
let content = code.split(/\n/g);
|
|
26
33
|
let formattedContent = content
|
|
@@ -29,7 +36,9 @@ class DisplayError extends ErrorHightLight_1.ErrorHighLighter {
|
|
|
29
36
|
return this.renderHtml(res, formattedContent, startLine, `${message.trim()} <p> ${pathParts.join("/").trim()} ${startLine}:${endLine} </p>`);
|
|
30
37
|
}
|
|
31
38
|
catch (error) {
|
|
32
|
-
return res
|
|
39
|
+
return res
|
|
40
|
+
.status(500)
|
|
41
|
+
.json({ message: "Internal Error", error: error.message });
|
|
33
42
|
}
|
|
34
43
|
}
|
|
35
44
|
/**
|
|
@@ -14,66 +14,204 @@
|
|
|
14
14
|
<body class="">
|
|
15
15
|
<div class="code-container">
|
|
16
16
|
<div class="error-message">
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
Cannot find module 'app'
|
|
18
|
+
Require stack:
|
|
19
|
+
- /home/abdou/Documents/GAMBTECH/FRAMEWORK/jcc/node_modules/express/lib/view.js
|
|
20
|
+
- /home/abdou/Documents/GAMBTECH/FRAMEWORK/jcc/node_modules/express/lib/application.js
|
|
21
|
+
- /home/abdou/Documents/GAMBTECH/FRAMEWORK/jcc/node_modules/express/lib/express.js
|
|
22
|
+
- /home/abdou/Documents/GAMBTECH/FRAMEWORK/jcc/node_modules/express/index.js
|
|
23
|
+
- /home/abdou/Documents/GAMBTECH/FRAMEWORK/jcc/framework/lib/Server/index.ts
|
|
24
|
+
- /home/abdou/Documents/GAMBTECH/FRAMEWORK/jcc/framework/lib/App.ts
|
|
25
|
+
- /home/abdou/Documents/GAMBTECH/FRAMEWORK/jcc/framework/server.ts
|
|
26
|
+
- /home/abdou/Documents/GAMBTECH/FRAMEWORK/jcc/server.ts <p> /home/abdou/Documents/GAMBTECH/FRAMEWORK/jcc/node_modules/express/lib/view.js undefined:undefined </p>
|
|
20
27
|
</div>
|
|
21
28
|
<div class="container">
|
|
22
29
|
<pre
|
|
23
|
-
data-line="
|
|
30
|
+
data-line="undefined"
|
|
24
31
|
class="line-numbers"
|
|
25
|
-
><code class="language-javascript">1.
|
|
26
|
-
2.
|
|
27
|
-
3.
|
|
28
|
-
4.
|
|
29
|
-
5.
|
|
30
|
-
6.
|
|
31
|
-
7.
|
|
32
|
-
8.
|
|
33
|
-
9.
|
|
34
|
-
10.
|
|
35
|
-
11.
|
|
36
|
-
12.
|
|
37
|
-
13.
|
|
38
|
-
14.
|
|
32
|
+
><code class="language-javascript">1. /*!
|
|
33
|
+
2. * express
|
|
34
|
+
3. * Copyright(c) 2009-2013 TJ Holowaychuk
|
|
35
|
+
4. * Copyright(c) 2013 Roman Shtylman
|
|
36
|
+
5. * Copyright(c) 2014-2015 Douglas Christopher Wilson
|
|
37
|
+
6. * MIT Licensed
|
|
38
|
+
7. */
|
|
39
|
+
8.
|
|
40
|
+
9. 'use strict';
|
|
41
|
+
10.
|
|
42
|
+
11. /**
|
|
43
|
+
12. * Module dependencies.
|
|
44
|
+
13. * @private
|
|
45
|
+
14. */
|
|
39
46
|
15.
|
|
40
|
-
16.
|
|
41
|
-
17.
|
|
42
|
-
18.
|
|
43
|
-
19.
|
|
44
|
-
20.
|
|
45
|
-
21.
|
|
46
|
-
22.
|
|
47
|
-
23.
|
|
47
|
+
16. var debug = require('debug')('express:view');
|
|
48
|
+
17. var path = require('path');
|
|
49
|
+
18. var fs = require('fs');
|
|
50
|
+
19.
|
|
51
|
+
20. /**
|
|
52
|
+
21. * Module variables.
|
|
53
|
+
22. * @private
|
|
54
|
+
23. */
|
|
48
55
|
24.
|
|
49
|
-
25.
|
|
50
|
-
26.
|
|
51
|
-
27.
|
|
52
|
-
28.
|
|
53
|
-
29.
|
|
54
|
-
30.
|
|
55
|
-
31.
|
|
56
|
-
32.
|
|
57
|
-
33.
|
|
58
|
-
34.
|
|
59
|
-
35.
|
|
60
|
-
36.
|
|
56
|
+
25. var dirname = path.dirname;
|
|
57
|
+
26. var basename = path.basename;
|
|
58
|
+
27. var extname = path.extname;
|
|
59
|
+
28. var join = path.join;
|
|
60
|
+
29. var resolve = path.resolve;
|
|
61
|
+
30.
|
|
62
|
+
31. /**
|
|
63
|
+
32. * Module exports.
|
|
64
|
+
33. * @public
|
|
65
|
+
34. */
|
|
66
|
+
35.
|
|
67
|
+
36. module.exports = View;
|
|
61
68
|
37.
|
|
62
|
-
38.
|
|
63
|
-
39.
|
|
64
|
-
40.
|
|
65
|
-
41.
|
|
66
|
-
42.
|
|
67
|
-
43.
|
|
68
|
-
44.
|
|
69
|
-
45.
|
|
70
|
-
46.
|
|
71
|
-
47.
|
|
72
|
-
48.
|
|
73
|
-
49.
|
|
74
|
-
50.
|
|
75
|
-
51.
|
|
76
|
-
52.
|
|
69
|
+
38. /**
|
|
70
|
+
39. * Initialize a new `View` with the given `name`.
|
|
71
|
+
40. *
|
|
72
|
+
41. * Options:
|
|
73
|
+
42. *
|
|
74
|
+
43. * - `defaultEngine` the default template engine name
|
|
75
|
+
44. * - `engines` template engine require() cache
|
|
76
|
+
45. * - `root` root path for view lookup
|
|
77
|
+
46. *
|
|
78
|
+
47. * @param {string} name
|
|
79
|
+
48. * @param {object} options
|
|
80
|
+
49. * @public
|
|
81
|
+
50. */
|
|
82
|
+
51.
|
|
83
|
+
52. function View(name, options) {
|
|
84
|
+
53. var opts = options || {};
|
|
85
|
+
54.
|
|
86
|
+
55. this.defaultEngine = opts.defaultEngine;
|
|
87
|
+
56. this.ext = extname(name);
|
|
88
|
+
57. this.name = name;
|
|
89
|
+
58. this.root = opts.root;
|
|
90
|
+
59.
|
|
91
|
+
60. if (!this.ext && !this.defaultEngine) {
|
|
92
|
+
61. throw new Error('No default engine was specified and no extension was provided.');
|
|
93
|
+
62. }
|
|
94
|
+
63.
|
|
95
|
+
64. var fileName = name;
|
|
96
|
+
65.
|
|
97
|
+
66. if (!this.ext) {
|
|
98
|
+
67. // get extension from default engine name
|
|
99
|
+
68. this.ext = this.defaultEngine[0] !== '.'
|
|
100
|
+
69. ? '.' + this.defaultEngine
|
|
101
|
+
70. : this.defaultEngine;
|
|
102
|
+
71.
|
|
103
|
+
72. fileName += this.ext;
|
|
104
|
+
73. }
|
|
105
|
+
74.
|
|
106
|
+
75. if (!opts.engines[this.ext]) {
|
|
107
|
+
76. // load engine
|
|
108
|
+
77. var mod = this.ext.slice(1)
|
|
109
|
+
78. debug('require "%s"', mod)
|
|
110
|
+
79.
|
|
111
|
+
80. // default engine export
|
|
112
|
+
81. var fn = require(mod).__express
|
|
113
|
+
82.
|
|
114
|
+
83. if (typeof fn !== 'function') {
|
|
115
|
+
84. throw new Error('Module "' + mod + '" does not provide a view engine.')
|
|
116
|
+
85. }
|
|
117
|
+
86.
|
|
118
|
+
87. opts.engines[this.ext] = fn
|
|
119
|
+
88. }
|
|
120
|
+
89.
|
|
121
|
+
90. // store loaded engine
|
|
122
|
+
91. this.engine = opts.engines[this.ext];
|
|
123
|
+
92.
|
|
124
|
+
93. // lookup path
|
|
125
|
+
94. this.path = this.lookup(fileName);
|
|
126
|
+
95. }
|
|
127
|
+
96.
|
|
128
|
+
97. /**
|
|
129
|
+
98. * Lookup view by the given `name`
|
|
130
|
+
99. *
|
|
131
|
+
100. * @param {string} name
|
|
132
|
+
101. * @private
|
|
133
|
+
102. */
|
|
134
|
+
103.
|
|
135
|
+
104. View.prototype.lookup = function lookup(name) {
|
|
136
|
+
105. var path;
|
|
137
|
+
106. var roots = [].concat(this.root);
|
|
138
|
+
107.
|
|
139
|
+
108. debug('lookup "%s"', name);
|
|
140
|
+
109.
|
|
141
|
+
110. for (var i = 0; i < roots.length && !path; i++) {
|
|
142
|
+
111. var root = roots[i];
|
|
143
|
+
112.
|
|
144
|
+
113. // resolve the path
|
|
145
|
+
114. var loc = resolve(root, name);
|
|
146
|
+
115. var dir = dirname(loc);
|
|
147
|
+
116. var file = basename(loc);
|
|
148
|
+
117.
|
|
149
|
+
118. // resolve the file
|
|
150
|
+
119. path = this.resolve(dir, file);
|
|
151
|
+
120. }
|
|
152
|
+
121.
|
|
153
|
+
122. return path;
|
|
154
|
+
123. };
|
|
155
|
+
124.
|
|
156
|
+
125. /**
|
|
157
|
+
126. * Render with the given options.
|
|
158
|
+
127. *
|
|
159
|
+
128. * @param {object} options
|
|
160
|
+
129. * @param {function} callback
|
|
161
|
+
130. * @private
|
|
162
|
+
131. */
|
|
163
|
+
132.
|
|
164
|
+
133. View.prototype.render = function render(options, callback) {
|
|
165
|
+
134. debug('render "%s"', this.path);
|
|
166
|
+
135. this.engine(this.path, options, callback);
|
|
167
|
+
136. };
|
|
168
|
+
137.
|
|
169
|
+
138. /**
|
|
170
|
+
139. * Resolve the file within the given directory.
|
|
171
|
+
140. *
|
|
172
|
+
141. * @param {string} dir
|
|
173
|
+
142. * @param {string} file
|
|
174
|
+
143. * @private
|
|
175
|
+
144. */
|
|
176
|
+
145.
|
|
177
|
+
146. View.prototype.resolve = function resolve(dir, file) {
|
|
178
|
+
147. var ext = this.ext;
|
|
179
|
+
148.
|
|
180
|
+
149. // <path>.<ext>
|
|
181
|
+
150. var path = join(dir, file);
|
|
182
|
+
151. var stat = tryStat(path);
|
|
183
|
+
152.
|
|
184
|
+
153. if (stat && stat.isFile()) {
|
|
185
|
+
154. return path;
|
|
186
|
+
155. }
|
|
187
|
+
156.
|
|
188
|
+
157. // <path>/index.<ext>
|
|
189
|
+
158. path = join(dir, basename(file, ext), 'index' + ext);
|
|
190
|
+
159. stat = tryStat(path);
|
|
191
|
+
160.
|
|
192
|
+
161. if (stat && stat.isFile()) {
|
|
193
|
+
162. return path;
|
|
194
|
+
163. }
|
|
195
|
+
164. };
|
|
196
|
+
165.
|
|
197
|
+
166. /**
|
|
198
|
+
167. * Return a stat, maybe.
|
|
199
|
+
168. *
|
|
200
|
+
169. * @param {string} path
|
|
201
|
+
170. * @return {fs.Stats}
|
|
202
|
+
171. * @private
|
|
203
|
+
172. */
|
|
204
|
+
173.
|
|
205
|
+
174. function tryStat(path) {
|
|
206
|
+
175. debug('stat "%s"', path);
|
|
207
|
+
176.
|
|
208
|
+
177. try {
|
|
209
|
+
178. return fs.statSync(path);
|
|
210
|
+
179. } catch (e) {
|
|
211
|
+
180. return undefined;
|
|
212
|
+
181. }
|
|
213
|
+
182. }
|
|
214
|
+
183. </code></pre>
|
|
77
215
|
</div>
|
|
78
216
|
</div>
|
|
79
217
|
<script src="/js/app-error-prism.js"> </script>
|