serverpreconfigured 2.2.15 → 2.2.17
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/dist/auth/auth.d.ts +3 -0
- package/dist/auth/auth.js +22 -0
- package/dist/auth/config.d.ts +1 -0
- package/dist/auth/config.js +4 -0
- package/dist/database/database.d.ts +2 -0
- package/dist/database/database.js +10 -0
- package/dist/database/models/User.d.ts +9 -0
- package/dist/database/models/User.js +19 -0
- package/dist/database/models/WSAuth.d.ts +6 -0
- package/dist/database/models/WSAuth.js +19 -0
- package/dist/expressServer.d.ts +20 -0
- package/dist/expressServer.js +52 -0
- package/dist/logs/logs.d.ts +29 -0
- package/dist/logs/logs.js +132 -0
- package/dist/middlewares/auth.d.ts +6 -0
- package/dist/middlewares/auth.js +35 -0
- package/dist/middlewares/post.d.ts +1 -0
- package/dist/middlewares/post.js +6 -0
- package/dist/middlewares/wsauth.d.ts +1 -0
- package/dist/middlewares/wsauth.js +56 -0
- package/dist/modules/initcors.d.ts +1 -0
- package/dist/modules/initcors.js +13 -0
- package/dist/modules/postreader.d.ts +1 -0
- package/dist/modules/postreader.js +12 -0
- package/dist/modules/sessions.d.ts +1 -0
- package/dist/modules/sessions.js +20 -0
- package/dist/routes/userauth.d.ts +2 -0
- package/dist/routes/userauth.js +68 -0
- package/dist/routes/userresgister.d.ts +2 -0
- package/dist/routes/userresgister.js +42 -0
- package/dist/routes/wsauth.d.ts +1 -0
- package/dist/routes/wsauth.js +33 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.js +42 -0
- package/dist/sessions/secureget.d.ts +1 -0
- package/dist/sessions/secureget.js +7 -0
- package/dist/sessions/secureset.d.ts +2 -0
- package/dist/sessions/secureset.js +11 -0
- package/dist/settings/database/database.d.ts +11 -0
- package/dist/settings/database/database.js +15 -0
- package/dist/settings/env.d.ts +15 -0
- package/dist/settings/env.js +30 -0
- package/dist/users/password.d.ts +3 -0
- package/dist/users/password.js +41 -0
- package/dist/users/types.d.ts +6 -0
- package/dist/users/types.js +3 -0
- package/dist/users/users.d.ts +12 -0
- package/dist/users/users.js +143 -0
- package/dist/utils/debug/debug.d.ts +1 -0
- package/dist/utils/debug/debug.js +15 -0
- package/dist/utils/response.d.ts +8 -0
- package/dist/utils/response.js +27 -0
- package/dist/utils/string/random.d.ts +1 -0
- package/dist/utils/string/random.js +14 -0
- package/dist/utils/validators/email.d.ts +1 -0
- package/dist/utils/validators/email.js +18 -0
- package/dist/wsauth/types.d.ts +0 -0
- package/dist/wsauth/types.js +1 -0
- package/dist/wsauth/wsauth.d.ts +5 -0
- package/dist/wsauth/wsauth.js +111 -0
- package/package.json +1 -1
- package/src/settings/env.ts +8 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.router = void 0;
|
|
16
|
+
const express_1 = __importDefault(require("express"));
|
|
17
|
+
const response_1 = require("../utils/response");
|
|
18
|
+
const wsauth_1 = require("../wsauth/wsauth");
|
|
19
|
+
const auth_1 = require("../middlewares/auth");
|
|
20
|
+
exports.router = express_1.default.Router();
|
|
21
|
+
exports.router.post('/gettoken', auth_1.setUserDataMiddleware, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
try {
|
|
23
|
+
let userId = req.user.id;
|
|
24
|
+
let n = yield (0, wsauth_1.setWSAuthDataNewToken)(userId);
|
|
25
|
+
return res.send((0, response_1.JSONResponse)({ token: n.dataValues.token,
|
|
26
|
+
expiration: n.dataValues.expiration,
|
|
27
|
+
userId: userId
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
return (0, response_1.sendIError)(req, res, e);
|
|
32
|
+
}
|
|
33
|
+
}));
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./auth/auth";
|
|
2
|
+
export { User } from "./database/models/User";
|
|
3
|
+
export { dataBase } from "./database/database";
|
|
4
|
+
export * from "./sessions/secureset";
|
|
5
|
+
export * from "./sessions/secureget";
|
|
6
|
+
export * from "./users/users";
|
|
7
|
+
export { WebSocketAuth } from "./database/models/WSAuth";
|
|
8
|
+
export * from "./wsauth/wsauth";
|
|
9
|
+
export { randomString } from "./utils/string/random";
|
|
10
|
+
export { JSONResponse } from "./utils/response";
|
|
11
|
+
import ExpressServer from "./expressServer";
|
|
12
|
+
export { debugMessage } from "./utils/debug/debug";
|
|
13
|
+
export * from "./middlewares/auth";
|
|
14
|
+
export * from "./middlewares/wsauth";
|
|
15
|
+
export default ExpressServer;
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.debugMessage = exports.JSONResponse = exports.randomString = exports.WebSocketAuth = exports.dataBase = exports.User = void 0;
|
|
21
|
+
__exportStar(require("./auth/auth"), exports);
|
|
22
|
+
;
|
|
23
|
+
var User_1 = require("./database/models/User");
|
|
24
|
+
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return User_1.User; } });
|
|
25
|
+
var database_1 = require("./database/database");
|
|
26
|
+
Object.defineProperty(exports, "dataBase", { enumerable: true, get: function () { return database_1.dataBase; } });
|
|
27
|
+
__exportStar(require("./sessions/secureset"), exports);
|
|
28
|
+
__exportStar(require("./sessions/secureget"), exports);
|
|
29
|
+
__exportStar(require("./users/users"), exports);
|
|
30
|
+
var WSAuth_1 = require("./database/models/WSAuth");
|
|
31
|
+
Object.defineProperty(exports, "WebSocketAuth", { enumerable: true, get: function () { return WSAuth_1.WebSocketAuth; } });
|
|
32
|
+
__exportStar(require("./wsauth/wsauth"), exports);
|
|
33
|
+
var random_1 = require("./utils/string/random");
|
|
34
|
+
Object.defineProperty(exports, "randomString", { enumerable: true, get: function () { return random_1.randomString; } });
|
|
35
|
+
var response_1 = require("./utils/response");
|
|
36
|
+
Object.defineProperty(exports, "JSONResponse", { enumerable: true, get: function () { return response_1.JSONResponse; } });
|
|
37
|
+
const expressServer_1 = __importDefault(require("./expressServer"));
|
|
38
|
+
var debug_1 = require("./utils/debug/debug");
|
|
39
|
+
Object.defineProperty(exports, "debugMessage", { enumerable: true, get: function () { return debug_1.debugMessage; } });
|
|
40
|
+
__exportStar(require("./middlewares/auth"), exports);
|
|
41
|
+
__exportStar(require("./middlewares/wsauth"), exports);
|
|
42
|
+
exports.default = expressServer_1.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSessionValue(req: any, get: string): any;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteSessionValue = exports.setSessionValue = void 0;
|
|
4
|
+
function setSessionValue(req, to, value) {
|
|
5
|
+
req.session[to] = value;
|
|
6
|
+
}
|
|
7
|
+
exports.setSessionValue = setSessionValue;
|
|
8
|
+
function deleteSessionValue(req, to) {
|
|
9
|
+
setSessionValue(req, to, undefined);
|
|
10
|
+
}
|
|
11
|
+
exports.deleteSessionValue = deleteSessionValue;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const dialect: string;
|
|
2
|
+
export const host: any;
|
|
3
|
+
export const database: any;
|
|
4
|
+
export const username: any;
|
|
5
|
+
export const password: string | undefined;
|
|
6
|
+
export const port: any;
|
|
7
|
+
export namespace define {
|
|
8
|
+
const underscored: boolean;
|
|
9
|
+
const timestamps: boolean;
|
|
10
|
+
}
|
|
11
|
+
export const logging: boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const ENV = require("./../env").default;
|
|
3
|
+
module.exports = {
|
|
4
|
+
dialect: ENV.DATABASE.dialect,
|
|
5
|
+
host: ENV.DATABASE.host,
|
|
6
|
+
database: ENV.DATABASE.database,
|
|
7
|
+
username: ENV.DATABASE.username,
|
|
8
|
+
password: ENV.DATABASE.password,
|
|
9
|
+
port: ENV.DATABASE.port,
|
|
10
|
+
define: {
|
|
11
|
+
underscored: true,
|
|
12
|
+
timestamps: true,
|
|
13
|
+
},
|
|
14
|
+
logging: false,
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare const ENV: {
|
|
2
|
+
NODE_ENV: string;
|
|
3
|
+
ALLOW_CORS: boolean;
|
|
4
|
+
PORT: number;
|
|
5
|
+
DATABASE: {
|
|
6
|
+
dialect: string;
|
|
7
|
+
port: any;
|
|
8
|
+
host: any;
|
|
9
|
+
database: any;
|
|
10
|
+
username: any;
|
|
11
|
+
password: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
SESSION_SECRET: string;
|
|
14
|
+
};
|
|
15
|
+
export default ENV;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const custom_env_path = path_1.default.join(process.cwd(), "spc_envfile.json");
|
|
9
|
+
var custom_env = {};
|
|
10
|
+
try {
|
|
11
|
+
custom_env = JSON.parse(fs_1.default.readFileSync(custom_env_path).toString());
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
custom_env = {};
|
|
15
|
+
}
|
|
16
|
+
const ENV = {
|
|
17
|
+
NODE_ENV: process.env.SERVER_ENV == 'development' ? 'development' : 'production',
|
|
18
|
+
ALLOW_CORS: process.env.ALLOW_CORS == 'ALLOW' ? true : false,
|
|
19
|
+
PORT: process.env.SERVER_PORT ? parseInt(process.env.SERVER_PORT) : 3000,
|
|
20
|
+
DATABASE: {
|
|
21
|
+
dialect: process.env.DATABASE_DIALECT ? process.env.DATABASE_DIALECT : 'postgres',
|
|
22
|
+
port: (custom_env.DATABASE && custom_env.DATABASE.PORT) || process.env.DATABASE_PORT || 5432,
|
|
23
|
+
host: (custom_env.DATABASE && custom_env.DATABASE.HOST) || (process.env.DATABASE_HOST ? process.env.DATABASE_HOST : 'localhost'),
|
|
24
|
+
database: (custom_env.DATABASE && custom_env.DATABASE.DATABASE) || (process.env.DATABASE_DATABASE || 'postgres'),
|
|
25
|
+
username: (custom_env.DATABASE && custom_env.DATABASE.USERNAME) || (process.env.DATABASE_USERNAME ? process.env.DATABASE_USERNAME : 'postgres'),
|
|
26
|
+
password: (custom_env.DATABASE && custom_env.DATABASE.PASSWOR) || process.env.DATABASE_PASSWORD ? process.env.DATABASE_PASSWORD : '',
|
|
27
|
+
},
|
|
28
|
+
SESSION_SECRET: process.env.SESSION_SECRET ? process.env.SESSION_SECRET : "secret key session",
|
|
29
|
+
};
|
|
30
|
+
exports.default = ENV;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.checkArgon2Password = exports.createArgon2Hash = void 0;
|
|
16
|
+
const argon2_1 = __importDefault(require("argon2"));
|
|
17
|
+
function createArgon2Hash(password_string) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
try {
|
|
20
|
+
let hash = yield argon2_1.default.hash(password_string);
|
|
21
|
+
return hash;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
exports.createArgon2Hash = createArgon2Hash;
|
|
29
|
+
function checkArgon2Password(password_hash, password_string) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
try {
|
|
32
|
+
if (yield argon2_1.default.verify(password_hash, password_string))
|
|
33
|
+
return "Match";
|
|
34
|
+
return "Dont Match";
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
return "Dont Match";
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
exports.checkArgon2Password = checkArgon2Password;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { User } from "./../database/models/User";
|
|
2
|
+
import { UserCreateInterface } from "./types";
|
|
3
|
+
export declare function updateUserLastAction(user: User): Promise<User>;
|
|
4
|
+
export declare function getUserSessionData(req: any): string;
|
|
5
|
+
export declare function getUserById(id: Number): Promise<any>;
|
|
6
|
+
export declare function getUserByEmail(email: string): Promise<any>;
|
|
7
|
+
export declare function getUserIdByUserEmail(email: string): Promise<number>;
|
|
8
|
+
export declare function deleteUserById(id: Number): Promise<any>;
|
|
9
|
+
export declare function isUserExist(email: string): Promise<boolean>;
|
|
10
|
+
export declare function createUser(data: UserCreateInterface): Promise<any>;
|
|
11
|
+
export declare function changeUserPassword(email: string, password: string): Promise<User>;
|
|
12
|
+
export declare function checkUserPassword(email: string, password_string: string): Promise<boolean>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.checkUserPassword = exports.changeUserPassword = exports.createUser = exports.isUserExist = exports.deleteUserById = exports.getUserIdByUserEmail = exports.getUserByEmail = exports.getUserById = exports.getUserSessionData = exports.updateUserLastAction = void 0;
|
|
13
|
+
const User_1 = require("./../database/models/User");
|
|
14
|
+
const password_1 = require("./password");
|
|
15
|
+
const config_1 = require("../auth/config");
|
|
16
|
+
const secureget_1 = require("../sessions/secureget");
|
|
17
|
+
function updateUserLastAction(user) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
try {
|
|
20
|
+
user.last_action = new Date();
|
|
21
|
+
yield user.save();
|
|
22
|
+
return user;
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
exports.updateUserLastAction = updateUserLastAction;
|
|
30
|
+
function getUserSessionData(req) {
|
|
31
|
+
return (0, secureget_1.getSessionValue)(req, config_1.SESSION_LOGGED_DATA);
|
|
32
|
+
}
|
|
33
|
+
exports.getUserSessionData = getUserSessionData;
|
|
34
|
+
function getUserById(id) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
let result = yield User_1.User.findOne({ where: { id: id.toString() } });
|
|
37
|
+
return (result);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.getUserById = getUserById;
|
|
41
|
+
function getUserByEmail(email) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
let result = yield User_1.User.findOne({ where: { email: email } });
|
|
44
|
+
return (result);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.getUserByEmail = getUserByEmail;
|
|
48
|
+
function getUserIdByUserEmail(email) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
try {
|
|
51
|
+
let u = yield getUserByEmail(email);
|
|
52
|
+
if (!Boolean(u))
|
|
53
|
+
return NaN;
|
|
54
|
+
return u.dataValues.id;
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
return NaN;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.getUserIdByUserEmail = getUserIdByUserEmail;
|
|
62
|
+
function deleteUserById(id) {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
let result = yield User_1.User.destroy({ where: { id: id.toString() } });
|
|
65
|
+
return result;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
exports.deleteUserById = deleteUserById;
|
|
69
|
+
function isUserExist(email) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
try {
|
|
72
|
+
let user = yield getUserByEmail(email);
|
|
73
|
+
return Boolean(user);
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
throw (e);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
exports.isUserExist = isUserExist;
|
|
81
|
+
function createUser(data) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
let user_exist = false;
|
|
84
|
+
try {
|
|
85
|
+
user_exist = yield isUserExist(data.email);
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
throw (e);
|
|
89
|
+
}
|
|
90
|
+
if (user_exist)
|
|
91
|
+
throw "User exist";
|
|
92
|
+
let hash = yield (0, password_1.createArgon2Hash)(data.password_string);
|
|
93
|
+
if (!hash)
|
|
94
|
+
throw "Create argon2 hash error";
|
|
95
|
+
try {
|
|
96
|
+
let user_instance = yield User_1.User.create({ email: data.email,
|
|
97
|
+
first_name: data.first_name,
|
|
98
|
+
password_hash: hash });
|
|
99
|
+
return user_instance;
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
throw e;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
exports.createUser = createUser;
|
|
107
|
+
function changeUserPassword(email, password) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
try {
|
|
110
|
+
let user = yield User_1.User.findOne({ where: { email } });
|
|
111
|
+
if (!user)
|
|
112
|
+
throw "Unknwon User";
|
|
113
|
+
let hash = yield (0, password_1.createArgon2Hash)(password);
|
|
114
|
+
if (typeof (hash) !== "string")
|
|
115
|
+
throw "Create Hash Error";
|
|
116
|
+
user.password_hash = hash;
|
|
117
|
+
yield user.save();
|
|
118
|
+
return user;
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
throw e;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
exports.changeUserPassword = changeUserPassword;
|
|
126
|
+
function checkUserPassword(email, password_string) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
let user;
|
|
129
|
+
try {
|
|
130
|
+
user = yield getUserByEmail(email);
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
throw e;
|
|
134
|
+
}
|
|
135
|
+
if (!user)
|
|
136
|
+
return false;
|
|
137
|
+
let hash = user.dataValues.password_hash;
|
|
138
|
+
if ((yield (0, password_1.checkArgon2Password)(hash, password_string)) == 'Match')
|
|
139
|
+
return true;
|
|
140
|
+
return false;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
exports.checkUserPassword = checkUserPassword;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function debugMessage(isDebug: boolean, message: string, data?: any): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debugMessage = void 0;
|
|
4
|
+
function debugMessage(isDebug, message, data = {}) {
|
|
5
|
+
if (!isDebug)
|
|
6
|
+
return;
|
|
7
|
+
let error = new Error();
|
|
8
|
+
let stack = error.stack.split("\n");
|
|
9
|
+
let addData = data.data ? JSON.stringify(data.data) : "";
|
|
10
|
+
console.log("----DEBUG----" +
|
|
11
|
+
"\nCaller: " + stack[2] +
|
|
12
|
+
"\nMessage: " + message +
|
|
13
|
+
(addData ? "\naddData: " + addData : ""));
|
|
14
|
+
}
|
|
15
|
+
exports.debugMessage = debugMessage;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LogSeverity } from "../logs/logs";
|
|
2
|
+
export declare function JSONResponse(data: any, error?: any): string;
|
|
3
|
+
export interface SendIErrorOptions {
|
|
4
|
+
severity?: LogSeverity;
|
|
5
|
+
penTestSuspcion?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function sendIError(req: any, res: any, error?: any, options?: SendIErrorOptions): any;
|
|
8
|
+
export declare function WSResponse(isOK: boolean, message?: string, errorMessage?: string, data?: any): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WSResponse = exports.sendIError = exports.JSONResponse = void 0;
|
|
4
|
+
const logs_1 = require("../logs/logs");
|
|
5
|
+
function JSONResponse(data, error) {
|
|
6
|
+
return JSON.stringify({
|
|
7
|
+
data,
|
|
8
|
+
hasError: Boolean(error),
|
|
9
|
+
error,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
exports.JSONResponse = JSONResponse;
|
|
13
|
+
;
|
|
14
|
+
function sendIError(req, res, error, options) {
|
|
15
|
+
(0, logs_1.saveInternalErrorLog)(req, error, options);
|
|
16
|
+
return res.status(500).send(JSONResponse("", "I-E"));
|
|
17
|
+
}
|
|
18
|
+
exports.sendIError = sendIError;
|
|
19
|
+
function WSResponse(isOK, message = '', errorMessage = "", data = {}) {
|
|
20
|
+
return JSON.stringify({
|
|
21
|
+
is_ok: isOK,
|
|
22
|
+
message: message,
|
|
23
|
+
error_message: errorMessage,
|
|
24
|
+
data: data
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.WSResponse = WSResponse;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function randomString(length: number): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomString = void 0;
|
|
4
|
+
function randomString(length) {
|
|
5
|
+
var result = '';
|
|
6
|
+
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
7
|
+
var charactersLength = characters.length;
|
|
8
|
+
for (var i = 0; i < length; i++) {
|
|
9
|
+
result += characters.charAt(Math.floor(Math.random() *
|
|
10
|
+
charactersLength));
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
exports.randomString = randomString;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkEmail(email: string): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkEmail = void 0;
|
|
4
|
+
function checkEmail(email) {
|
|
5
|
+
const atIndex = email.indexOf("@");
|
|
6
|
+
if (atIndex < 1)
|
|
7
|
+
return false;
|
|
8
|
+
const after = email.slice(atIndex + 1);
|
|
9
|
+
if (after.length < 3)
|
|
10
|
+
return false;
|
|
11
|
+
if (after.indexOf('@') >= 0)
|
|
12
|
+
return false;
|
|
13
|
+
const periodIndex = after.indexOf('.');
|
|
14
|
+
if (periodIndex < 1 || periodIndex >= after.length - 1)
|
|
15
|
+
return false;
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
exports.checkEmail = checkEmail;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function getWSAuthDataByUserId(userId: number): Promise<any>;
|
|
2
|
+
export declare function setWSAuthDataNewToken(userId: number, expiration_hours?: number): Promise<any>;
|
|
3
|
+
export declare function checkWSAuthToken(userId: number, token: string): Promise<boolean>;
|
|
4
|
+
export declare function authenticateWS(userId: number, token: string, connection_token: string): Promise<boolean>;
|
|
5
|
+
export declare function checkConnectionAuth(userId: number, connection_token: string): Promise<boolean>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.checkConnectionAuth = exports.authenticateWS = exports.checkWSAuthToken = exports.setWSAuthDataNewToken = exports.getWSAuthDataByUserId = void 0;
|
|
13
|
+
const server_1 = require("../server");
|
|
14
|
+
const random_1 = require("./../utils/string/random");
|
|
15
|
+
function getWSAuthDataByUserId(userId) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
try {
|
|
18
|
+
let u = yield server_1.WebSocketAuth.findOne({ where: { user_id: userId.toString() } });
|
|
19
|
+
return u;
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
throw e;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.getWSAuthDataByUserId = getWSAuthDataByUserId;
|
|
27
|
+
function setWSAuthDataNewToken(userId, expiration_hours = 72) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
try {
|
|
30
|
+
let ws = yield getWSAuthDataByUserId(userId);
|
|
31
|
+
let token = (0, random_1.randomString)(50);
|
|
32
|
+
let expiration = new Date();
|
|
33
|
+
expiration.setTime(expiration.getTime() + expiration_hours * 60 * 60 * 1000);
|
|
34
|
+
if (!Boolean(ws)) {
|
|
35
|
+
return yield server_1.WebSocketAuth.create({ user_id: userId.toString(),
|
|
36
|
+
token: token,
|
|
37
|
+
expiration: expiration,
|
|
38
|
+
is_active: true,
|
|
39
|
+
auth_connection_token: "",
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
ws.token = token;
|
|
44
|
+
ws.expiration = expiration;
|
|
45
|
+
ws.is_active = true;
|
|
46
|
+
ws.auth_connection_token = "";
|
|
47
|
+
return yield ws.save();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
throw e;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.setWSAuthDataNewToken = setWSAuthDataNewToken;
|
|
56
|
+
function checkWSAuthToken(userId, token) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
try {
|
|
59
|
+
let ws = yield getWSAuthDataByUserId(userId);
|
|
60
|
+
if (!Boolean(ws))
|
|
61
|
+
return false;
|
|
62
|
+
if (!ws.dataValues.is_active)
|
|
63
|
+
return false;
|
|
64
|
+
if (ws.dataValues.token != token)
|
|
65
|
+
return false;
|
|
66
|
+
if (Date.now() > ws.dataValues.expiration.getTime())
|
|
67
|
+
return false;
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
throw e;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
exports.checkWSAuthToken = checkWSAuthToken;
|
|
76
|
+
function authenticateWS(userId, token, connection_token) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
try {
|
|
79
|
+
if (!(yield checkWSAuthToken(userId, token)))
|
|
80
|
+
return false;
|
|
81
|
+
let ws = yield getWSAuthDataByUserId(userId);
|
|
82
|
+
ws.auth_connection_token = connection_token;
|
|
83
|
+
yield ws.save();
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
throw e;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
exports.authenticateWS = authenticateWS;
|
|
92
|
+
function checkConnectionAuth(userId, connection_token) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
try {
|
|
95
|
+
let ws = yield getWSAuthDataByUserId(userId);
|
|
96
|
+
if (!Boolean(ws))
|
|
97
|
+
return false;
|
|
98
|
+
if (!ws.dataValues.is_active)
|
|
99
|
+
return false;
|
|
100
|
+
if (Date.now() > ws.dataValues.expiration.getTime())
|
|
101
|
+
return false;
|
|
102
|
+
if (ws.dataValues.auth_connection_token !== connection_token)
|
|
103
|
+
return false;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
throw e;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
exports.checkConnectionAuth = checkConnectionAuth;
|