Skip to content

Commit 0b80d40

Browse files
committed
feat(user account verification): Implemention of user account verification to avoid spams
- send Verify email to user using nodemailer - verify if token in email url is same with token in database - update isVerified to true - user can login only is verified [Delivers #187419049]
1 parent d014e09 commit 0b80d40

File tree

7 files changed

+92
-5
lines changed

7 files changed

+92
-5
lines changed

.env-example

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ SERVICE = < your SERVICE >
2525

2626
EMAIL=<your email>
2727
PASSWORD=<your email password>
28+

.github/workflows/node.js.yml

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
env:
18+
BASE_URL: ${{ secrets.BASE_URL}}
19+
HOST: ${{ secrets.HOST}}
20+
SERVICE: ${{ secrets.SERVICE}}
21+
EMAIL: ${{ secrets.EMAIL}}
22+
PASSWORD: ${{ secrets.PASSWORD}}
1823
DB_TEST_URL: ${{ secrets.DB_TEST_URL }}
1924
DEV_MODE: ${{ secrets.DEV_MODE }}
2025
DB_HOSTED_MODE: ${{ secrets.DB_HOSTED_MODE }}

package-lock.json

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"@types/supertest": "^6.0.2",
7373
"@types/swagger-jsdoc": "^6.0.4",
7474
"@types/swagger-ui-express": "^4.1.6",
75+
"@types/uuid": "^9.0.8",
7576
"@typescript-eslint/eslint-plugin": "^7.7.0",
7677
"@typescript-eslint/parser": "^7.7.0",
7778
"dotenv": "^16.4.5",

src/__test__/users.test.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
NewUser,
1111
user_bad_request,
1212
} from "../mock/static";
13+
import { Token } from "../database/models/token";
1314

1415
jest.setTimeout(30000);
1516

@@ -34,6 +35,7 @@ describe("USER API TEST", () => {
3435

3536
afterAll(async () => {
3637
await deleteTableData(User, "users");
38+
await deleteTableData(Token, "tokens");
3739
});
3840
it("it should register a user and return 201", async () => {
3941
const { body } = await Jest_request.post("/api/v1/users/register")
@@ -63,7 +65,8 @@ describe("USER API TEST", () => {
6365

6466
const { body } = await Jest_request.get(
6567
`/api/v1/users/account/verify/${token}`,
66-
).expect(200);
68+
);
69+
console.log(`/api/v1/users/account/verify/${token}`);
6770

6871
expect(body.status).toStrictEqual(200);
6972
expect(body.message).toStrictEqual("Email verified successfull");
@@ -98,8 +101,8 @@ describe("USER API TEST", () => {
98101
it("should return 404 when a user login with wrong credentials", async () => {
99102
const { body } = await Jest_request.post("/api/v1/users/login")
100103
.send(login_user_wrong_credentials)
101-
.expect(404);
102-
expect(body.status).toStrictEqual("NOT FOUND");
104+
.expect(403);
105+
expect(body.status).toStrictEqual("FORBIDDEN");
103106
expect(body.message).toStrictEqual("Wrong credentials!");
104107
});
105108

src/controllers/userController.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ const login = async (req: Request, res: Response, next: NextFunction) => {
6262

6363
if (info) {
6464
return res
65-
.status(404)
66-
.json(new HttpException("NOT FOUND", info.message));
65+
.status(403)
66+
.json(new HttpException("FORBIDDEN", info.message));
6767
}
6868

6969
(req as any).login(user, (err: Error) => {

src/documention/user/index.ts

+52
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,58 @@ const users = {
7676
responses,
7777
},
7878
},
79+
"/users/account/verify/{token}": {
80+
get: {
81+
tags: ["User"],
82+
summary: "Verify user account",
83+
parameters: [
84+
{
85+
in: "path",
86+
name: "token",
87+
required: true,
88+
type: "string",
89+
description: "Verification token",
90+
},
91+
],
92+
responses: {
93+
"200": {
94+
description: "Email verified successfully",
95+
schema: {
96+
type: "object",
97+
properties: {
98+
status: {
99+
type: "integer",
100+
example: 200,
101+
},
102+
message: {
103+
type: "string",
104+
example: "Email verified successfull",
105+
},
106+
},
107+
},
108+
},
109+
"400": {
110+
description: "Invalid link or something went wrong",
111+
schema: {
112+
type: "object",
113+
properties: {
114+
status: {
115+
type: "integer",
116+
example: 400,
117+
},
118+
message: {
119+
type: "string",
120+
example: "Invalid link",
121+
},
122+
error: {
123+
type: "string",
124+
},
125+
},
126+
},
127+
},
128+
},
129+
},
130+
},
79131
};
80132

81133
export default users;

0 commit comments

Comments
 (0)