serverpreconfigured 2.1.3 → 2.1.5

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.
@@ -54,24 +54,24 @@ router.post('/login', (req, res) => __awaiter(void 0, void 0, void 0, function*
54
54
  password = meta_sanitizer_1.default.queryProtector(req.body.password);
55
55
  }
56
56
  catch (e) {
57
- return res.send((0, response_1.JSONResponse)(false, LoginErrorCode.InvalidParams, "Must have 'email' and 'password' params"));
57
+ return res.status(403).send((0, response_1.JSONResponse)(false, LoginErrorCode.InvalidParams, "Must have 'email' and 'password' params"));
58
58
  }
59
59
  if (password == "" || email == "")
60
- return res.send((0, response_1.JSONResponse)(false, LoginErrorCode.InvalidParams, "Must have 'email' and 'password' params"));
60
+ return res.status(403).send((0, response_1.JSONResponse)(false, LoginErrorCode.InvalidParams, "Must have 'email' and 'password' params"));
61
61
  email = email.toLocaleLowerCase();
62
62
  try {
63
63
  const checkPass = yield (0, users_1.checkUserPassword)(email, password);
64
64
  if (checkPass) {
65
65
  (0, auth_3.setUserLogged)(req, email);
66
- return res.send((0, response_1.JSONResponse)(true, LoginErrorCode.NoError, "Login Ok"));
66
+ return res.status(200).send((0, response_1.JSONResponse)(true, LoginErrorCode.NoError, "Login Ok"));
67
67
  }
68
- return res.send((0, response_1.JSONResponse)(false, LoginErrorCode.InvalidPassword, "Invalid Password"));
68
+ return res.status(403).send((0, response_1.JSONResponse)(false, LoginErrorCode.InvalidPassword, "Invalid Password"));
69
69
  }
70
70
  catch (e) {
71
71
  let more = null;
72
72
  if (DEBUG)
73
73
  more = e;
74
- return res.send((0, response_1.JSONResponse)(false, LoginErrorCode.InternalError, "I-Error", more));
74
+ return res.status(500).send((0, response_1.JSONResponse)(false, LoginErrorCode.InternalError, "I-Error", more));
75
75
  }
76
76
  }));
77
77
  router.post('/register', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
@@ -1,3 +1,4 @@
1
+ import { User } from "./../database/models/User";
1
2
  import { UserCreateInterface } from "./types";
2
3
  export declare function getUserSessionData(req: any): string;
3
4
  export declare function getUserById(id: Number): Promise<any>;
@@ -6,5 +7,5 @@ export declare function getUserIdByUserEmail(email: string): Promise<number>;
6
7
  export declare function deleteUserById(id: Number): Promise<any>;
7
8
  export declare function isUserExist(email: string): Promise<boolean>;
8
9
  export declare function createUser(data: UserCreateInterface): Promise<any>;
9
- export declare function changeUserPassword(email: string, password: string): Promise<Bluebird<T>>;
10
+ export declare function changeUserPassword(email: string, password: string): Promise<User>;
10
11
  export declare function checkUserPassword(email: string, password_string: string): Promise<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverpreconfigured",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "\"Pre-configured server with authentication system and database integration\"",
5
5
  "main": "dist/server.js",
6
6
  "keywords": [
@@ -41,23 +41,23 @@ router.post('/login',async (req,res)=>{
41
41
  email=meta_sanitizer.sanitizeEmail(req.body.email);
42
42
  password=meta_sanitizer.queryProtector(req.body.password);
43
43
  }catch(e){
44
- return res.send(JSONResponse(false,LoginErrorCode.InvalidParams,"Must have 'email' and 'password' params"))
44
+ return res.status(403).send(JSONResponse(false,LoginErrorCode.InvalidParams,"Must have 'email' and 'password' params"))
45
45
  }
46
46
  if(password==""||email=="")
47
- return res.send(JSONResponse(false,LoginErrorCode.InvalidParams,"Must have 'email' and 'password' params"));
47
+ return res.status(403).send(JSONResponse(false,LoginErrorCode.InvalidParams,"Must have 'email' and 'password' params"));
48
48
  email=email.toLocaleLowerCase();
49
49
  try{
50
50
  const checkPass=await checkUserPassword(email,password);
51
51
  if(checkPass){
52
52
  setUserLogged(req,email);
53
- return res.send(JSONResponse(true,LoginErrorCode.NoError,"Login Ok"));
53
+ return res.status(200).send(JSONResponse(true,LoginErrorCode.NoError,"Login Ok"));
54
54
  }
55
- return res.send(JSONResponse(false,LoginErrorCode.InvalidPassword,"Invalid Password"));
55
+ return res.status(403).send(JSONResponse(false,LoginErrorCode.InvalidPassword,"Invalid Password"));
56
56
  }catch(e){
57
57
  let more=null;
58
58
  if(DEBUG)
59
59
  more=e;
60
- return res.send(JSONResponse(false,LoginErrorCode.InternalError,"I-Error",more));
60
+ return res.status(500).send(JSONResponse(false,LoginErrorCode.InternalError,"I-Error",more));
61
61
  }
62
62
 
63
63
  });
@@ -64,7 +64,7 @@ export async function createUser(data:UserCreateInterface):Promise<any>{
64
64
  }
65
65
  }
66
66
 
67
- export async function changeUserPassword(email:string,password:string){
67
+ export async function changeUserPassword(email:string,password:string):Promise<User>{
68
68
  try{
69
69
  let user=await User.findOne({where:{email}});
70
70
  if(!user)