Sms feature finished + desactivate in dev
This commit is contained in:
parent
1d8642b61f
commit
cc316aeb2f
@ -20,6 +20,7 @@ export default class OvhService extends BaseService {
|
||||
ovh.request('POST', '/sms/' + serviceName + '/jobs/', {
|
||||
message: message,
|
||||
sender: "LeCoffre",
|
||||
senderForResponse: true,
|
||||
receivers: [phoneNumber],
|
||||
}, (error: any, response: any) => {
|
||||
if (error) {
|
||||
|
@ -16,12 +16,12 @@ export default class SmsFactorService extends BaseService {
|
||||
phoneNumber +
|
||||
"&sender=LeCoffre&text=" +
|
||||
message +
|
||||
"token=" +
|
||||
"&token=" +
|
||||
this.variables.SMS_FACTOR_TOKEN,
|
||||
{},
|
||||
)
|
||||
.then((response) => {
|
||||
console.log("SMS sent successfully via Sms Factor:", response.status);
|
||||
console.log("SMS sent successfully via Sms Factor :" + response);
|
||||
return true;
|
||||
})
|
||||
.catch((error) => {
|
||||
|
@ -110,7 +110,7 @@ export default class CustomersService extends BaseService {
|
||||
const totpCode = await this.saveTotpPin(customer, totpPin, new Date(now + 5 * 60000), reason);
|
||||
if (!totpCode) return null;
|
||||
// 5: Send the SMS code to the customer
|
||||
await this.sendSmsCodeToCustomer(totpPin, customer);
|
||||
if(this.variables.ENV !== 'dev') await this.sendSmsCodeToCustomer(totpPin, customer);
|
||||
return {
|
||||
customer,
|
||||
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);
|
||||
|
||||
// 5: Send the SMS code to the customer
|
||||
await this.sendSmsCodeToCustomer(totpPin, customer);
|
||||
if(this.variables.ENV !== 'dev') await this.sendSmsCodeToCustomer(totpPin, customer);
|
||||
return customer;
|
||||
}
|
||||
|
||||
@ -292,7 +292,7 @@ export default class CustomersService extends BaseService {
|
||||
const totpCode = await this.saveTotpPin(customer, totpPin, new Date(now + 5 * 60000), totpCodeToResend.reason!, true);
|
||||
|
||||
// 7: Send the SMS code to the customer
|
||||
await this.sendSmsCodeToCustomer(totpPin, customer);
|
||||
if(this.variables.ENV !== 'dev') await this.sendSmsCodeToCustomer(totpPin, customer);
|
||||
return { customer, totpCode };
|
||||
}
|
||||
|
||||
@ -355,17 +355,18 @@ export default class CustomersService extends BaseService {
|
||||
}
|
||||
|
||||
private async sendSmsCodeToCustomer(totpPin: number, customer: Customer) {
|
||||
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
|
||||
const selectedProvider = this.variables.SMS_PROVIDER === "OVH" ? this.ovhService : this.smsFactorService;
|
||||
|
||||
// Envoi du SMS
|
||||
if (!customer.contact?.phone_number) return;
|
||||
let success = await selectedProvider.sendSms(customer.contact?.phone_number, totpPin.toString());
|
||||
let success = await selectedProvider.sendSms(customer.contact?.phone_number, message);
|
||||
|
||||
// Si l'envoi échoue, basculez automatiquement sur le second fournisseur
|
||||
if (!success) {
|
||||
const alternateProvider = this.variables.SMS_PROVIDER === "OVH" ? this.smsFactorService : this.ovhService;
|
||||
success = await alternateProvider.sendSms(customer.contact?.phone_number, totpPin.toString());
|
||||
success = await alternateProvider.sendSms(customer.contact?.phone_number, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user