Skip to content

Commit ca15013

Browse files
authored
Merge pull request #22 from p-society/auth-otp
Addition of Otp flow to project.
2 parents 7a90b3e + 67c9d1b commit ca15013

33 files changed

+407
-254
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@socket.io/redis-adapter": "^8.3.0",
4545
"@types/nodemailer": "^6.4.17",
4646
"bcrypt": "^5.1.1",
47+
"bcryptjs": "^2.4.3",
4748
"bullmq": "^5.34.3",
4849
"class-transformer": "^0.5.1",
4950
"class-validator": "^0.14.1",
@@ -62,6 +63,7 @@
6263
"@nestjs/schematics": "^10.1.4",
6364
"@nestjs/testing": "^10.4.1",
6465
"@types/bcrypt": "^5.0.2",
66+
"@types/bcryptjs": "^2.4.6",
6567
"@types/express": "^4.17.21",
6668
"@types/jest": "^29.5.12",
6769
"@types/lodash": "^4.17.13",

src/app.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { ReactionsModule } from './services/apis/reactions/reactions.module';
1414
import { ProfilesModule } from './services/apis/profiles/profiles.module';
1515
import { QueueModule } from './services/bullmq/queue.module';
1616
import { BullModule } from '@nestjs/bullmq';
17+
import { GenerateOtpModule } from './services/apis/otp/generateOtp.module';
18+
import { MailerModule } from './services/apis/mailer/mailer.module';
1719

1820
@Module({
1921
imports: [
@@ -43,6 +45,8 @@ import { BullModule } from '@nestjs/bullmq';
4345
AdapterModule,
4446
ProfilesModule,
4547
ReactionsModule,
48+
GenerateOtpModule,
49+
MailerModule,
4650
],
4751
controllers: [AppController],
4852
providers: [

src/common/hashing.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as bcrypt from 'bcryptjs';
2+
3+
export async function hashString(input: string): Promise<string> {
4+
const saltRounds = 10;
5+
const hashedString = await bcrypt.hash(input, saltRounds);
6+
return hashedString;
7+
}
8+
9+
export async function compareHashedString(
10+
input: string,
11+
hashedString: string,
12+
): Promise<boolean> {
13+
const isMatch = await bcrypt.compare(input, hashedString);
14+
return isMatch;
15+
}

src/constants/kafkajs-consumer-options.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/constants/otp.constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const OTP_TTL = 10 * 60; // 10 minutes

src/constants/sports-enum.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,14 @@ enum SportsEnum {
55
Basketball = 'Basketball',
66
Volleyball = 'Volleyball',
77
}
8+
9+
export const SportsEnumList = [
10+
SportsEnum.Football,
11+
SportsEnum.Badminton,
12+
SportsEnum.Basketball,
13+
SportsEnum.Cricket,
14+
SportsEnum.Football,
15+
SportsEnum.Volleyball,
16+
];
17+
818
export default SportsEnum;
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { Controller, Post } from '@nestjs/common';
2-
import { MailerService } from './mailer.service';
1+
// import { Controller, Post } from '@nestjs/common';
2+
// import { MailerService } from './mailer.service';
33

4-
@Controller('mail')
5-
export class MailerController {
6-
constructor(private mailerService: MailerService) {}
4+
// @Controller('mail')
5+
// export class MailerController {
6+
// constructor(private mailerService: MailerService) {}
77

8-
// @Public()
9-
// @Post()
10-
// async sendMail() {
11-
// await this.mailerService.sendMPassGenerationEmail(
12-
// 'saswat.pb03@gmail.com',
13-
// 'Saswat',
14-
// 'XYZ'
15-
// )
16-
// await this.mailerService.sendSupportTicketResolvedEmail(
17-
// 'saswat.pb03@gmail.com',
18-
// 'Saswat',
19-
// '123456'
20-
// )
21-
// }
22-
}
8+
// // @Public()
9+
// // @Post()
10+
// // async sendMail() {
11+
// // await this.mailerService.sendMPassGenerationEmail(
12+
// // 'saswat.pb03@gmail.com',
13+
// // 'Saswat',
14+
// // 'XYZ'
15+
// // )
16+
// // await this.mailerService.sendSupportTicketResolvedEmail(
17+
// // 'saswat.pb03@gmail.com',
18+
// // 'Saswat',
19+
// // '123456'
20+
// // )
21+
// // }
22+
// }

src/services/apis/mailer/mailer.module.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { MailerService } from './mailer.service';
44
import { MailerModule as NestMailerModule } from '@nestjs-modules/mailer';
55
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
66
import * as path from 'path';
7-
import { MailerController } from './mailer.controller';
7+
// import { MailerController } from './mailer.controller';
88

99
@Global()
1010
@Module({
@@ -24,15 +24,21 @@ import { MailerController } from './mailer.controller';
2424
from: configService.get<string>('MAIL_FROM'),
2525
},
2626
template: {
27-
dir: path.join(__dirname, 'templates'),
27+
dir: path.join(
28+
__dirname,
29+
'../../../../src/services/apis/mailer/templates',
30+
),
2831
adapter: new HandlebarsAdapter(),
2932
options: {
3033
strict: true,
3134
},
3235
},
3336
options: {
3437
partials: {
35-
dir: path.join(__dirname, 'templates/partials'),
38+
dir: path.join(
39+
__dirname,
40+
'../../../../src/services/apis/mailer/templates/partials',
41+
),
3642
options: {
3743
strict: true,
3844
},
@@ -41,7 +47,7 @@ import { MailerController } from './mailer.controller';
4147
}),
4248
}),
4349
],
44-
controllers: [MailerController],
50+
controllers: [],
4551
providers: [MailerService],
4652
exports: [MailerService],
4753
})

src/services/apis/mailer/mailer.service.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ export class MailerService {
99

1010
async sendMail(
1111
to: string,
12-
subject: string,
13-
content: string,
12+
// subject: string,
13+
// content: string,
14+
otp: string,
1415
template?: string,
15-
context?: Record<string, any>,
16+
//context?: Record<string, any>,
1617
) {
1718
await this.mailerService.sendMail({
1819
to,
19-
subject,
20-
text: content,
20+
subject: 'OTP for your account',
2121
template: template ? `./${template}` : undefined,
22-
context: context || {},
22+
context: {
23+
otp,
24+
supportEmail: 'techsociety@iiit-bh.ac.in',
25+
},
2326
});
2427
}
2528
}
Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,68 @@
1-
<p> Use
2-
the OTP below to complete the process:</p>
3-
<div class='otp'> {{otp}} </div>
4-
<p>This OTP is valid for 15 minutes. If you didn’t request this, please ignore
5-
this email or contact support at
6-
{{supportEmail}}</p>
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<style>
7+
body {
8+
font-family: Arial, sans-serif;
9+
background-color: #f4f4f4;
10+
margin: 0;
11+
padding: 0;
12+
}
13+
.container {
14+
max-width: 600px;
15+
margin: 20px auto;
16+
background-color: #ffffff;
17+
padding: 20px;
18+
border-radius: 8px;
19+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
20+
}
21+
.header {
22+
text-align: center;
23+
padding-bottom: 20px;
24+
border-bottom: 1px solid #dddddd;
25+
}
26+
.header h1 {
27+
margin: 0;
28+
color: #333333;
29+
}
30+
.content {
31+
padding: 20px 0;
32+
}
33+
.otp {
34+
font-size: 24px;
35+
font-weight: bold;
36+
color: #333333;
37+
text-align: center;
38+
margin: 20px 0;
39+
}
40+
.footer {
41+
text-align: center;
42+
padding-top: 20px;
43+
border-top: 1px solid #dddddd;
44+
color: #777777;
45+
}
46+
.footer a {
47+
color: #007BFF;
48+
text-decoration: none;
49+
}
50+
</style>
51+
</head>
52+
<body>
53+
<div class="container">
54+
<div class="header">
55+
<h1>Programming Society</h1>
56+
</div>
57+
<div class="content">
58+
<p>Dear Member,</p>
59+
<p>Use the OTP below to complete the process:</p>
60+
<div class="otp">{{otp}}</div>
61+
<p>This OTP is valid for 10 minutes. If you didn’t request this, please ignore this email or contact support at <a href="mailto:{{supportEmail}}">{{supportEmail}}</a>.</p>
62+
</div>
63+
<div class="footer">
64+
<p>Thank you,<br>Programming Society Team</p>
65+
</div>
66+
</div>
67+
</body>
68+
</html>

0 commit comments

Comments
 (0)