✨ Improving comprehension of code
This commit is contained in:
parent
70845595df
commit
1d8642b61f
@ -6,7 +6,6 @@ import CustomersService, {
|
|||||||
InvalidPasswordError,
|
InvalidPasswordError,
|
||||||
InvalidTotpCodeError,
|
InvalidTotpCodeError,
|
||||||
NotRegisteredCustomerError,
|
NotRegisteredCustomerError,
|
||||||
PasswordAlreadySetError,
|
|
||||||
SmsNotExpiredError,
|
SmsNotExpiredError,
|
||||||
TooSoonForNewCode,
|
TooSoonForNewCode,
|
||||||
TotpCodeExpiredError,
|
TotpCodeExpiredError,
|
||||||
@ -141,7 +140,7 @@ export default class AuthController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const customer = await this.customerService.setFirstPassword(email, totpCode, password);
|
const customer = await this.customerService.setPassword(email, totpCode, password);
|
||||||
if (!customer) {
|
if (!customer) {
|
||||||
this.httpBadRequest(response, "Customer not found");
|
this.httpBadRequest(response, "Customer not found");
|
||||||
return;
|
return;
|
||||||
@ -153,7 +152,7 @@ export default class AuthController extends ApiController {
|
|||||||
const refreshToken = this.authService.generateRefreshToken(payload);
|
const refreshToken = this.authService.generateRefreshToken(payload);
|
||||||
this.httpSuccess(response, { accessToken, refreshToken });
|
this.httpSuccess(response, { accessToken, refreshToken });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof TotpCodeExpiredError || error instanceof PasswordAlreadySetError) {
|
if (error instanceof TotpCodeExpiredError) {
|
||||||
this.httpBadRequest(response, error.message);
|
this.httpBadRequest(response, error.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ export default class CustomersService extends BaseService {
|
|||||||
* @param password
|
* @param password
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public async setFirstPassword(email: string, totpCode: string, password: string): Promise<Customer | null> {
|
public async setPassword(email: string, totpCode: string, password: string): Promise<Customer | null> {
|
||||||
// 1: Check if the customer exists
|
// 1: Check if the customer exists
|
||||||
const customer = await this.getByEmail(email);
|
const customer = await this.getByEmail(email);
|
||||||
if (!customer) return null;
|
if (!customer) return null;
|
||||||
@ -212,7 +212,7 @@ export default class CustomersService extends BaseService {
|
|||||||
const hashedPassword = await this.authService.hashPassword(password);
|
const hashedPassword = await this.authService.hashPassword(password);
|
||||||
|
|
||||||
// 7: Set the password in database and return the result of the update
|
// 7: Set the password in database and return the result of the update
|
||||||
return await this.setPassword(customer, hashedPassword);
|
return await this.setPasswordInDatabase(customer, hashedPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -300,7 +300,7 @@ export default class CustomersService extends BaseService {
|
|||||||
* @description : Set password for a customer
|
* @description : Set password for a customer
|
||||||
* @throws {Error} If customer cannot be updated
|
* @throws {Error} If customer cannot be updated
|
||||||
*/
|
*/
|
||||||
private async setPassword(customer: Customer, password: string) {
|
private async setPasswordInDatabase(customer: Customer, password: string) {
|
||||||
return await this.customerRepository.update(
|
return await this.customerRepository.update(
|
||||||
customer.uid as string,
|
customer.uid as string,
|
||||||
Customer.hydrate<Customer>({
|
Customer.hydrate<Customer>({
|
||||||
@ -360,7 +360,7 @@ export default class CustomersService extends BaseService {
|
|||||||
|
|
||||||
// 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, totpPin.toString());
|
||||||
|
|
||||||
// Si l'envoi échoue, basculez automatiquement sur le second fournisseur
|
// Si l'envoi échoue, basculez automatiquement sur le second fournisseur
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user