Skip to content

Commit

Permalink
Generic APIs: default users/otp verification support added
Browse files Browse the repository at this point in the history
  • Loading branch information
choxx committed Jul 17, 2023
1 parent 5623bf0 commit 4373db3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/api/sms/cdac/cdac.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@ export class CdacService extends SmsService implements SMS {
}

verifyOTP(data: SMSData): Promise<TrackResponse> {
if(
process.env.ALLOW_DEFAULT_OTP === 'true' &&
process.env.DEFAULT_OTP_USERS
){
if(JSON.parse(process.env.DEFAULT_OTP_USERS).indexOf(data.phone)!=-1){
if(data.params.otp == process.env.DEFAULT_OTP) {
return new Promise(resolve => {
const status: TrackResponse = {} as TrackResponse;
status.provider = SMSProvider.cdac;
status.phone = data.phone;
status.networkResponseCode = 200;
status.messageID = Date.now() + '';
status.error = null;
status.providerResponseCode = null;
status.providerSuccessResponse = 'OTP matched.';
status.status = SMSResponseStatus.success;
resolve(status);
});
}
}
}

let verified = false;
try {
verified = speakeasy.totp.verify({
Expand Down
22 changes: 22 additions & 0 deletions src/api/sms/gupshup/gupshup.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,28 @@ export class GupshupService extends SmsService implements SMS {
}

verifyOTP(data: SMSData): Promise<TrackResponse> {
if(
process.env.ALLOW_DEFAULT_OTP === 'true' &&
process.env.DEFAULT_OTP_USERS
){
if(JSON.parse(process.env.DEFAULT_OTP_USERS).indexOf(data.phone)!=-1){
if(data.params.otp == process.env.DEFAULT_OTP) {
return new Promise(resolve => {
const status: TrackResponse = {} as TrackResponse;
status.provider = SMSProvider.gupshup;
status.phone = data.phone;
status.networkResponseCode = 200;
status.messageID = Date.now() + '';
status.error = null;
status.providerResponseCode = null;
status.providerSuccessResponse = 'OTP matched.';
status.status = SMSResponseStatus.success;
resolve(status);
});
}
}
}

console.log({ data });
const options = {
searchParams: {
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as Sentry from '@sentry/node';

async function bootstrap() {
const app = await NestFactory.create(AppModule, { cors: true });
app.getHttpAdapter().getInstance().set('etag', false);

const config = new DocumentBuilder()
.setTitle('e-Samwad User Service')
Expand Down

0 comments on commit 4373db3

Please sign in to comment.