INITIALPUSH : AADHAVAN
This commit is contained in:
parent
262a094a8c
commit
e77f06fdb7
4
.gitignore
vendored
4
.gitignore
vendored
@ -6,7 +6,8 @@
|
||||
# Node artifact files
|
||||
node_modules/
|
||||
dist/
|
||||
|
||||
storage/
|
||||
.env
|
||||
# Compiled Java class files
|
||||
*.class
|
||||
|
||||
@ -48,3 +49,4 @@ Thumbs.db
|
||||
*.mov
|
||||
*.wmv
|
||||
|
||||
|
||||
|
||||
16
app/config/db_config.js
Normal file
16
app/config/db_config.js
Normal file
@ -0,0 +1,16 @@
|
||||
require('dotenv').config();
|
||||
|
||||
const { logMsg } = require('../services/logger');
|
||||
module.exports =empModel= {
|
||||
|
||||
"development": {
|
||||
"username": process.env.USER_NAME,
|
||||
"password": process.env.PASSWORD,
|
||||
"database": process.env.DATABASE,
|
||||
"port": process.env.PORT,
|
||||
"host": process.env.HOST,
|
||||
"dialect": "mysql",
|
||||
"logging": (message) =>(logMsg.info(message))
|
||||
|
||||
}
|
||||
};
|
||||
80
app/controllers/jwt_controller.js
Normal file
80
app/controllers/jwt_controller.js
Normal file
@ -0,0 +1,80 @@
|
||||
const { MacModel } = require('../models')
|
||||
const {logMsg} = require('../services/logger')
|
||||
const secretKeyJwt = process.env.SECRETKEY;
|
||||
const { info } = require('winston');
|
||||
const moment = require('moment');
|
||||
|
||||
|
||||
|
||||
module.exports.addMacValue= async(req, res, next)=>{
|
||||
try {
|
||||
const today = moment().format('YYYY/MM/DD');
|
||||
const one_year = moment().add(1, 'year');
|
||||
const nextFiscalYearEndDate = one_year.format('YYYY/MM/DD');
|
||||
|
||||
const mac =await MacModel.findOne({where:{licency_key:req.body.key}});
|
||||
if (mac.dataValues.licency_key == req.body.key) {
|
||||
if (mac.dataValues.isActive == false) {
|
||||
|
||||
const info={
|
||||
licency_key:req.body.key,
|
||||
mac_id: JSON.stringify(req.body.mac_id),
|
||||
mail: req.body.mail,
|
||||
company_name:req.body.company_name,
|
||||
isActive:true,
|
||||
activation_date:today,
|
||||
expiry_date:nextFiscalYearEndDate,
|
||||
}
|
||||
const macUpdate = await MacModel.update(info, {where:{id: mac.dataValues.id}});
|
||||
if (macUpdate) {
|
||||
logMsg.info({status:200,message:"Update Success!", data: info});
|
||||
res.send({status:200,message:" Update Success!", data: info})
|
||||
}
|
||||
} else {
|
||||
const macId = JSON.parse(mac.mac_id);
|
||||
var DBData= [];
|
||||
macId.forEach(function(macid) {
|
||||
DBData.push(macid.mac)
|
||||
});
|
||||
var BodyData = [];
|
||||
var BodyValue = req.body.mac_id;
|
||||
BodyValue.forEach(function(body) {
|
||||
BodyData.push(body.mac)
|
||||
});
|
||||
|
||||
function hasCommonElement(arr1, arr2) {
|
||||
for (let element of arr1) {
|
||||
if (arr2.includes(element)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const isMatch = hasCommonElement(DBData, BodyData);
|
||||
|
||||
if (isMatch) {
|
||||
const info={
|
||||
licency_key:req.body.key,
|
||||
mail: req.body.mail,
|
||||
company_name:req.body.company_name,
|
||||
activation_date:today,
|
||||
expiry_date:nextFiscalYearEndDate,
|
||||
}
|
||||
logMsg.info({status:200,message:" Your Mac is Already Activated!", data: info});
|
||||
res.send({status:200,message:" Your Mac is Already Activated!", data: info});
|
||||
} else {
|
||||
logMsg.info({status:404,message:" Your Mac is Not Match!", data: "No Data!"});
|
||||
res.send({status:404,message:" Your Mac is Not Match!", data: "No Data!"});
|
||||
}
|
||||
}
|
||||
}else{
|
||||
logMsg.info({status:404,message:" Licency Key is No Match DB!", data: "No Data"});
|
||||
res.send({status:404,message:" Licency Key is No Match DB!", data: "No Data"})
|
||||
}
|
||||
} catch (error) {
|
||||
logMsg.info("addMacValue ->Internal Server Error!", error);
|
||||
console.error(error);
|
||||
res.status(404).send('addMacValue ->Internal Server Error!', error);
|
||||
}
|
||||
}
|
||||
32
app/models/MacModel.js
Normal file
32
app/models/MacModel.js
Normal file
@ -0,0 +1,32 @@
|
||||
'use strict'
|
||||
const { Model } = require('sequelize');
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
|
||||
class MacModel extends Model {
|
||||
}
|
||||
|
||||
MacModel.init(
|
||||
{
|
||||
licency_key: {type: DataTypes.STRING},
|
||||
mac_id:{type: DataTypes.STRING},
|
||||
mail: {type: DataTypes.STRING},
|
||||
company_name: {type: DataTypes.STRING},
|
||||
activation_date: {type: DataTypes.STRING,},
|
||||
expiry_type: { type: DataTypes.STRING, defaultValue: 'One Year' },
|
||||
expiry_date: {type: DataTypes.STRING},
|
||||
isActive: {type: DataTypes.BOOLEAN,allowNull: false,defaultValue: false, },
|
||||
app_version: { type: DataTypes.STRING, },
|
||||
createdAt: {type: DataTypes.DATE,allowNull: true},
|
||||
updatedAt: {type: DataTypes.DATE,allowNull: true}
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
tableName: 'macmodels',
|
||||
modelName: 'MacModel',
|
||||
}
|
||||
|
||||
)
|
||||
|
||||
|
||||
return MacModel
|
||||
}
|
||||
46
app/models/index.js
Normal file
46
app/models/index.js
Normal file
@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const {Sequelize,DataTypes} = require('sequelize');
|
||||
const { log } = require('winston');
|
||||
const basename = path.basename(__filename);
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const config = require(__dirname + '/../config/db_config.js')[env];
|
||||
//console.log(env);
|
||||
//console.log(config);
|
||||
const db = {};
|
||||
|
||||
let sequelize;
|
||||
if (config.use_env_variable) {
|
||||
sequelize = new Sequelize(process.env[config.use_env_variable], config);
|
||||
} else {
|
||||
sequelize = new Sequelize(config.database, config.username, config.password, config);
|
||||
}
|
||||
|
||||
fs
|
||||
.readdirSync(__dirname)
|
||||
.filter(file => {
|
||||
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
|
||||
})
|
||||
.forEach(file => {
|
||||
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
|
||||
db[model.name] = model;
|
||||
});
|
||||
|
||||
Object.keys(db).forEach(modelName => {
|
||||
if (db[modelName].associate) {
|
||||
db[modelName].associate(db);
|
||||
}
|
||||
});
|
||||
|
||||
db.sequelize= sequelize;
|
||||
db.Sequelize= Sequelize;
|
||||
|
||||
|
||||
db.sequelize.sync({ force : false})
|
||||
.then(()=>{
|
||||
console.log('Yes DB re-sync done.');
|
||||
})
|
||||
|
||||
module.exports = db;
|
||||
112
app/routes/jwt_route.js
Normal file
112
app/routes/jwt_route.js
Normal file
@ -0,0 +1,112 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const bodyParser = require('body-parser');
|
||||
const app = express();
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
const Mycontroller = require('../controllers/jwt_controller');
|
||||
const { jwtTokenCheck, jwtTokenCheckDataFromDB} = require('../services/authendicate')
|
||||
// const mailFormatCheck = require('../services/mailFormat.Helpper')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /generateToken:
|
||||
* get:
|
||||
* summary: Generate the JWT Token
|
||||
* description: Create a new user with the specified details.
|
||||
* responses:
|
||||
* '201':
|
||||
* description: User created successfully
|
||||
* '400':
|
||||
* description: Bad request. Invalid input or validation error.
|
||||
*/
|
||||
router.get('/generateToken', Mycontroller.generateToken);
|
||||
|
||||
router.get('/tokenChange', jwtTokenCheckDataFromDB , Mycontroller.tokenChange)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /list:
|
||||
* get:
|
||||
* summary: Retrieving a List of Data
|
||||
* description: Retrieving a List of Data in DB
|
||||
* parameters:
|
||||
* - name: auth
|
||||
* in: header
|
||||
* description: an authorization header
|
||||
* required: true
|
||||
* type: string
|
||||
* responses:
|
||||
* '201':
|
||||
* description: User created successfully
|
||||
* '400':
|
||||
* description: Bad request. Invalid input or validation error.
|
||||
*/
|
||||
router.get('/list',jwtTokenCheck, Mycontroller.list);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /addMacValue:
|
||||
* post:
|
||||
* summary: Create a new Business
|
||||
* description: Create a new user with the specified details.
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* key:
|
||||
* type: string
|
||||
* example: 'NGYB6784HUUSDJ'
|
||||
* mail:
|
||||
* type: string
|
||||
* example: 'ss@gmail.com'
|
||||
* company_name:
|
||||
* type: string
|
||||
* example: 'ASD'
|
||||
* mac_id:
|
||||
* type: array
|
||||
* items:
|
||||
* type: object
|
||||
* properties:
|
||||
* address:
|
||||
* type: string
|
||||
* example: '192.168.1.108'
|
||||
* netmask:
|
||||
* type: string
|
||||
* example: '255.255.255.0'
|
||||
* family:
|
||||
* type: string
|
||||
* example: 'IPv4'
|
||||
* mac:
|
||||
* type: string
|
||||
* example: '01:02:03:0a:0b:0c'
|
||||
* internal:
|
||||
* type: boolean
|
||||
* example: false
|
||||
* cidr:
|
||||
* type: string
|
||||
* example: '192.168.1.108/24'
|
||||
* responses:
|
||||
* '201':
|
||||
* description: User created successfully
|
||||
* '400':
|
||||
* description: Bad request. Invalid input or validation error.
|
||||
*/
|
||||
|
||||
|
||||
router.post('/addMacValue', Mycontroller.addMacValue)
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = router
|
||||
26
app/services/logger.js
Normal file
26
app/services/logger.js
Normal file
@ -0,0 +1,26 @@
|
||||
/*Configurations of logger*/
|
||||
var winston = require('winston');
|
||||
const {createLogger,transports} = require('winston');
|
||||
require('winston-daily-rotate-file');
|
||||
|
||||
|
||||
var transport = new transports.DailyRotateFile({
|
||||
filename: 'storage/log/msg.log',
|
||||
datePattern: 'YYYY-MM-DD',
|
||||
zippedArchive: true,
|
||||
maxSize: '20m',
|
||||
maxFiles: '14d'
|
||||
});
|
||||
|
||||
transport.on('rotate', function(oldFilename, newFilename) {
|
||||
// do something fun
|
||||
});
|
||||
|
||||
const logger = createLogger({
|
||||
transports: [
|
||||
transport
|
||||
]
|
||||
});
|
||||
module.exports = {
|
||||
'logMsg': logger,
|
||||
};
|
||||
53
index.js
Normal file
53
index.js
Normal file
@ -0,0 +1,53 @@
|
||||
require('dotenv').config();
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const session = require("express-session");
|
||||
const flash = require('express-flash');
|
||||
const path = require('path');
|
||||
const cookieParser = require("cookie-parser");
|
||||
const swaggerJSDoc = require('swagger-jsdoc');
|
||||
const swaggerUI = require('swagger-ui-express');
|
||||
const SWAGGERENDPOINT = process.env.SWAGGERENDPOINT;
|
||||
|
||||
|
||||
app.set('views', path.join(__dirname, 'app\\views'));
|
||||
app.set('view engine', 'ejs');
|
||||
app.use(express.static(path.join(__dirname, 'storage/css')));
|
||||
app.use(cookieParser());
|
||||
app.use(session({secret: "secret",saveUninitialized: false ,cookie:{ expires:120000 } ,resave: false}));
|
||||
app.use(flash());
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
|
||||
// Swagger setup
|
||||
const swaggerOptions = {
|
||||
definition: {
|
||||
openapi: '3.0.0',
|
||||
info: {
|
||||
title: 'JWt Token Project',
|
||||
version: '1.0.0',
|
||||
description: 'Documentation for your API',
|
||||
},
|
||||
},
|
||||
// Path to the API specs
|
||||
apis: [
|
||||
'./app/routes/jwt_route.js',
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
const swaggerSpec = swaggerJSDoc(swaggerOptions);
|
||||
app.use(`/api-docs`, swaggerUI.serve, swaggerUI.setup(swaggerSpec));
|
||||
|
||||
|
||||
|
||||
|
||||
const go_home = require('./app/routes/jwt_route.js');
|
||||
app.use('/',go_home)
|
||||
|
||||
const PORT_NUMBER = process.env.SERVER_PORT;
|
||||
app.listen({ port: PORT_NUMBER }, async () => {
|
||||
console.log(`Server up on http://localhost:${PORT_NUMBER}`)
|
||||
})
|
||||
|
||||
7795
package-lock.json
generated
Normal file
7795
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
51
package.json
Normal file
51
package.json
Normal file
@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "dt_expressapp",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "nodemon index.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "aadhavan",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.19.0",
|
||||
"cookie": "^0.6.0",
|
||||
"cookie-parser": "^1.4.6",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^10.0.0",
|
||||
"ejs": "^3.1.9",
|
||||
"email-domain-check": "^1.1.4",
|
||||
"email-validator": "^2.0.4",
|
||||
"email-verifier": "^0.4.1",
|
||||
"express": "^4.17.1",
|
||||
"express-fileupload": "^1.4.0",
|
||||
"express-flash": "^0.0.2",
|
||||
"express-session": "^1.17.3",
|
||||
"express-upload": "^0.1.0",
|
||||
"fs": "0.0.1-security",
|
||||
"jquery": "^3.7.0",
|
||||
"jsdom": "^22.1.0",
|
||||
"lodash": "^4.17.21",
|
||||
"log4js": "^6.3.0",
|
||||
"moment": "^2.30.1",
|
||||
"mssql": "^7.2.0",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"mysql2": "^3.6.5",
|
||||
"node-forge": "^1.3.1",
|
||||
"nodemon": "^3.0.1",
|
||||
"path": "^0.12.7",
|
||||
"random-code-generate": "^1.0.5",
|
||||
"request": "^2.88.2",
|
||||
"sequelize": "^6.32.1",
|
||||
"svelte": "^4.2.8",
|
||||
"swagger-jsdoc": "^6.2.8",
|
||||
"swagger-ui-express": "^4.6.3",
|
||||
"validator": "^13.11.0",
|
||||
"window": "^4.2.7",
|
||||
"winston": "^3.3.3",
|
||||
"winston-daily-rotate-file": "^4.5.5",
|
||||
"zxcvbn": "^4.4.2"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user