Skip to content

Commit

Permalink
Merge pull request #6 from fless-lab/feat/authentication
Browse files Browse the repository at this point in the history
 Integrate Authentication System
  • Loading branch information
fless-lab authored Jul 1, 2024
2 parents ef4914e + bc41182 commit f6dab76
Show file tree
Hide file tree
Showing 44 changed files with 2,151 additions and 87 deletions.
32 changes: 32 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ ENABLE_CLIENT_AUTH=true
BASIC_AUTH_USER=admin
BASIC_AUTH_PASS=secret

# JWT Tokens
ACCESS_TOKEN_SECRET=your-access-token-secret
ACCESS_TOKEN_EXPIRE_TIME=1h # Adjust as needed
REFRESH_TOKEN_SECRET=your-refresh-token-secret
REFRESH_TOKEN_EXPIRE_TIME=7d # Adjust as needed
TOKEN_ISSUER=your-issuer

# Database
DB_URI=mongodb://mongo:27017
DB_NAME=mydatabase
Expand All @@ -15,6 +22,8 @@ MONGO_CLIENT_PORT=9005
# Cache
REDIS_HOST=redis
REDIS_SERVER_PORT=9079
REDIS_TOKEN_EXPIRE_TIME=31536000 # 1 year in seconds (validity for refresh token)
REDIS_BLACKLIST_EXPIRE_TIME=2592000 # 1 month in seconds

# MinIO
MINIO_ENDPOINT=minio
Expand All @@ -29,6 +38,16 @@ MAILDEV_PORT=1025
MAILDEV_SMTP=9025
MAILDEV_WEBAPP_PORT=9080

# SMTP (for production)
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=your-smtp-username
SMTP_PASS=your-smtp-password

# Mail Senders
FROM_EMAIL=[email protected]
FROM_NAME="Your Service Name"

# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000 # 15 minutes in milliseconds
RATE_LIMIT_MAX=100 # 100 requests per windowMs
Expand All @@ -38,3 +57,16 @@ BRUTE_FORCE_FREE_RETRIES=5
BRUTE_FORCE_MIN_WAIT=300000 # 5 minutes in milliseconds
BRUTE_FORCE_MAX_WAIT=3600000 # 1 hour in milliseconds
BRUTE_FORCE_LIFETIME=86400 # 1 day in seconds

# Bcrypt
BCRYPT_SALT_ROUNDS=10

# Session
SESSION_SESSION_SECRET="mysessionsecret"

#View engine
VIEW_ENGINE=ejs

#OTP
OTP_LENGTH=6
OTP_EXPIRATION=15
98 changes: 49 additions & 49 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,57 @@
// -----------------------------------------------------------------------------------------------------------------------------------------------------

module.exports = {
parserPreset: {
parserOpts: {
headerPattern: /^(\w+)(?:\((\w+)\))?:\s(.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
},
parserPreset: {
parserOpts: {
headerPattern: /^(\w+)(?:\((\w+)\))?:\s(.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
},
plugins: [
{
rules: {
'header-match-team-pattern': (parsed) => {
const { type, subject } = parsed;
const allowedTypes = [
'build',
'chore',
'ci',
'docs',
'feat',
'update',
'fix',
'perf',
'refactor',
'style',
'test',
'translation',
'sec',
},
plugins: [
{
rules: {
'header-match-team-pattern': (parsed) => {
const { type, subject } = parsed;
const allowedTypes = [
'build',
'chore',
'ci',
'docs',
'feat',
'update',
'fix',
'perf',
'refactor',
'style',
'test',
'translation',
'sec',
];

if (!type || !subject) {
return [
false,
"\x1b[31mERROR\x1b[0m: Please follow the format 'feat(auth): user login form' or 'fix: fixing data problems'",
];

if (!type || !subject) {
return [
false,
"\x1b[31mERROR\x1b[0m: Please follow the format 'feat(auth): user login form' or 'fix: fixing data problems'",
];
}

if (!allowedTypes.includes(type)) {
return [
false,
`\x1b[31mERROR\x1b[0m: The commit type '${type}' is not allowed. Allowed types are: [${allowedTypes.join(', ')}]`,
];
}

return [true, ''];
},
}

if (!allowedTypes.includes(type)) {
return [
false,
`\x1b[31mERROR\x1b[0m: The commit type '${type}' is not allowed. Allowed types are: [${allowedTypes.join(', ')}]`,
];
}

return [true, ''];
},
},
],
rules: {
'header-match-team-pattern': [2, 'always'],
'subject-empty': [2, 'never'],
'body-leading-blank': [2, 'always'],
'footer-leading-blank': [2, 'always'],
'footer-empty': [2, 'always'],
},
};
],
rules: {
'header-match-team-pattern': [2, 'always'],
'subject-empty': [2, 'never'],
'body-leading-blank': [2, 'always'],
'footer-leading-blank': [2, 'always'],
// 'footer-empty': [2, 'always'],
},
};
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ services:
- redis
- minio
- maildev
volumes:
- .:/usr/src/app

mongo:
image: mongo
Expand Down
18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,41 @@
"author": "Abdou-Raouf ATARMLA",
"license": "ISC",
"dependencies": {
"@types/connect-flash": "^0.0.40",
"@types/express-session": "^1.18.0",
"bcrypt": "^5.1.1",
"connect-flash": "^0.1.1",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"ejs": "^3.1.10",
"express": "^4.19.2",
"express-brute": "^1.0.1",
"express-brute-mongo": "^1.0.0",
"express-brute-redis": "^0.0.1",
"express-list-endpoints": "^7.1.0",
"express-rate-limit": "^7.3.1",
"express-session": "^1.18.0",
"handlebars": "^4.7.8",
"helmet": "^7.1.0",
"http-errors": "^2.0.0",
"ioredis": "^5.4.1",
"joi": "^17.13.3",
"jsonwebtoken": "^9.0.2",
"minio": "^8.0.0",
"mongoose": "^8.4.3",
"morgan": "^1.10.0"
"morgan": "^1.10.0",
"nodemailer": "^6.9.14"
},
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@types/bcrypt": "^5.0.2",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/express-brute": "^1.0.5",
"@types/express-brute-mongo": "^0.0.39",
"@types/jsonwebtoken": "^9.0.6",
"@types/morgan": "^1.9.9",
"@types/nodemailer": "^6.4.15",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"eslint": "^8.56.0",
Expand All @@ -67,8 +79,10 @@
"lint-staged": "^15.2.7",
"node-ts": "^6.0.1",
"nodemon": "^3.1.3",
"postcss": "^8.4.38",
"prettier": "^3.3.2",
"prettier-plugin-pug": "^1.0.0-alpha.8",
"tailwindcss": "^3.4.4",
"ts-node": "^10.9.2",
"typescript": "^5.0.4"
}
Expand Down
23 changes: 23 additions & 0 deletions src/app/controllers/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Request, Response, NextFunction } from 'express';
import ViewService from '../services/shared/view.service';

class AppController {
static async showHomePage(
req: Request,
res: Response,
next: NextFunction,
): Promise<void> {
try {
const viewService = new ViewService();
req.flash('error', 'Error msg sample : une erreur est survenue.');
req.flash('success', 'Success msg sample : Successfully added.');
viewService.renderPage(req, res, 'index');
} catch (error) {
const viewService = new ViewService();
viewService.renderErrorPage(req, res, 500, 'Internal Server Error');
}
}
}

export default AppController;
Loading

0 comments on commit f6dab76

Please sign in to comment.