@movalib/movalib-commons 1.59.37 → 1.59.38

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.
@@ -55,6 +55,7 @@ var react_1 = require("react");
55
55
  var lab_1 = require("@mui/lab");
56
56
  var logo_large_border_png_1 = __importDefault(require("./assets/images/logo/logo_large_border.png"));
57
57
  var logo_pro_large_border_png_1 = __importDefault(require("./assets/images/logo/logo_pro_large_border.png"));
58
+ var logo_admin_large_png_1 = __importDefault(require("./assets/images/logo/logo_admin_large.png"));
58
59
  var logo_large_dm_png_1 = __importDefault(require("./assets/images/logo/logo_large_dm.png"));
59
60
  var logo_pro_large_dm_png_1 = __importDefault(require("./assets/images/logo/logo_pro_large_dm.png"));
60
61
  var leaf_green_large_png_1 = __importDefault(require("./assets/images/leaf_green_large.png"));
@@ -119,7 +120,7 @@ var MovaLogin = function (_a) {
119
120
  var validateForm = function () {
120
121
  var newForm = __assign({}, form);
121
122
  // Validator pour les champs obligatoires
122
- if (movaAppType === Enums_1.MovaAppType.GARAGE) {
123
+ if (movaAppType === Enums_1.MovaAppType.GARAGE || movaAppType === Enums_1.MovaAppType.ADMIN) {
123
124
  newForm.email = (0, Tools_1.validateField)(form.email, function (value) { return !!value; }, 'Champ obligatoire');
124
125
  // Validator pour l'email
125
126
  newForm.email = (0, Tools_1.validateField)(form.email, Validator_1.validateEmail, 'Adresse email invalide');
@@ -131,7 +132,7 @@ var MovaLogin = function (_a) {
131
132
  // Validator pour le mot de passe
132
133
  newForm.password = (0, Tools_1.validateField)(form.password, function (value) { return value.length >= 10 && /[a-z]/.test(value) && /[A-Z]/.test(value); }, 'Mot de passe invalide');
133
134
  setForm(newForm);
134
- return newForm.password.isValid && (movaAppType === Enums_1.MovaAppType.GARAGE ? newForm.email.isValid : true)
135
+ return newForm.password.isValid && ((movaAppType === Enums_1.MovaAppType.GARAGE || movaAppType === Enums_1.MovaAppType.ADMIN) ? newForm.email.isValid : true)
135
136
  && (movaAppType === Enums_1.MovaAppType.INDIVIDUAL ? newForm.phoneNumberEmail.isValid : true);
136
137
  };
137
138
  var getMovaLogo = function () {
@@ -143,7 +144,7 @@ var MovaLogin = function (_a) {
143
144
  else {
144
145
  return movaAppType === Enums_1.MovaAppType.GARAGE ? logo_pro_large_border_png_1.default :
145
146
  movaAppType === Enums_1.MovaAppType.INDIVIDUAL ? logo_large_border_png_1.default :
146
- movaAppType === Enums_1.MovaAppType.ADMIN ? logo_large_border_png_1.default : logo_large_border_png_1.default;
147
+ movaAppType === Enums_1.MovaAppType.ADMIN ? logo_admin_large_png_1.default : logo_large_border_png_1.default;
147
148
  }
148
149
  };
149
150
  var handleOnClickSignUp = function () {
@@ -161,7 +162,7 @@ var MovaLogin = function (_a) {
161
162
  setOpenForgotPassword(false);
162
163
  // On appel de callback de soumission de la demande de réinitialisation du mot de passe
163
164
  if (onSubmitForgotPassword) {
164
- onSubmitForgotPassword(movaAppType === Enums_1.MovaAppType.GARAGE ? form.email.value : form.phoneNumberEmail.value);
165
+ onSubmitForgotPassword((movaAppType === Enums_1.MovaAppType.GARAGE || movaAppType === Enums_1.MovaAppType.ADMIN) ? form.email.value : form.phoneNumberEmail.value);
165
166
  }
166
167
  };
167
168
  var handleClickShowPassword = function () {
@@ -233,7 +234,7 @@ var MovaLogin = function (_a) {
233
234
  '& .MuiOutlinedInput-notchedOutline': {
234
235
  borderColor: darkMode ? 'white' : 'default', // Couleur de la bordure
235
236
  }
236
- } }), movaAppType === Enums_1.MovaAppType.GARAGE &&
237
+ } }), (movaAppType === Enums_1.MovaAppType.GARAGE || movaAppType === Enums_1.MovaAppType.ADMIN) &&
237
238
  (0, jsx_runtime_1.jsx)(material_1.TextField, { margin: "normal", required: true, fullWidth: true, id: "email", label: "Adresse email", name: "email", autoComplete: "email", autoFocus: true, onChange: function (e) { return handleInputChange(e); }, value: form.email.value, error: !form.email.isValid, helperText: form.email.error, sx: {
238
239
  '& .MuiOutlinedInput-notchedOutline': {
239
240
  borderColor: darkMode ? 'white' : 'default', // Couleur de la bordure
@@ -66,6 +66,11 @@ var request = function (options) {
66
66
  headers.append('Authorization', 'Bearer ' + (0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_PRO_TOKEN));
67
67
  }
68
68
  break;
69
+ case Enums_1.MovaAppType.ADMIN:
70
+ if ((0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_ADMIN_TOKEN)) {
71
+ headers.append('Authorization', 'Bearer ' + (0, CookieUtils_1.readCookie)(CookieUtils_1.COOKIE_ADMIN_TOKEN));
72
+ }
73
+ break;
69
74
  }
70
75
  // On intègre les headers aux options
71
76
  var defaults = { headers: headers };
@@ -1,5 +1,6 @@
1
1
  export declare const COOKIE_PRO_TOKEN: string;
2
2
  export declare const COOKIE_INDIVIDUAL_TOKEN: string;
3
+ export declare const COOKIE_ADMIN_TOKEN: string;
3
4
  export declare const COOKIE_DEFAULT_EXPIRES: number;
4
5
  export declare const createCookie: (name: string, value: string) => void;
5
6
  export declare const deleteCookie: (name: string) => void;
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.readCookie = exports.deleteCookie = exports.createCookie = exports.COOKIE_DEFAULT_EXPIRES = exports.COOKIE_INDIVIDUAL_TOKEN = exports.COOKIE_PRO_TOKEN = void 0;
6
+ exports.readCookie = exports.deleteCookie = exports.createCookie = exports.COOKIE_DEFAULT_EXPIRES = exports.COOKIE_ADMIN_TOKEN = exports.COOKIE_INDIVIDUAL_TOKEN = exports.COOKIE_PRO_TOKEN = void 0;
7
7
  var js_cookie_1 = __importDefault(require("js-cookie"));
8
8
  exports.COOKIE_PRO_TOKEN = 'movalibProToken';
9
9
  exports.COOKIE_INDIVIDUAL_TOKEN = 'movalibIndividualToken';
10
+ exports.COOKIE_ADMIN_TOKEN = 'movalibAdminToken';
10
11
  exports.COOKIE_DEFAULT_EXPIRES = 7;
11
12
  var createCookie = function (name, value) {
12
13
  console.log('from lib', name, value);
@@ -6,5 +6,5 @@ export default class AuthenticationService {
6
6
  static login(appType: MovaAppType, phoneEmail: string, password: string): Promise<APIResponse<User>>;
7
7
  static ValidateSecurityCode(req: {
8
8
  securityCode: string;
9
- }): Promise<APIResponse<User>>;
9
+ }, appType?: MovaAppType): Promise<APIResponse<User>>;
10
10
  }
@@ -86,6 +86,14 @@ var AuthenticationService = /** @class */ (function () {
86
86
  password: password
87
87
  };
88
88
  break;
89
+ case Enums_1.MovaAppType.ADMIN:
90
+ url = "".concat(ApiHelper_1.API_BASE_URL, "/garage/login");
91
+ tokenCookie = CookieUtils_1.COOKIE_ADMIN_TOKEN;
92
+ req = {
93
+ email: phoneEmail,
94
+ password: password
95
+ };
96
+ break;
89
97
  }
90
98
  return [4 /*yield*/, (0, ApiHelper_1.request)({
91
99
  url: url,
@@ -97,7 +105,7 @@ var AuthenticationService = /** @class */ (function () {
97
105
  tokenResponse = _a.sent();
98
106
  if (!tokenResponse.success) return [3 /*break*/, 3];
99
107
  // CSM CASE
100
- if (tokenResponse.data.accessToken === null && tokenResponse.data.role.includes('ROLE_CSM')) {
108
+ if (tokenResponse.data.accessToken === null && (tokenResponse.data.role.includes('ROLE_CSM') || tokenResponse.data.role.includes('ROLE_SUPER_ADMIN'))) {
101
109
  return [2 /*return*/, { success: true, data: tokenResponse.data }];
102
110
  }
103
111
  Logger_1.default.info(tokenResponse);
@@ -123,13 +131,13 @@ var AuthenticationService = /** @class */ (function () {
123
131
  });
124
132
  });
125
133
  };
126
- AuthenticationService.ValidateSecurityCode = function (req) {
134
+ AuthenticationService.ValidateSecurityCode = function (req, appType) {
127
135
  return __awaiter(this, void 0, void 0, function () {
128
136
  var tokenResponse, tokenCookie, userResponse, errorMsg, error_2, errorMessage;
129
137
  return __generator(this, function (_a) {
130
138
  switch (_a.label) {
131
139
  case 0:
132
- _a.trys.push([0, 5, , 6]);
140
+ _a.trys.push([0, 8, , 9]);
133
141
  return [4 /*yield*/, (0, ApiHelper_1.request)({
134
142
  url: "".concat(ApiHelper_1.API_BASE_URL, "/check-security-code"),
135
143
  method: Enums_1.APIMethod.POST,
@@ -138,26 +146,47 @@ var AuthenticationService = /** @class */ (function () {
138
146
  case 1:
139
147
  tokenResponse = _a.sent();
140
148
  tokenCookie = CookieUtils_1.COOKIE_PRO_TOKEN;
141
- if (!tokenResponse.success) return [3 /*break*/, 3];
149
+ if (appType) {
150
+ switch (appType) {
151
+ case Enums_1.MovaAppType.GARAGE:
152
+ tokenCookie = CookieUtils_1.COOKIE_PRO_TOKEN;
153
+ break;
154
+ case Enums_1.MovaAppType.INDIVIDUAL:
155
+ tokenCookie = CookieUtils_1.COOKIE_INDIVIDUAL_TOKEN;
156
+ break;
157
+ case Enums_1.MovaAppType.ADMIN:
158
+ tokenCookie = CookieUtils_1.COOKIE_ADMIN_TOKEN;
159
+ break;
160
+ }
161
+ }
162
+ if (!tokenResponse.success) return [3 /*break*/, 6];
142
163
  Logger_1.default.info(tokenResponse);
143
164
  (0, CookieUtils_1.createCookie)(tokenCookie, tokenResponse.data.accessToken);
144
- return [4 /*yield*/, UserService_1.default.getCurrentUser(Enums_1.MovaAppType.GARAGE)];
165
+ userResponse = void 0;
166
+ if (!appType) return [3 /*break*/, 3];
167
+ return [4 /*yield*/, UserService_1.default.getCurrentUser(appType)];
145
168
  case 2:
146
169
  userResponse = _a.sent();
170
+ return [3 /*break*/, 5];
171
+ case 3: return [4 /*yield*/, UserService_1.default.getCurrentUser(Enums_1.MovaAppType.GARAGE)];
172
+ case 4:
173
+ userResponse = _a.sent();
174
+ _a.label = 5;
175
+ case 5:
147
176
  if (!userResponse || !userResponse.success) {
148
177
  errorMsg = 'Erreur au chargement de votre profil';
149
178
  Logger_1.default.error(errorMsg);
150
179
  return [2 /*return*/, { success: false, error: errorMsg }];
151
180
  }
152
181
  return [2 /*return*/, { success: true, data: userResponse.data }];
153
- case 3: return [2 /*return*/, tokenResponse];
154
- case 4: return [3 /*break*/, 6];
155
- case 5:
182
+ case 6: return [2 /*return*/, tokenResponse];
183
+ case 7: return [3 /*break*/, 9];
184
+ case 8:
156
185
  error_2 = _a.sent();
157
186
  Logger_1.default.error('Error occurred during login:', error_2);
158
187
  errorMessage = error_2 instanceof Error ? error_2.message : 'Erreur inconnue';
159
188
  return [2 /*return*/, { success: false, error: errorMessage }];
160
- case 6: return [2 /*return*/];
189
+ case 9: return [2 /*return*/];
161
190
  }
162
191
  });
163
192
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@movalib/movalib-commons",
3
- "version": "1.59.37",
3
+ "version": "1.59.38",
4
4
  "description": "Bibliothèque d'objets communs à l'ensemble des projets React de Movalib",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/MovaLogin.tsx CHANGED
@@ -2,6 +2,7 @@ import { CSSProperties, ChangeEvent, FormEvent, FunctionComponent, MouseEvent, R
2
2
  import { LoadingButton } from '@mui/lab';
3
3
  import LogoLarge from './assets/images/logo/logo_large_border.png';
4
4
  import LogoProLarge from './assets/images/logo/logo_pro_large_border.png';
5
+ import LogoAdminLarge from './assets/images/logo/logo_admin_large.png';
5
6
  import LogoLargeDarkMode from './assets/images/logo/logo_large_dm.png';
6
7
  import LogoProLargeDarkMode from './assets/images/logo/logo_pro_large_dm.png';
7
8
  import GreenLeafImage from "./assets/images/leaf_green_large.png";
@@ -93,7 +94,7 @@ const MovaLogin: FunctionComponent<MovaLoginProps> = ({ loading, movaAppType, on
93
94
  let newForm: MovaLoginForm = { ...form };
94
95
 
95
96
  // Validator pour les champs obligatoires
96
- if(movaAppType === MovaAppType.GARAGE){
97
+ if(movaAppType === MovaAppType.GARAGE || movaAppType === MovaAppType.ADMIN){
97
98
  newForm.email = validateField(form.email, value => !!value, 'Champ obligatoire');
98
99
  // Validator pour l'email
99
100
  newForm.email = validateField(form.email, validateEmail, 'Adresse email invalide');
@@ -112,7 +113,7 @@ const MovaLogin: FunctionComponent<MovaLoginProps> = ({ loading, movaAppType, on
112
113
 
113
114
  setForm(newForm);
114
115
 
115
- return newForm.password.isValid && (movaAppType === MovaAppType.GARAGE ? newForm.email.isValid : true)
116
+ return newForm.password.isValid && ((movaAppType === MovaAppType.GARAGE || movaAppType === MovaAppType.ADMIN) ? newForm.email.isValid : true)
116
117
  && (movaAppType === MovaAppType.INDIVIDUAL ? newForm.phoneNumberEmail.isValid : true) ;
117
118
  }
118
119
 
@@ -125,7 +126,7 @@ const MovaLogin: FunctionComponent<MovaLoginProps> = ({ loading, movaAppType, on
125
126
  } else {
126
127
  return movaAppType === MovaAppType.GARAGE ? LogoProLarge :
127
128
  movaAppType === MovaAppType.INDIVIDUAL ? LogoLarge :
128
- movaAppType === MovaAppType.ADMIN ? LogoLarge : LogoLarge;
129
+ movaAppType === MovaAppType.ADMIN ? LogoAdminLarge : LogoLarge;
129
130
  }
130
131
  }
131
132
 
@@ -147,7 +148,7 @@ const MovaLogin: FunctionComponent<MovaLoginProps> = ({ loading, movaAppType, on
147
148
  setOpenForgotPassword(false);
148
149
  // On appel de callback de soumission de la demande de réinitialisation du mot de passe
149
150
  if(onSubmitForgotPassword){
150
- onSubmitForgotPassword(movaAppType === MovaAppType.GARAGE ? form.email.value : form.phoneNumberEmail.value);
151
+ onSubmitForgotPassword((movaAppType === MovaAppType.GARAGE || movaAppType === MovaAppType.ADMIN) ? form.email.value : form.phoneNumberEmail.value);
151
152
  }
152
153
  }
153
154
 
@@ -253,7 +254,7 @@ const MovaLogin: FunctionComponent<MovaLoginProps> = ({ loading, movaAppType, on
253
254
  />
254
255
  }
255
256
 
256
- {movaAppType === MovaAppType.GARAGE &&
257
+ {(movaAppType === MovaAppType.GARAGE || movaAppType === MovaAppType.ADMIN) &&
257
258
  <TextField
258
259
  margin="normal"
259
260
  required
@@ -1,5 +1,5 @@
1
1
  import { APIMethod, MovaAppType } from "./Enums";
2
- import { COOKIE_PRO_TOKEN, COOKIE_INDIVIDUAL_TOKEN, readCookie } from "./CookieUtils";
2
+ import { COOKIE_PRO_TOKEN, COOKIE_INDIVIDUAL_TOKEN, COOKIE_ADMIN_TOKEN, readCookie } from "./CookieUtils";
3
3
  import Logger from "./Logger";
4
4
 
5
5
  export const API_BASE_URL = process.env.REACT_APP_API_URL || 'https://localhost:8443/api';
@@ -100,6 +100,11 @@ export const request = (options:APIRequest): Promise<APIResponse<any>> => {
100
100
  headers.append('Authorization', 'Bearer ' + readCookie(COOKIE_PRO_TOKEN))
101
101
  }
102
102
  break;
103
+ case MovaAppType.ADMIN:
104
+ if(readCookie(COOKIE_ADMIN_TOKEN)) {
105
+ headers.append('Authorization', 'Bearer ' + readCookie(COOKIE_ADMIN_TOKEN))
106
+ }
107
+ break;
103
108
  }
104
109
 
105
110
  // On intègre les headers aux options
@@ -2,6 +2,7 @@ import Cookies from "js-cookie";
2
2
 
3
3
  export const COOKIE_PRO_TOKEN: string = 'movalibProToken';
4
4
  export const COOKIE_INDIVIDUAL_TOKEN: string = 'movalibIndividualToken';
5
+ export const COOKIE_ADMIN_TOKEN: string = 'movalibAdminToken';
5
6
  export const COOKIE_DEFAULT_EXPIRES: number = 7;
6
7
 
7
8
  export const createCookie = (name:string, value:string) => {
@@ -1,5 +1,5 @@
1
1
  import { APIResponse, API_BASE_URL, request } from "../helpers/ApiHelper";
2
- import { COOKIE_PRO_TOKEN, COOKIE_INDIVIDUAL_TOKEN, createCookie } from "../helpers/CookieUtils";
2
+ import { COOKIE_PRO_TOKEN, COOKIE_INDIVIDUAL_TOKEN, COOKIE_ADMIN_TOKEN, createCookie } from "../helpers/CookieUtils";
3
3
  import { APIMethod, MovaAppType } from "../helpers/Enums";
4
4
  import Logger from "../helpers/Logger";
5
5
  import User from "../models/User";
@@ -42,6 +42,14 @@ export default class AuthenticationService {
42
42
  password: password
43
43
  }
44
44
  break;
45
+ case MovaAppType.ADMIN:
46
+ url = `${API_BASE_URL}/garage/login`;
47
+ tokenCookie = COOKIE_ADMIN_TOKEN;
48
+ req = {
49
+ email : phoneEmail,
50
+ password: password
51
+ }
52
+ break;
45
53
  }
46
54
 
47
55
  let tokenResponse = await request({
@@ -53,7 +61,7 @@ export default class AuthenticationService {
53
61
 
54
62
  if(tokenResponse.success){
55
63
  // CSM CASE
56
- if (tokenResponse.data.accessToken === null && tokenResponse.data.role.includes('ROLE_CSM')) {
64
+ if (tokenResponse.data.accessToken === null && (tokenResponse.data.role.includes('ROLE_CSM') || tokenResponse.data.role.includes('ROLE_SUPER_ADMIN'))) {
57
65
  return { success: true, data: tokenResponse.data };
58
66
  }
59
67
  Logger.info(tokenResponse);
@@ -82,7 +90,7 @@ export default class AuthenticationService {
82
90
  return { success: false, error: errorMessage };
83
91
  }
84
92
  }
85
- static async ValidateSecurityCode(req: { securityCode: string }): Promise<APIResponse<User>> {
93
+ static async ValidateSecurityCode(req: { securityCode: string}, appType?: MovaAppType ): Promise<APIResponse<User>> {
86
94
  try {
87
95
  //For now it's only for CSM
88
96
  const tokenResponse = await request({
@@ -90,8 +98,21 @@ export default class AuthenticationService {
90
98
  method: APIMethod.POST,
91
99
  body: JSON.stringify(req)
92
100
  });
93
- const tokenCookie = COOKIE_PRO_TOKEN;
94
101
 
102
+ let tokenCookie = COOKIE_PRO_TOKEN;
103
+ if(appType){
104
+ switch(appType){
105
+ case MovaAppType.GARAGE:
106
+ tokenCookie = COOKIE_PRO_TOKEN;
107
+ break;
108
+ case MovaAppType.INDIVIDUAL:
109
+ tokenCookie = COOKIE_INDIVIDUAL_TOKEN;
110
+ break;
111
+ case MovaAppType.ADMIN:
112
+ tokenCookie = COOKIE_ADMIN_TOKEN;
113
+ break;
114
+ }
115
+ }
95
116
 
96
117
  if (tokenResponse.success) {
97
118
 
@@ -100,8 +121,12 @@ export default class AuthenticationService {
100
121
  createCookie(tokenCookie, tokenResponse.data.accessToken);
101
122
 
102
123
  // Si le login est un succès, on renvoie les infos de l'utilisateur connecté
103
- let userResponse = await UserService.getCurrentUser(MovaAppType.GARAGE);
104
-
124
+ let userResponse;
125
+ if(appType){
126
+ userResponse = await UserService.getCurrentUser(appType);
127
+ }else{
128
+ userResponse = await UserService.getCurrentUser(MovaAppType.GARAGE);
129
+ }
105
130
  if (!userResponse || !userResponse.success) {
106
131
  const errorMsg = 'Erreur au chargement de votre profil';
107
132
  Logger.error(errorMsg);