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/', {
|
ovh.request('POST', '/sms/' + serviceName + '/jobs/', {
|
||||||
message: message,
|
message: message,
|
||||||
sender: "LeCoffre",
|
sender: "LeCoffre",
|
||||||
|
senderForResponse: true,
|
||||||
receivers: [phoneNumber],
|
receivers: [phoneNumber],
|
||||||
}, (error: any, response: any) => {
|
}, (error: any, response: any) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -16,12 +16,12 @@ export default class SmsFactorService extends BaseService {
|
|||||||
phoneNumber +
|
phoneNumber +
|
||||||
"&sender=LeCoffre&text=" +
|
"&sender=LeCoffre&text=" +
|
||||||
message +
|
message +
|
||||||
"token=" +
|
"&token=" +
|
||||||
this.variables.SMS_FACTOR_TOKEN,
|
this.variables.SMS_FACTOR_TOKEN,
|
||||||
{},
|
{},
|
||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log("SMS sent successfully via Sms Factor:", response.status);
|
console.log("SMS sent successfully via Sms Factor :" + response);
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.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);
|
const totpCode = await this.saveTotpPin(customer, totpPin, new Date(now + 5 * 60000), 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
|
||||||
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
|
||||||
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 * 60000), totpCodeToResend.reason!, true);
|
const totpCode = await this.saveTotpPin(customer, totpPin, new Date(now + 5 * 60000), totpCodeToResend.reason!, true);
|
||||||
|
|
||||||
// 7: Send the SMS code to the customer
|
// 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 };
|
return { customer, totpCode };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,17 +355,18 @@ 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();
|
||||||
// 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?.phone_number) return;
|
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
|
// Si l'envoi échoue, basculez automatiquement sur le second fournisseur
|
||||||
if (!success) {
|
if (!success) {
|
||||||
const alternateProvider = this.variables.SMS_PROVIDER === "OVH" ? this.smsFactorService : this.ovhService;
|
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