Compare commits

...

10 Commits

Author SHA1 Message Date
AADHAVAN
58ce2a053a aadhavan 2023-09-21 14:48:39 +05:30
suseendhiran17
5134b8ac6a change ejs path : suseendhiran 2022-12-05 11:24:39 +05:30
suseendhiran17
69053d6d15 suseendhiran 2022-12-05 10:49:44 +05:30
suseendhiran17
5caa5e2cdf suseendhiran 2022-11-29 12:20:16 +05:30
suseendhiran17
4d251e0e7f controller : suseendhiran 2022-11-29 10:46:37 +05:30
suseendhiran17
ff6321e0c1 change login btn : suseendhiran 2022-11-29 10:45:28 +05:30
suseendhiran17
65ea397989 change login btn : suseendhiran 2022-11-29 10:43:37 +05:30
suseendhiran17
59165504b8 suseendhiran 2022-11-28 14:29:55 +05:30
suseendhiran17
0cf797a2e3 del credit.js file : suseendhiran 2022-11-28 11:10:54 +05:30
suseendhiran17
c7e0be4172 ini cmt : suseendhiran 2022-11-28 11:07:30 +05:30
16 changed files with 11857 additions and 50 deletions

53
.gitignore vendored
View File

@ -1,50 +1,3 @@
# These are some examples of commonly ignored file patterns.
# You should customize this list as applicable to your project.
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore
# Node artifact files
node_modules/
dist/
# Compiled Java class files
*.class
# Compiled Python bytecode
*.py[cod]
# Log files
*.log
# Package files
*.jar
# Maven
target/
dist/
# JetBrains IDE
.idea/
# Unit test reports
TEST*.xml
# Generated by MacOS
.DS_Store
# Generated by Windows
Thumbs.db
# Applications
*.app
*.exe
*.war
# Large media files
*.mp4
*.tiff
*.avi
*.flv
*.mov
*.wmv
/node_modules
/storage
.env

View File

@ -0,0 +1,8 @@
[
{
"email": "aadhavanvalli@gmail.com"
},
{
"email": "aadhavancarousell@gmail.com"
}
]

View File

@ -0,0 +1,8 @@
{
"folders": [
{
"path": "../.."
}
],
"settings": {}
}

View File

@ -0,0 +1,13 @@
{
"type": "service_account",
"project_id": "rosy-semiotics-399007",
"private_key_id": "a9066914a24a4cf1892ec3d5e73dcbdd9e0c5690",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDnrREnBGg7V35b\nxF4754WUdPniqyIojGO0NzThMHDzcLtu+bD7PTlkE1yYT7oUk8ncw7ogKEymuAoY\nnIvqkgEnmulva+stBIqRVVcUndhFTXB/mw4g0TfjW9MZgD4fkK+B2UpPnsWPZikf\n2zECHDTQ/mhXFlv70R8arCnsGY3dOEupdfEyO6mt2i0Z0YG1Ni8TJBdV7HvGAFt5\nsFTS/igxQYUAZQ+uIbC1NbdCgWIQdlsB83YQy2gvHXxtL+7Luyd0kK0SY1lun0bC\nJk2HsE3OWpgiyFi646eoHXuzs6J2TANVPwsLsMCxRO1EkKFRSVDGimmE0FMumbi1\nVCDHZpdPAgMBAAECggEAAMIuTQ2Lf4iGqIbUWUwlnT6IOuoKz3IIgq2vBcgCiPKm\n+CnC1bjjmBJJTMCmEnYIRJdXdhd9+MEyErH78iWFX3Jk94y1edZBrwePEklaA6Jb\n2DhA4rsxM12mdLc0M7kcsNmStG0sXY74Wu19E9/Ve0rVX3p6Z8M7Ox/7dpWSQ1W4\n00uM8j+5xAyosTiMfsPxS2fnAZTB6cXtgy0vowsHL8ffmFZWdW0kxOI2djvcXTsg\nzm2Cz0Tk8a/RVFhvithBIIhtvXBy6ECQb+WUbw1nlWbUITt9Wc9ob5L7fWsRDY9v\n3U5QmN1yTBrhyx0lidOcYDTMkeHJXLVhNSidILn/gQKBgQD/Gj7B51p8q6Ce8ERQ\ngaH67DUAZD5z69Mp+Rj4mHuCldhHM+aZs013GpeDRhOIWfBDsTiZrt6KZqoyK1zf\nD2qr68BTRcxFOk6z22tv9A5pNcU8RhN4MdwRehk9bsxLWLpF7ARXzgQHKSy2Z+WG\n3CYrQSSvTTuVHuqVlEOQ5LuEIQKBgQDofbkcyItButCzzWWl6yGYzpTyZ5CjADQu\nevxQBj6JtnB2eWZU2uuDM4YZi+UgVfqgiZ50gaOp9Tgg0O7Odq08NtnpIDiVPiYq\nCtfJZHFpQjCtQmbNQj6D9s56d7Zfkj9AceDS5gROsJ2efnylvQ4ciRvaeEN+ES9o\nXfREqA6tbwKBgQCIQr6O2ELvIMWU4AW9cuDQpObSpLjvNmH+o32BHAGtCNkTf1eH\ndczE98FCb2XziQbbQYhYHp3kE16JmbvrsdJqrmx2jmvD9pcfXu6OSDCCZiRKQ6wW\noZtJAo0E0W/yNxyYSK8xL2vbX1TwwaJKXMFOjWdI89oFlxP6fc1xUZwPwQKBgBg/\nPHYfCD8Dr86AxnAmdKuOKASb/n6xf7+1PelOrWkJaPNCOATzjApz7jFt4KidrvTd\nRXRbLOmF1KO/hphr0idshQ+GN8CA6dQKq3SqkBVtPMxlF3mixghXTjOBlrii9QvQ\nlKUKLjrSuq2T/YX/kKAzQH9peYiFXE9jNR2P9W/rAoGBAKitQDMBZ7Ov1vLsL3ZK\nhkx4cbFV9pQcjTQr62VVyNKXgq/gfwq57YnErQyRTtYVMkJT2D5cNOiiV5nwOrjT\nz34YqYb8T7jbfcdRO/QQ60wgcx5eJDeCX1gqRKMl+0PoS3l58yZ0n30eulBCUwtv\nnrO/gauaV/QcXqSEkvzU0W5s\n-----END PRIVATE KEY-----\n",
"client_email": "test-google-sheet@rosy-semiotics-399007.iam.gserviceaccount.com",
"client_id": "106850194283146982068",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/test-google-sheet%40rosy-semiotics-399007.iam.gserviceaccount.com",
"universe_domain": "googleapis.com"
}

View File

@ -0,0 +1,321 @@
// const { sequelize,Test} = require('../models')
const { logMsg } = require('../services/logger.js');
const { GoogleSpreadsheet } = require('google-spreadsheet');
const fs = require('fs');
const path = require('path');
// const { log } = require('util');
require('dotenv').config();
let dropdown = [];
let column_name;
let doc;
let CREDENTIALS;
// use in addRow and getRow api
let tempData = [];
const filePath = path.join(__dirname, 'data.json');
const datafromjson = require('./data.json');
const { log } = require('console');
// const { col } = require('sequelize');
let number; // Declare number as a global variable
async function fetchSheetData() {
try {
let sheet1 = doc.sheetsByIndex[0];
let rows1 = await sheet1.getRows();
number = rows1.length+1; // Assign the value to the global variable 'number'
// You can now use the 'number' variable as a global variable.
console.log(`Number of rows: ${number}`);
} catch (error) {
console.error('Error fetching sheet data:', error);
}
}
// Call the async function to fetch and work with sheet data.
// You can use 'number' outside of the function.
console.log(`Global number variable: ${number}`);
exports.Welcome = (req, res) =>
{
// number=0;
console.log(datafromjson.length);
try
{
const Msg = "Welcom....!";
console.log(Msg);
logMsg.info("Api Call Success");
res.send({'status':200 , message:"Success." ,'data': Msg});
} catch(err) {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
}); } //end of try catch
};
exports.loginPage = async (req, res ) =>
{
try
{
res.render( 'login' ,function (err, html ) { res.send(html) })
} catch(err) {
res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" });
} //end of try catch
};
exports.adduser = async (req, res ) =>
{
try
{
res.render( 'adduser' ,function (err, html ) { res.send(html) })
} catch(err) {
res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" });
} //end of try catch
};
exports.addjson = async (req, res ) =>
{
try
{
const getvalue = req.body.data;
// console.log(req.body.data);
let newData={"email":getvalue};
fs.readFile(filePath, 'utf8', (readErr, data) => {
if (readErr) {
console.error('Error reading file:', readErr);
return;
}
let existingData = [];
try {
// Parse the existing JSON data (if any)
existingData = JSON.parse(data);
} catch (parseErr) {
console.error('Error parsing existing data:', parseErr);
}
// Append the new data to the existing array
existingData.push(newData);
// Write the updated data back to the JSON file
fs.writeFile(filePath, JSON.stringify(existingData, null, 2), (writeErr) => {
if (writeErr) {
console.error('Error writing to file:', writeErr);
} else {
console.log('Data appended and saved to file successfully.');
}
});
})
if(rows[0]['Gatnayak'] == tempData[0].email ) {res.send({'status':200 , message:"Success." ,'data': "success" , 'statusCode' : 1 }); }
else{res.send({'status':200 , message:"Success." ,'data': "success", 'statusCode' : 0 }); }
} catch(err) {
res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" });
} //end of try catch
};
exports.getRow = async (req, res) =>
{
try
{
fetchSheetData();
for (let index = 0; index < datafromjson.length; index++) {
// console.log(req.query.email);
// email = req.query.email;
const email=req.body.email;
req.session.user = { email };
// console.log(req.session.user.email);
// console.log(email);
aadhaemail= datafromjson[0].email;
let emaill = datafromjson[index].email;
if (email == emaill) {
const empData = [];
tempData = ['fdd'];
await doc.loadInfo();
let sheet = doc.sheetsByIndex[0];
let rows = await sheet.getRows();
// const number = rows.length+1;
category = []; age_Category = [];
basthi = []; varga = [];
milan_shaka = []; poruppu = [];
blood_group = []; ganavesh_2w_4w_basg = [];
// new_index = 0;
category.push('Redmi','Samsung','ONEPLUS');
age_Category.push('18-21','22-25','26-30');
basthi.push('Niruha/Kashaya Basthi','Anuvasana Basthi');
varga.push('Rasi','Hora','Chaturthamsa','Dasamsa','Shodasamsa');
milan_shaka.push('');
poruppu.push('');
blood_group.push('A+','A-','B+','B-','AB+','AB-','O+','O-');
ganavesh_2w_4w_basg.push('')
for (let index = 0; index < rows.length; index++) {
const row = rows[index];
category.push(row['Category']);
age_Category.push(row['Age Category']);
basthi.push(row['Basthi']);
varga.push(row['Varga']);
milan_shaka.push(row['Milan / Shaka']);
poruppu.push(row['Poruppu']);
blood_group.push(row['Blood Group']);
ganavesh_2w_4w_basg.push(row['Ganavesh']);
// if (index == rows.length-1) {
// new_index = Number(row.Sl) + 1;
// }
};
dropdown ={
"category": [...new Set(category)],
"age_Category" : [...new Set(age_Category)],
"basthi" : [...new Set(basthi)],
"varga" : [...new Set(varga)],
"milan_shaka" : [...new Set(milan_shaka)],
"poruppu" : [...new Set(poruppu)],
"blood_group" : [...new Set(blood_group)],
"ganavesh_2w_4w_basg" : [...new Set(ganavesh_2w_4w_basg)],
// "new_index" : new_index
}
for (let index = 0; index < rows.length; index++) {
const row = rows[index];
if(index == 0){ column_name = row._sheet.headerValues; }
if (row.email == email) {
var obj = {}
for (let i = 0; i < column_name.length; i++){
Object.assign( obj , { [column_name[i]] : row[column_name[i]] });
}
tempData.push(obj);
}
};
// if (tempData.length > 0) {
for (let index = 0; index < rows.length; index++) {
const row = rows[index];
// console.log(rows[0]._rawData[22]);
// if (row == email || row.Gatnayak == tempData[0]['email'] ) {
if(true){
// console.log(row.);
var obj = {}
for (let i = 0; i < column_name.length; i++){
Object.assign( obj , { [column_name[i]] : row[column_name[i]] });
}
empData.push(obj);
}
};
res.render( 'displaydata' , { "data" : empData , "dropdown" : dropdown , aadhaemail,email,number} , function (err, html ) { res.send(html) });
// }
// else{
// res.send('<p style="text-align:center;font-size: 4em;top: 510px;font-style:bold">No Data</p>');
// }
}
}
res.end("<h1 style='text-align:center;font-size:40px'>No Data</h1>");
}catch(err) {
res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" });
}
};
exports.addRow = async (req, res) =>{
try{
newData = req.body.data;
console.log(newData);
var obj = {}
for (let i = 0; i < column_name.length; i++){
Object.assign( obj , { [column_name[i]] : newData[i] });
}
let rows = [obj];
await doc.loadInfo();
let sheet = doc.sheetsByIndex[0];
for (let index = 0; index < rows.length; index++) {
const row = rows[index];
await sheet.addRow(row);
}
if(rows[0]['Gatnayak'] == tempData[0].email ) {res.send({'status':200 , message:"Success." ,'data': "success" , 'statusCode' : 1 }); }
else{res.send({'status':200 , message:"Success." ,'data': "success", 'statusCode' : 0 }); }
number++;
} catch(err) {
res.status(500).send({'status':404,
message: err.message || "Some error occurred while inserting statements." ,'data': "No data"
}); } //end of try catch
};
exports.updateRow = async (req, res ) =>
{
try
{
Olddata = req.body.Old;
Newdata = req.body.New;
// console.log('old'+Olddata[1]);// this will give old number same
// console.log('new'+Newdata[1]);// this will give new number sam
Old = {}; New = {};
column_name.forEach(async(element , index) => {
Object.assign( Old , { [element] : Olddata[index]});//oldata
Object.assign( New , { [element] : Newdata[index]});//newdata
});
arrKeys = [ ];
arrKeys = Object.keys(Old);//keys -> heading values -> datas
var updateVal = [];
for (let i = 0; i < arrKeys.length ; i++) {
if (Old[arrKeys[i]] != New[arrKeys[i]]) {
// if (Old[arrKeys[i]] == New[arrKeys[i]]) {
obj = { "keyValue" : arrKeys[i] , oldValue : Old[arrKeys[i]] , newValue : New[arrKeys[i]] };
updateVal.push(obj)
obj = { };
}
}
console.log(updateVal);
//console.log(updateVal[0].newValue); // this is the value for compare and update the value in sheet
// load the documents info
await doc.loadInfo();
// Index of the sheet
let sheet = doc.sheetsByIndex[0]; //it will detials of googlesheet
let rows = await sheet.getRows();
// console.log(rows[0]._rawData); //this is give the googlesheet values by changin the [] value to get different
updateVal.forEach(async(element) => {
// console.log(rows.length);//check in
// console.log(rows[0]._rawData[4]); //this will get the phone number
for (let index = 0; index < rows.length; index++) {
const row = rows[index]._rawData[1];
// console.log("Row->"+row);
// if (updateVal[0].newValue) {
//if (row[element.keyValue] === element.oldValue) {//row[element.keyValue]-> categry value one by one
if(Newdata[1]==row){
rows[index][element.keyValue] = element.newValue;
await rows[index].save();
break;
}
// }
};
});
res.send({'status':200 , message:"Success." ,'data': "Msg"})
} catch(err) {
res.send({'status':404,message: err.message || "Some error occurred while retrieving data." ,'data': "No data" });
} //end of try catch
};
(async function ( req , res ) {
const private_keyy = process.env.PRIVATE_KEY.replace(/\\n/g, '\n');
// spreadsheet key is the long id in the sheets URL
const RESPONSES_SHEET_ID = process.env.RESPONSES_SHEET_ID;
// Create a new document
doc = new GoogleSpreadsheet(RESPONSES_SHEET_ID);
// use service account creds
await doc.useServiceAccountAuth({ client_email: process.env.CLIENT_EMAIL , private_key: private_keyy });
// load the documents info
await doc.loadInfo();
// Index of the sheet
let sheet = doc.sheetsByIndex[0];
// Get all the rows
let rows = await sheet.getRows();
})();

38
app/routes/routes.js Normal file
View File

@ -0,0 +1,38 @@
module.exports = app => {
const request = require("request");
const cors=require('cors');
const Mycontroller = require("../controllers/test.controller.js");
const { logMsg } = require('../services/logger.js');
var router = require("express").Router();
/**
* @swagger
* /api/demo:
* get:
* summary: Demo Api
* description: Welcome Message
* responses:
* 200:
* description: success
*/
// router.get("/demo", Mycontroller.Welcome);
router.get("/home", Mycontroller.loginPage);
router.get("/adduser", Mycontroller.adduser);
router.post("/addjson", Mycontroller.addjson);
// router.get("/getRow", Mycontroller.get);
router.post("/getRow", Mycontroller.getRow);
router.post("/addRow", Mycontroller.addRow);
router.post("/updateRow", Mycontroller.updateRow);
// routes started here
app.use('/', router);
};

26
app/services/logger.js Normal file
View 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,
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
app/views/Y4Pb2E.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

250
app/views/adduser.ejs Normal file
View File

@ -0,0 +1,250 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<style>
/* Medium Devices, Desktops */
@media only screen and (min-width : 992px) {
* {
box-sizing: border-box;
}
body {
background-color: #435d7d;
}
#div_center{
background-color: #ffffff;
width: 500px;
height: 600px;
margin: 50px auto 10px auto;
padding: 30px;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 10px -3px #333;
text-align: center;
}
#div_1{
display: flex;
justify-content: center; /* Horizontally center content */
align-items: center; /* Vertically center content */
height: 100vh;
}
h3{
/* font-family: Google Sans,Noto Sans Myanmar UI,arial,sans-serif; */
font-size: 26px;
/* margin-top: 70px; */
}
label{
display: flex;
padding-left: 40px;
padding-top: 10px;
}
input{
/* background-color: #999; */
border-style: solid;
border-radius: 2px;
}
/* Basic styles for the input container */
.input-container {
position: relative;
margin: 20px;
}
/* Style the input field */
.input-container input {
width: 90%;
padding: 10px;
border: none;
/* border-bottom: 2px solid #2196F3; */
outline: none;
font-size: 16px;
border-style: solid;
border-width: 1px;
border-color: lightgrey;
}
/* Style the label (initially hidden) */
.input-container label {
position: absolute;
top: 0;
left: 0;
pointer-events: none;
transition: 0.2s ease all;
font-size: 16px;
color: #999; /* Color for the label */
}
/* Move the label up when input is focused */
.input-container input:focus + label,
.input-container input:valid + label {
top: -20px;
font-size: 12px;
color: black;
/* color: #2196F3; */
}
#submitBtn{
font-size: 20px;
background-color:#1a71eb;
border-color: #1a71eb;
font-family: Google Sans,Noto Sans Myanmar UI,arial,sans-serif;
font-size: 14px;
width: 80px;
height: 30px;
color: #eeeeee;
margin-top: 20px;
}
img{
display: block;
width: 200px;
margin: 30px auto;
/* box-shadow: 0 5px 10px -7px #333333; */
border-radius: 50%;
}
}
/* Smartphones (portrait and landscape) ----------- */
@media only screen and (max-width : 992px){
body {
background-color: #eeeeee;
}
#div_center{
background-color: #ffffff;
width: 500px;
height: 600px;
margin: 50px auto 10px auto;
padding: 30px;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 10px -3px #333;
text-align: center;
}
#div_1{
display: flex;
justify-content: center; /* Horizontally center content */
align-items: center; /* Vertically center content */
height: 100vh;
}
h3{
font-family: Google Sans,Noto Sans Myanmar UI,arial,sans-serif;
font-size: 24px;
}
label{
display: flex;
padding-left: 40px;
padding-top: 10px;
}
input{
/* background-color: #999; */
border-style: solid;
border-radius: 2px;
}
/* Basic styles for the input container */
.input-container {
position: relative;
margin: 20px;
}
/* Style the input field */
.input-container input {
width: 90%;
padding: 10px;
border: none;
/* border-bottom: 2px solid #2196F3; */
outline: none;
font-size: 16px;
border-style: solid;
border-width: 1px;
border-color: lightgrey;
}
/* Style the label (initially hidden) */
.input-container label {
position: absolute;
top: 0;
left: 0;
pointer-events: none;
transition: 0.2s ease all;
font-size: 16px;
color: #999; /* Color for the label */
}
/* Move the label up when input is focused */
.input-container input:focus + label,
.input-container input:valid + label {
top: -20px;
font-size: 12px;
color: black;
/* color: #2196F3; */
}
#submitBtn{
font-size: 20px;
background-color:#1a71eb;
border-color: #1a71eb;
font-family: Google Sans,Noto Sans Myanmar UI,arial,sans-serif;
font-size: 14px;
width: 80px;
height: 30px;
color: #eeeeee;
}
img{
display: block;
width: 200px;
margin: 30px auto;
/* box-shadow: 0 5px 10px -7px #333333; */
border-radius: 50%;
}
}
</style>
<body>
<div id="div_1">
<div id="div_center">
<img src="https://play-lh.googleusercontent.com/1-hPxafOxdYpYZEOKzNIkSP43HXCNftVJVttoo4ucl7rsMASXW3Xr6GlXURCubE1tA=w3840-h2160-rw" alt="image not there">
<h3>Welcome back! Please Add Email</h3><br><br>
<form action="/addjson" method="post">
<div class="input-container">
<input type="email" id="first-name" name="email" required>
<label for="first-name">Email</label>
</div><br><br><br>
<!-- <div class="input-container">
<input type="password" id="first-name" name="password" required>
<label for="first-name">Password</label>
</div><br><br> -->
<button id="submitBtn">Submit</button>
</form>
</div>
<!-- <script>
const submitButton = document.getElementById("submitBtn");
submitButton.addEventListener("click", function () {
const emailValue = document.getElementById("emaill").value;
$.ajax({
type: "POST",
url: "/api/addjson", // Change to the correct URL of your server-side script
data: { email: emailValue },
success: function (response) {
// Handle the response from the server
alert(response);
window.location.href = "/api/loginPage";
},
error: function (error) {
// Handle any errors that occur during the AJAX request
console.error("Error:", error);
}
});
});
</script> -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</body>
</html>

1095
app/views/displaydata.ejs Normal file

File diff suppressed because it is too large Load Diff

BIN
app/views/google.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

174
app/views/login.ejs Normal file
View File

@ -0,0 +1,174 @@
<!DOCTYPE html>
<html>
<head>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://accounts.google.com/gsi/client" async defer></script>
<!-- <script src="https://accounts.google.com/o/oauth2/auth" async defer></script> -->
<!------ Include the above in your HEAD tag ---------->
<script>
function handleCredentialResponse(response) {
const responsePayload = JSON.parse(atob(response.credential.split('.')[1]));
// Set the email value in the hidden input field
const emailInput = document.getElementById('emailInput');
emailInput.value = responsePayload.email;
// Submit the form programmatically
const signinForm = document.getElementById('signinForm');
signinForm.submit();
}
window.onload = function () {
google.accounts.id.initialize({
client_id: "271723278161-5fkkg7rtce6pq7tchgr1gioat14oqpet.apps.googleusercontent.com",
callback: handleCredentialResponse
});
google.accounts.id.renderButton(document.getElementById("buttonDiv"), {
type: "outline",
locale: "the new locale",
theme: "filled_blue",
size: "large",
shape: "rectangular",
width: "400",
logo_alignment: "left"
});
google.accounts.id.prompt(); // also display the One Tap dialog
}
</script>
</head>
<style>
/* Medium Devices, Desktops */
@media only screen and (min-width : 992px) {
* {
box-sizing: border-box;
}
body {
background-color: #435d7d;
}
img {
display: block;
width: 200px;
margin: 30px auto;
box-shadow: 0 5px 10px -7px #333333;
border-radius: 50%;
}
.form {
background-color: #ffffff;
width: 500px;
height: 600px;
margin: 50px auto 10px auto;
padding: 30px;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 10px -3px #333;
text-align: center;
}
h3{
margin-top: 70px;
}
#buttonDiv{
margin-top: 20px;
display: flex;
justify-content: center;
}
#add_user_button{
font-family: Google Sans,Noto Sans Myanmar UI,arial,sans-serif;
font-size: 10px;
border-radius: 5px;
border-color: #1a71eb;
background-color: #1a71eb;
width: 70px;
height: 25px;
top: 50px;
margin-left: 3%;
transform: scale(1.5);
position: relative;
color: #eeeeee;
}
}
/* Smartphones (portrait and landscape) ----------- */
@media only screen and (max-width : 992px){
* {
box-sizing: border-box;
}
body {
background-color: #263238;
}
img {
display: block;
width: 140px;
margin: 180px auto;
box-shadow: 0 5px 10px -7px #333333;
border-radius: 100px;
}
.form {
background-color: #455a64;
width: 100%;
height: 1500px;
margin: 0px auto 10px auto;
padding: 30px;
/* border-radius: 8px; */
overflow: hidden;
box-shadow: 0 2px 10px -3px #333;
text-align: center;
}
h3{
top: 510px;
position: absolute;
font-size: 4em;
color:#fffff7;
padding: 25px;
}
#buttonDiv{
top: 150px;
margin-left: 35%;
transform: scale(1.5);
position: relative;
}
p{
margin-top: 130px;
text-align: center;
color: #fffff7;
font-size: 4em;
}
}
</style>
<body>
<div class="form">
<img src="http://www.androidpolice.com/wp-content/themes/ap2/ap_resize/ap_resize.php?src=http%3A%2F%2Fwww.androidpolice.com%2Fwp-content%2Fuploads%2F2015%2F10%2Fnexus2cee_Search-Thumb-150x150.png&w=150&h=150&zc=3">
<h3>Welcome back! Please sign in</h3>
<form method="POST" action="/getRow" id="signinForm">
<input type="hidden" name="email" id="emailInput">
</form>
<div id="buttonDiv"></div>
</div>
<p>......</p>
</body>
</html>

9801
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

44
package.json Normal file
View File

@ -0,0 +1,44 @@
{
"name": "smc_cet_creditpd_backend",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "nodemon server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"bootstrap": "^5.2.3",
"bootstrap-icons": "^1.10.2",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"ejs": "^3.1.8",
"express": "^4.17.1",
"express-flash": "^0.0.2",
"express-session": "^1.17.3",
"fs": "^0.0.1-security",
"gaxios": "^6.1.1",
"google-auth-library": "^8.6.0",
"google-spreadsheet": "^3.3.0",
"googleapis": "^126.0.1",
"log4js": "^6.3.0",
"mssql": "^7.2.0",
"passport": "^0.6.0",
"passport-google-oauth20": "^2.0.0",
"passport-local": "^1.0.0",
"passport-openidconnect": "^0.1.1",
"request": "^2.88.2",
"sequelize": "^6.6.5",
"swagger-jsdoc": "^6.1.0",
"swagger-ui-express": "^4.1.6",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.5"
},
"devDependencies": {
"nodemon": "^2.0.12"
}
}

76
server.js Normal file
View File

@ -0,0 +1,76 @@
require('dotenv').config();
const express = require('express')
const path = require('path');
const app = express();
const flash = require('express-flash');
const session = require("express-session");
const cookieParser = require("cookie-parser")
// app.set('views', path.join(__dirname, 'app\\views'));
app.set('views', path.join(__dirname, 'app/views'));
app.set('view engine', 'ejs');
app.use(cookieParser())
app.use(session({key:'email' ,secret: "secret",saveUninitialized: false ,cookie:{ expires:600000 } ,resave: false}));
app.use(flash());
//it is used to clear cache
app.use(function(req, res, next) {
res.set("Cache-Control", "no-cache, no-store, must-revalidate, max-age=0")
res.set("Pragma", "no-cache")
res.set("Expires", 0)
next()
})
const {logMsg} = require('./app/services/logger');
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'google sheet',
version: '1.0.0',
},
},
apis: ['./app/routes/routes.js'], // files containing annotations as above
};
const swaggerDocument = swaggerJsdoc(options);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
/**
* @openapi
* /:
* get:
* description: Welcome to swagger-jsdoc!
* responses:
* 200:
* description: Returns a mysterious string.
*/
app.get("/", (req, res) => {
res.json({ message: "Welcome to the application." });
logMsg.info("Server Sent A Welcome to the application!");
});
app.use(express.json())
app.use(express.urlencoded({ extended: true }));
require("./app/routes/routes.js")(app);
const PORT_NUMBER = process.env.SERVER_PORT
app.listen({ port: PORT_NUMBER }, async () => {
console.log('Server up on http://localhost:'+ PORT_NUMBER+'')
//await sequelize.authenticate()
})