Merge branch 'staging' into preprod

This commit is contained in:
Maxime Lalo 2023-12-18 14:47:09 +01:00
commit e6d1b75d35
9 changed files with 23 additions and 23 deletions

View File

@ -57,7 +57,7 @@
"file-type-checker": "^1.0.8", "file-type-checker": "^1.0.8",
"fp-ts": "^2.16.1", "fp-ts": "^2.16.1",
"jsonwebtoken": "^9.0.0", "jsonwebtoken": "^9.0.0",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.104", "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.105",
"module-alias": "^2.2.2", "module-alias": "^2.2.2",
"monocle-ts": "^2.3.13", "monocle-ts": "^2.3.13",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",

View File

@ -56,7 +56,7 @@ export default class CustomersController extends ApiController {
/** /**
* @description Create a new customer * @description Create a new customer
*/ */
@Post("/api/v1/notary/customers", [authHandler, ruleHandler]) @Post("/api/v1/admin/customers", [authHandler, ruleHandler])
protected async post(req: Request, response: Response) { protected async post(req: Request, response: Response) {
try { try {
//init IUser resource with request body values //init IUser resource with request body values
@ -69,6 +69,8 @@ export default class CustomersController extends ApiController {
return; return;
} }
if (!customerEntity.contact?.cell_phone_number) return;
const customers = await this.customersService.get({ const customers = await this.customersService.get({
where: { where: {
contact: { email: customerEntity.contact?.email }, contact: { email: customerEntity.contact?.email },

View File

@ -68,6 +68,8 @@ export default class CustomersController extends ApiController {
return; return;
} }
if (!customerEntity.contact?.cell_phone_number) return;
const customers = await this.customersService.get({ const customers = await this.customersService.get({
where: { where: {
contact: { email: customerEntity.contact?.email }, contact: { email: customerEntity.contact?.email },

View File

@ -57,7 +57,7 @@ export default class CustomersController extends ApiController {
/** /**
* @description Create a new customer * @description Create a new customer
*/ */
@Post("/api/v1/notary/customers", [authHandler, ruleHandler]) @Post("/api/v1/super-admin/customers", [authHandler, ruleHandler])
protected async post(req: Request, response: Response) { protected async post(req: Request, response: Response) {
try { try {
//init IUser resource with request body values //init IUser resource with request body values
@ -70,6 +70,8 @@ export default class CustomersController extends ApiController {
return; return;
} }
if (!customerEntity.contact?.cell_phone_number) return;
const customers = await this.customersService.get({ const customers = await this.customersService.get({
where: { where: {
contact: { email: customerEntity.contact?.email }, contact: { email: customerEntity.contact?.email },

View File

@ -13,7 +13,7 @@ export default function authHandler(req: Request, response: Response, next: Next
return; return;
} }
const authService = Container.get(AuthService); const authService = Container.get(AuthService);
authService.verifyAccessToken(token, (err, userPayload) => { authService.verifyAccessToken(token, (err, userPayload) => {
if (err) { if (err) {
response.status(HttpCodes.UNAUTHORIZED).send("Error while verifying token"); response.status(HttpCodes.UNAUTHORIZED).send("Error while verifying token");

View File

@ -120,10 +120,7 @@ export default class IdNotService extends BaseService {
redirect_uri: this.variables.IDNOT_REDIRECT_URL, redirect_uri: this.variables.IDNOT_REDIRECT_URL,
code: code, code: code,
grant_type: "authorization_code", grant_type: "authorization_code",
}); });
console.log(this.variables.IDNOT_BASE_URL + this.variables.IDNOT_CONNEXION_URL + "?" + query);
const token = await fetch(this.variables.IDNOT_BASE_URL + this.variables.IDNOT_CONNEXION_URL + "?" + query, { method: "POST" }); const token = await fetch(this.variables.IDNOT_BASE_URL + this.variables.IDNOT_CONNEXION_URL + "?" + query, { method: "POST" });
if(token.status !== 200) console.error(await token.text()); if(token.status !== 200) console.error(await token.text());

View File

@ -27,7 +27,6 @@ export default class OvhService extends BaseService {
console.error('Error sending Ovh Sms'); console.error('Error sending Ovh Sms');
return false; return false;
} else { } else {
console.log('SMS sent successfully via Ovh');
return true; return true;
} }
}); });

View File

@ -21,7 +21,6 @@ export default class SmsFactorService extends BaseService {
{}, {},
) )
.then((response) => { .then((response) => {
console.log("SMS sent successfully via Sms Factor");
return true; return true;
}) })
.catch((error) => { .catch((error) => {

View File

@ -12,43 +12,43 @@ import SmsFactorService from "@Services/common/SmsFactorService/SmsFactorService
export class SmsNotExpiredError extends Error { export class SmsNotExpiredError extends Error {
constructor() { constructor() {
super("SMS code not expired"); super("Code déjà envoyé");
} }
} }
export class TotpCodeExpiredError extends Error { export class TotpCodeExpiredError extends Error {
constructor() { constructor() {
super("Totp code not found or expired"); super("Code non trouvé ou expiré, veuillez raffraîchir la page");
} }
} }
export class InvalidTotpCodeError extends Error { export class InvalidTotpCodeError extends Error {
constructor() { constructor() {
super("Invalid Totp code"); super("Code invalide");
} }
} }
export class NotRegisteredCustomerError extends Error { export class NotRegisteredCustomerError extends Error {
constructor() { constructor() {
super("Customer not registered"); super("Ce client n'existe pas");
} }
} }
export class InvalidPasswordError extends Error { export class InvalidPasswordError extends Error {
constructor() { constructor() {
super("Invalid password"); super("Mot de passe incorrect");
} }
} }
export class PasswordAlreadySetError extends Error { export class PasswordAlreadySetError extends Error {
constructor() { constructor() {
super("Password already set"); super("Le mot de passe a déjà été défini");
} }
} }
export class TooSoonForNewCode extends Error { export class TooSoonForNewCode extends Error {
constructor() { constructor() {
super("You need to wait at least 30 seconds before asking for a new code"); super("Vous devez attendre 30 secondes avant de pouvoir demander un nouveau code");
} }
} }
@Service() @Service()
@ -110,7 +110,7 @@ export default class CustomersService extends BaseService {
const totpCode = await this.saveTotpPin(customer, totpPin, new Date(now + 5 * 60 * 1000), reason); const totpCode = await this.saveTotpPin(customer, totpPin, new Date(now + 5 * 60 * 1000), reason);
if (!totpCode) return null; if (!totpCode) return null;
// 5: Send the SMS code to the customer // 5: Send the SMS code to the customer
if(this.variables.ENV !== 'dev') await this.sendSmsCodeToCustomer(totpPin, customer); if (this.variables.ENV !== "dev") await this.sendSmsCodeToCustomer(totpPin, customer);
return { return {
customer, customer,
totpCode: TotpCodesResource.hydrate<TotpCodesResource>({ totpCode: TotpCodesResource.hydrate<TotpCodesResource>({
@ -162,7 +162,7 @@ export default class CustomersService extends BaseService {
await this.saveTotpPin(customer, totpPin, new Date(now + 5 * 60000), TotpCodesReasons.RESET_PASSWORD); await this.saveTotpPin(customer, totpPin, new Date(now + 5 * 60000), TotpCodesReasons.RESET_PASSWORD);
// 5: Send the SMS code to the customer // 5: Send the SMS code to the customer
if(this.variables.ENV !== 'dev') await this.sendSmsCodeToCustomer(totpPin, customer); if (this.variables.ENV !== "dev") await this.sendSmsCodeToCustomer(totpPin, customer);
return customer; return customer;
} }
@ -292,7 +292,7 @@ export default class CustomersService extends BaseService {
const totpCode = await this.saveTotpPin(customer, totpPin, new Date(now + 5 * 60 * 1000), totpCodeToResend.reason!, true); const totpCode = await this.saveTotpPin(customer, totpPin, new Date(now + 5 * 60 * 1000), totpCodeToResend.reason!, true);
// 7: Send the SMS code to the customer // 7: Send the SMS code to the customer
if(this.variables.ENV !== 'dev') await this.sendSmsCodeToCustomer(totpPin, customer); if (this.variables.ENV !== "dev") await this.sendSmsCodeToCustomer(totpPin, customer);
return { customer, totpCode }; return { customer, totpCode };
} }
@ -356,14 +356,13 @@ export default class CustomersService extends BaseService {
private async sendSmsCodeToCustomer(totpPin: number, customer: Customer) { private async sendSmsCodeToCustomer(totpPin: number, customer: Customer) {
const message = "Votre code de vérification LEcoffre.io est : " + totpPin.toString(); const message = "Votre code de vérification LEcoffre.io est : " + totpPin.toString();
// Sélectionnez le fournisseur de SMS en fonction de la variable d'environnement // Sélectionnez le fournisseur de SMS en fonction de la variable d'environnement
//const selectedProvider = this.variables.SMS_PROVIDER === "OVH" ? this.ovhService : this.smsFactorService; //const selectedProvider = this.variables.SMS_PROVIDER === "OVH" ? this.ovhService : this.smsFactorService;
// Envoi du SMS // Envoi du SMS
if (!customer.contact?.cell_phone_number) return; if (!customer.contact?.cell_phone_number) return;
let success = await this.ovhService.sendSms(customer.contact?.cell_phone_number, message); let success = await this.ovhService.sendSms(customer.contact?.cell_phone_number, message);
// Si l'envoi échoue, basculez automatiquement sur le second fournisseur // Si l'envoi échoue, basculez automatiquement sur le second fournisseur
if (!success) { if (!success) {