emilsoftware-utilities 1.4.0-dev.4 → 1.4.0-dev.6

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.
@@ -64,6 +64,7 @@ export declare class RestUtilities {
64
64
  static sendErrorMessage(res: Response, error: any, tag?: string, status?: number): Response;
65
65
  static sendUnauthorized(res: Response): Response;
66
66
  static sendInvalidCredentials(res: Response): Response;
67
+ static sendPasswordExpired(res: Response): Response;
67
68
  /**
68
69
  * Sends a base response with a payload.
69
70
  * @param res - Express Response object.
package/dist/Utilities.js CHANGED
@@ -138,6 +138,14 @@ class RestUtilities {
138
138
  message: "Credenziali non valide"
139
139
  });
140
140
  }
141
+ static sendPasswordExpired(res) {
142
+ return res.status(403).send({
143
+ severity: "warning",
144
+ statusCode: StatusCode.Warning,
145
+ code: "PASSWORD_EXPIRED",
146
+ message: "Password scaduta. E' necessario aggiornarla"
147
+ });
148
+ }
141
149
  /**
142
150
  * Sends a base response with a payload.
143
151
  * @param res - Express Response object.
@@ -112,6 +112,10 @@ let AuthController = AuthController_1 = class AuthController {
112
112
  return Utilities_1.RestUtilities.sendBaseResponse(res, userData);
113
113
  }
114
114
  catch (error) {
115
+ if (error.message === 'PASSWORD_EXPIRED') {
116
+ this.logger.warning('Password scaduta, cambiare password ', error);
117
+ return Utilities_1.RestUtilities.sendPasswordExpired(res);
118
+ }
115
119
  this.logger.error('Errore durante il login', error);
116
120
  return Utilities_1.RestUtilities.sendInvalidCredentials(res);
117
121
  }
@@ -161,6 +165,20 @@ __decorate([
161
165
  status: 401,
162
166
  description: 'Credenziali non valide',
163
167
  }),
168
+ (0, swagger_1.ApiResponse)({
169
+ status: 403,
170
+ description: "Password scaduta, è necessatio aggiornarla. ",
171
+ schema: {
172
+ example: {
173
+ message: {
174
+ severity: 'warning',
175
+ statusCode: 2, // o il valore di StatusCode.Warning
176
+ code: 'PASSWORD_EXPIRED',
177
+ message: 'Password scaduta. È necessario aggiornarla.',
178
+ }
179
+ }
180
+ }
181
+ }),
164
182
  (0, common_1.Post)('login'),
165
183
  __param(0, (0, common_1.Body)()),
166
184
  __param(1, (0, common_1.Res)()),
@@ -64,7 +64,7 @@ let AuthService = class AuthService {
64
64
  const today = new Date();
65
65
  const targetDate = new Date(utente.dataScadenzaPassword);
66
66
  if (today >= targetDate) {
67
- throw new Error("Password scaduta!");
67
+ throw new Error("PASSWORD_EXPIRED");
68
68
  }
69
69
  // Recupera i grants
70
70
  const userGrants = yield this.permissionService.getUserRolesAndGrants(utente.codiceUtente);
@@ -43,11 +43,9 @@ let EmailService = class EmailService {
43
43
  var _a;
44
44
  try {
45
45
  const resetToken = (0, uuid_1.v4)(); // Generiamo un nuovo token unico
46
+ console.log("Generated reset token:", resetToken);
46
47
  // Aggiorna il campo keyReg nel database
47
- const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, "UPDATE UTENTI SET KEYREG = ?, STAREG = ? WHERE USRNAME = ? RETURNING CODUTE", [resetToken, StatoRegistrazione_1.StatoRegistrazione.INVIO, email]);
48
- if (result.length === 0) {
49
- throw new Error("Email non trovata.");
50
- }
48
+ const result = yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, "UPDATE UTENTI SET KEYREG = ?, STAREG = ? WHERE USRNAME = ? ", [resetToken, StatoRegistrazione_1.StatoRegistrazione.INVIO, email]);
51
49
  const returnUrlQueryParams = "?returnUrl=" + this.accessiOptions.confirmationEmailReturnUrl + "&prefix=" + ((_a = this.accessiOptions.confirmationEmailPrefix) !== null && _a !== void 0 ? _a : '');
52
50
  const { confirmationEmailUrl } = this.accessiOptions;
53
51
  let resetUrl = `${confirmationEmailUrl}/api/accessi/email/reset-password-page/${resetToken}${returnUrlQueryParams}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "1.4.0-dev.4",
3
+ "version": "1.4.0-dev.6",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",