Updating sms code in totp code

This commit is contained in:
Maxime Lalo 2023-11-27 10:55:38 +01:00
parent d32532b5ed
commit 3835127d63

View File

@ -48,26 +48,26 @@ export default class AuthController extends ApiController {
@Post("/api/v1/customer/auth/login") @Post("/api/v1/customer/auth/login")
protected async login(req: Request, response: Response) { protected async login(req: Request, response: Response) {
const email = req.body["email"]; const email = req.body["email"];
const smsCode = req.body["smsCode"]; const totpCode = req.body["totpCode"];
const password = req.body["password"]; const password = req.body["password"];
if (!email) { if (!email) {
this.httpBadRequest(response, "Email is required"); this.httpBadRequest(response, "email is required");
return; return;
} }
if (!smsCode) { if (!totpCode) {
this.httpBadRequest(response, "Sms code is required"); this.httpBadRequest(response, "totpCode is required");
return; return;
} }
if (!password) { if (!password) {
this.httpBadRequest(response, "Password is required"); this.httpBadRequest(response, "password is required");
return; return;
} }
try { try {
const customer = await this.customerService.login(email, smsCode, password); const customer = await this.customerService.login(email, totpCode, password);
if (!customer) { if (!customer) {
this.httpBadRequest(response, "Customer not found"); this.httpBadRequest(response, "Customer not found");
return; return;
@ -97,7 +97,7 @@ export default class AuthController extends ApiController {
@Post("/api/v1/customer/auth/set-password") @Post("/api/v1/customer/auth/set-password")
protected async setPassword(req: Request, response: Response) { protected async setPassword(req: Request, response: Response) {
const email = req.body["email"]; const email = req.body["email"];
const smsCode = req.body["smsCode"]; const totpCode = req.body["totpCode"];
const password = req.body["password"]; const password = req.body["password"];
if (!email) { if (!email) {
@ -105,7 +105,7 @@ export default class AuthController extends ApiController {
return; return;
} }
if (!smsCode) { if (!totpCode) {
this.httpBadRequest(response, "Sms code is required"); this.httpBadRequest(response, "Sms code is required");
return; return;
} }
@ -116,7 +116,7 @@ export default class AuthController extends ApiController {
} }
try { try {
const customer = await this.customerService.setFirstPassword(email, smsCode, password); const customer = await this.customerService.setFirstPassword(email, totpCode, password);
if (!customer) { if (!customer) {
this.httpBadRequest(response, "Customer not found"); this.httpBadRequest(response, "Customer not found");
return; return;
@ -164,7 +164,7 @@ export default class AuthController extends ApiController {
this.httpNotFoundRequest(response, "Customer not found"); this.httpNotFoundRequest(response, "Customer not found");
return; return;
} }
this.httpSuccess(response, { validCode: true }); this.httpSuccess(response, { validCode: true, firstConnection: customer.password === null });
} catch (error) { } catch (error) {
if (error instanceof InvalidTotpCodeError || error instanceof TotpCodeExpiredError) { if (error instanceof InvalidTotpCodeError || error instanceof TotpCodeExpiredError) {
this.httpUnauthorized(response, error.message); this.httpUnauthorized(response, error.message);