serverpreconfigured 2.1.1 → 2.1.2

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.
@@ -6,4 +6,5 @@ export declare function getUserIdByUserEmail(email: string): Promise<number>;
6
6
  export declare function deleteUserById(id: Number): Promise<any>;
7
7
  export declare function isUserExist(email: string): Promise<boolean>;
8
8
  export declare function createUser(data: UserCreateInterface): Promise<any>;
9
+ export declare function changeUserPassword(email: string, password: string): Promise<Bluebird<T>>;
9
10
  export declare function checkUserPassword(email: string, password_string: string): Promise<boolean>;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.checkUserPassword = exports.createUser = exports.isUserExist = exports.deleteUserById = exports.getUserIdByUserEmail = exports.getUserByEmail = exports.getUserById = exports.getUserSessionData = void 0;
12
+ exports.checkUserPassword = exports.changeUserPassword = exports.createUser = exports.isUserExist = exports.deleteUserById = exports.getUserIdByUserEmail = exports.getUserByEmail = exports.getUserById = exports.getUserSessionData = void 0;
13
13
  const database_1 = require("./../database/database");
14
14
  const User_1 = require("./../database/models/User");
15
15
  const password_1 = require("./password");
@@ -93,6 +93,25 @@ function createUser(data) {
93
93
  });
94
94
  }
95
95
  exports.createUser = createUser;
96
+ function changeUserPassword(email, password) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ try {
99
+ let user = yield User_1.User.findOne({ where: { email } });
100
+ if (!user)
101
+ throw "Unknwon User";
102
+ let hash = yield (0, password_1.createArgon2Hash)(password);
103
+ if (!hash)
104
+ "Create Hash Error";
105
+ user.password_hash = hash;
106
+ yield user.save();
107
+ return user;
108
+ }
109
+ catch (e) {
110
+ throw e;
111
+ }
112
+ });
113
+ }
114
+ exports.changeUserPassword = changeUserPassword;
96
115
  function checkUserPassword(email, password_string) {
97
116
  return __awaiter(this, void 0, void 0, function* () {
98
117
  let user;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverpreconfigured",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
4
4
  "description": "\"Pre-configured server with authentication system and database integration\"",
5
5
  "main": "dist/server.js",
6
6
  "keywords": [
@@ -64,6 +64,22 @@ export async function createUser(data:UserCreateInterface):Promise<any>{
64
64
  }
65
65
  }
66
66
 
67
+ export async function changeUserPassword(email:string,password:string){
68
+ try{
69
+ let user=await User.findOne({where:{email}});
70
+ if(!user)
71
+ throw "Unknwon User";
72
+ let hash=await createArgon2Hash(password);
73
+ if(!hash)
74
+ "Create Hash Error";
75
+ user.password_hash=hash;
76
+ await user.save();
77
+ return user;
78
+ }catch(e){
79
+ throw e;
80
+ }
81
+ }
82
+
67
83
  export async function checkUserPassword(email:string,password_string:string):Promise<boolean>{
68
84
  let user;
69
85
  try{