Skip to content

Commit

Permalink
send random number in sms
Browse files Browse the repository at this point in the history
  • Loading branch information
bahram1249 committed Mar 14, 2024
1 parent 197151e commit c3b52a4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ SKU_PREFIX="<SET_PREFIX_SKU_ECOMMERCE>"
PRODUCT_INVENTORY_STATUS_KEEPJOBS=100
```

# SMS

```bash
SMS_USERNAME=<Api_Username>
SMS_PASSWORD=<Api_Password>
```

## Running the app

```bash
Expand Down
3 changes: 2 additions & 1 deletion apps/discount-coffe/src/controller/login/login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Request, Response } from 'express';
import { AuthService } from '@rahino/core/auth/auth.service';
import { InjectModel } from '@nestjs/sequelize';
import { SmsService } from '@rahino/sms/sms.service';
import { getIntegerRandomArbitrary } from '@rahino/commontools';

@Injectable()
export class LoginService {
Expand Down Expand Up @@ -47,7 +48,7 @@ export class LoginService {
password: dto.phoneNumber,
});
}
const rand = '123456';
const rand = getIntegerRandomArbitrary(100000, 999999).toString();
req.session.userId = user.id;
req.session.verifyCode = rand;
await this.smsService.sendMessage({ text: rand, to: dto.phoneNumber });
Expand Down
3 changes: 3 additions & 0 deletions libs/commontools/src/functions/getIntegerRandomArbitrary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getIntegerRandomArbitrary(min: number, max: number) {
return Math.floor(Math.random() * (max - min)) + min;
}
1 change: 1 addition & 0 deletions libs/commontools/src/functions/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './replace-all';
export * from './replace-character-slug';
export * from './getIntegerRandomArbitrary';
3 changes: 2 additions & 1 deletion libs/sms/src/services/melipayamak.servie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class MeliPayamakService implements SmsProviderInterface {
message: MessageInterface,
bodyId?: string,
) {
await axios.post(
const request = await axios.post(
'https://rest.payamak-panel.com/api/SendSMS/BaseServiceNumber',
{
username: username,
Expand All @@ -19,5 +19,6 @@ export class MeliPayamakService implements SmsProviderInterface {
bodyId: bodyId,
},
);
console.log(request.data);
}
}

0 comments on commit c3b52a4

Please sign in to comment.