serverpreconfigured 1.1.4 → 1.2.0

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.
@@ -9,7 +9,7 @@ const env_1 = __importDefault(require("../settings/env"));
9
9
  function initSessions(app) {
10
10
  app.set('trust proxy', 1); // trust first proxy
11
11
  app.use((0, express_session_1.default)({
12
- secret: 'keyboard cat',
12
+ secret: env_1.default.SESSION_SECRET,
13
13
  resave: false,
14
14
  saveUninitialized: true,
15
15
  cookie: { secure: env_1.default.NODE_ENV == 'development' ? false : true,
@@ -58,6 +58,7 @@ router.post('/login', (req, res) => __awaiter(void 0, void 0, void 0, function*
58
58
  }
59
59
  if (password == "" || email == "")
60
60
  return res.send((0, response_1.JSONResponse)(false, LoginErrorCode.InvalidParams, "Must have 'email' and 'password' params"));
61
+ email = email.toLocaleLowerCase();
61
62
  try {
62
63
  const checkPass = yield (0, users_1.checkUserPassword)(email, password);
63
64
  if (checkPass) {
@@ -80,6 +81,7 @@ router.post('/register', (req, res) => __awaiter(void 0, void 0, void 0, functio
80
81
  let name = meta_sanitizer_1.default.SanitizerEngine(req.body.name || '', true, false, [' ']).sanitizedData;
81
82
  if (email == "" || password == "" || name == "")
82
83
  return res.send((0, response_1.JSONResponse)(false, RegisterUserErrorCode.InvalidParams, "Invalid params"));
84
+ email = email.toLocaleLowerCase();
83
85
  yield (0, users_2.createUser)({ first_name: name, email: email, password_string: password });
84
86
  return res.send((0, response_1.JSONResponse)(true, RegisterUserErrorCode.NoError, "", "REGISTER OK"));
85
87
  }
@@ -9,5 +9,6 @@ declare const ENV: {
9
9
  username: string;
10
10
  password: string;
11
11
  };
12
+ SESSION_SECRET: string;
12
13
  };
13
14
  export default ENV;
@@ -10,6 +10,7 @@ const ENV = {
10
10
  database: process.env.DATABASE_DATABASE ? process.env.DATABASE_DATABASE : 'postgres',
11
11
  username: process.env.DATABASE_USERNAME ? process.env.DATABASE_USERNAME : 'postgres',
12
12
  password: process.env.DATABASE_PASSWORD ? process.env.DATABASE_PASSWORD : '',
13
- }
13
+ },
14
+ SESSION_SECRET: process.env.SESSION_SECRET ? process.env.SESSION_SECRET : "secret key session",
14
15
  };
15
16
  exports.default = ENV;
@@ -10,6 +10,6 @@ function debugMessage(isDebug, message, data = {}) {
10
10
  console.log("----DEBUG----" +
11
11
  "\nCaller: " + stack[2] +
12
12
  "\nMessage: " + message +
13
- addData ? "\naddData: " + addData : "");
13
+ (addData ? "\naddData: " + addData : ""));
14
14
  }
15
15
  exports.debugMessage = debugMessage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverpreconfigured",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
4
4
  "description": "\"Pre-configured server with authentication system and database integration\"",
5
5
  "main": "dist/server.js",
6
6
  "keywords": ["server","pre configured","database","authentication"],
@@ -3,7 +3,7 @@ import ENV from "../settings/env";
3
3
  export function initSessions(app:any){
4
4
  app.set('trust proxy', 1) // trust first proxy
5
5
  app.use(session({
6
- secret: 'keyboard cat',
6
+ secret: ENV.SESSION_SECRET,
7
7
  resave: false,
8
8
  saveUninitialized: true,
9
9
  cookie: { secure: ENV.NODE_ENV=='development'?false:true,
@@ -43,6 +43,7 @@ router.post('/login',async (req,res)=>{
43
43
  }
44
44
  if(password==""||email=="")
45
45
  return res.send(JSONResponse(false,LoginErrorCode.InvalidParams,"Must have 'email' and 'password' params"));
46
+ email=email.toLocaleLowerCase();
46
47
  try{
47
48
  const checkPass=await checkUserPassword(email,password);
48
49
  if(checkPass){
@@ -65,6 +66,7 @@ router.post('/register',async (req,res)=>{
65
66
  let name=meta_sanitizer.SanitizerEngine(req.body.name||'',true,false,[' ']).sanitizedData;
66
67
  if(email=="" || password=="" || name=="")
67
68
  return res.send(JSONResponse(false,RegisterUserErrorCode.InvalidParams,"Invalid params"));
69
+ email=email.toLocaleLowerCase();
68
70
  await createUser({first_name:name,email:email,password_string:password});
69
71
  return res.send(JSONResponse(true,RegisterUserErrorCode.NoError,"","REGISTER OK"));
70
72
  }catch(e){
@@ -8,6 +8,7 @@ const ENV={
8
8
  database:process.env.DATABASE_DATABASE?process.env.DATABASE_DATABASE:'postgres',
9
9
  username:process.env.DATABASE_USERNAME?process.env.DATABASE_USERNAME:'postgres',
10
10
  password:process.env.DATABASE_PASSWORD?process.env.DATABASE_PASSWORD:'',
11
- }
11
+ },
12
+ SESSION_SECRET:process.env.SESSION_SECRET?process.env.SESSION_SECRET:"secret key session",
12
13
  };
13
14
  export default ENV;
@@ -7,6 +7,6 @@ export function debugMessage(isDebug:boolean,message:string,data:any={}){
7
7
  console.log("----DEBUG----"+
8
8
  "\nCaller: "+stack[2]+
9
9
  "\nMessage: "+message+
10
- addData?"\naddData: "+addData:""
10
+ (addData?"\naddData: "+addData:"")
11
11
  );
12
12
  }