-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft admin set and update password expiry time (#118)
- Loading branch information
Showing
11 changed files
with
206 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,5 +28,4 @@ DOCKER_DATABASE_PASSWORD= | |
GOOGLE_CLIENT_ID= | ||
GOOGLE_CLIENT_SECRET= | ||
|
||
PASSWORD_EXPIRATION_DAYS= | ||
ADMIN_EMAIL= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
import { QueryInterface, DataTypes } from "sequelize"; | ||
|
||
export default { | ||
up: async (queryInterface: QueryInterface) => { | ||
await queryInterface.createTable("settings", { | ||
id: { | ||
type: DataTypes.UUID, | ||
defaultValue: DataTypes.UUIDV4, | ||
allowNull: false, | ||
primaryKey: true | ||
}, | ||
key: { | ||
type: DataTypes.STRING(128), | ||
allowNull: false, | ||
unique: true | ||
}, | ||
value: { | ||
type: DataTypes.STRING(255), | ||
allowNull: false | ||
}, | ||
createdAt: { | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW | ||
}, | ||
updatedAt: { | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW | ||
} | ||
}); | ||
}, | ||
|
||
down: async (queryInterface: QueryInterface) => { | ||
await queryInterface.dropTable("settings"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable */ | ||
import { Model, DataTypes } from "sequelize"; | ||
import sequelizeConnection from "../config/db.config"; | ||
|
||
export interface SettingsAttributes { | ||
id: string; | ||
key: string; | ||
value: string; | ||
createdAt?: Date; | ||
updatedAt?: Date; | ||
} | ||
|
||
class Settings extends Model<SettingsAttributes> implements SettingsAttributes { | ||
declare id: string; | ||
declare key: string; | ||
declare value: string; | ||
declare createdAt?: Date; | ||
declare updatedAt?: Date; | ||
|
||
static associate(models: any) { | ||
} | ||
} | ||
|
||
Settings.init( | ||
{ | ||
id: { | ||
type: DataTypes.UUID, | ||
defaultValue: DataTypes.UUIDV4, | ||
primaryKey: true, | ||
}, | ||
key: { | ||
type: DataTypes.STRING(128), | ||
allowNull: false, | ||
unique: true, | ||
}, | ||
value: { | ||
type: DataTypes.STRING(255), | ||
allowNull: false, | ||
}, | ||
createdAt: { | ||
field: "createdAt", | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW, | ||
}, | ||
updatedAt: { | ||
field: "updatedAt", | ||
type: DataTypes.DATE, | ||
allowNull: false, | ||
defaultValue: DataTypes.NOW, | ||
}, | ||
}, | ||
{ | ||
sequelize: sequelizeConnection, | ||
tableName: "settings", | ||
timestamps: true, | ||
modelName: "Settings", | ||
} | ||
); | ||
|
||
export default Settings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* eslint-disable comma-dangle */ | ||
/* eslint-disable */ | ||
import app from "./index"; | ||
import chai from "chai"; | ||
import chaiHttp from "chai-http"; | ||
|
@@ -15,9 +13,12 @@ import { Socket } from "socket.io"; | |
import { socketAuthMiddleware } from "./middlewares/authorization"; | ||
import { checkPasswordExpiration } from "./middlewares/passwordExpiryCheck"; | ||
import Users from "./databases/models/users"; | ||
import { NextFunction } from "express"; | ||
import { NextFunction, Request, Response } from "express"; | ||
import * as emailService from "./services/sendEmail"; | ||
|
||
|
||
|
||
|
||
chai.use(chaiHttp); | ||
chai.use(sinonChai); | ||
const router = () => chai.request(app); | ||
|
@@ -342,30 +343,6 @@ describe("checkPasswordExpiration middleware", () => { | |
sinon.restore(); | ||
}); | ||
|
||
it("should send an email and respond with 403 if the password is expired", async () => { | ||
sinon.stub(Users, "findByPk").resolves({ | ||
passwordUpdatedAt: new Date( | ||
Date.now() - 1000 * 60 * (PASSWORD_EXPIRATION_MINUTES + 1) | ||
), | ||
email: "[email protected]", | ||
}); | ||
const sendEmailStub = sinon.stub(emailService, "sendEmail").resolves(); | ||
|
||
await checkPasswordExpiration(req, res, next); | ||
|
||
expect(sendEmailStub).to.have.been.calledOnceWith( | ||
"[email protected]", | ||
"Password Expired - Reset Required", | ||
`Your password has expired. Please reset your password using the following link: ${process.env.SERVER_URL_PRO}/reset-password` | ||
); | ||
expect(res.status).to.have.been.calledWith(httpStatus.FORBIDDEN); | ||
expect(res.json).to.have.been.calledWith({ | ||
status: httpStatus.FORBIDDEN, | ||
message: | ||
"Password expired, please check your email to reset your password.", | ||
}); | ||
expect(next).to.not.have.been.called; | ||
}); | ||
|
||
it("should call next if the password is valid", async () => { | ||
sinon.stub(Users, "findByPk").resolves({ | ||
|
@@ -397,10 +374,6 @@ describe("checkPasswordExpiration middleware", () => { | |
|
||
|
||
|
||
import { Request, Response } from 'express'; | ||
|
||
|
||
|
||
const paymentSuccess = (req: Request, res: Response) => { | ||
try { | ||
res.status(httpStatus.OK).json({ status: httpStatus.OK, message: "Payment successful!" }); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.