Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tem1 #55

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

tem1 #55

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ try {
},async function (email, givenPassword, done) {
debug("LINE 20");
debug(email, givenPassword);
return pool.query('Select id, password, name, uType, isActive, isVerified, verificationLink from user where email = ?;', [email])
return pool.query('Select id, password, name, uType, isActive, isVerified, verificationCode from user where email = ?;', [email])
.then(results => {
if (results[0].length > 0) {
const {
Expand Down
1 change: 0 additions & 1 deletion bin/www
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node

/**
* Module dependencies.
Expand Down
70 changes: 66 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"ip": "node ip.test.js"
},
"dependencies": {
"@sendgrid/mail": "^7.4.0",
"bcrypt": "^5.0.0",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
Expand All @@ -27,6 +28,7 @@
"helmet": "^4.2.0",
"morgan": "^1.9.1",
"mysql2": "^2.2.5",
"nanoid": "^3.1.20",
"passport": "^0.4.1",
"passport-local": "^1.0.0",
"validator-pizza-node": "^1.0.3"
Expand Down
51 changes: 35 additions & 16 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
const express = require('express');
const path = require('path');
const {
nanoid
} = require('nanoid');
// const bcrypt = require('bcrypt');
const {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
'destructuring binding' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

sendVerificationMail
} = require('../tools/sendEmails');

const router = express.Router();
const debug = require('debug')('backend:server:index.js');
const {
Expand Down Expand Up @@ -54,7 +62,7 @@ router.get("/login", function (req, res, next) {
});

router.post("/login", (req, res, next) => {
if(req.isAuthenticated()) {
if (req.isAuthenticated()) {
debug("Is Authenticated");
res.redirect(301, "/users/student");
return;
Expand Down Expand Up @@ -256,12 +264,13 @@ router.post('/register',
errors: results.array()
});
} else {
const verificationID = nanoid();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

// console.table([{
// ...req.body
// }]);

// debug("Received at /register");
req.db.query("CALL Reg(?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", [req.body.email, req.body.password, req.body.fullname, req.body.mobile, req.body.address, req.body.city, req.body.country, req.body.postcode, req.body.institute_name, req.body.photo])
req.db.query("CALL Reg(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", [req.body.email, req.body.password, req.body.fullname, req.body.mobile, req.body.address, req.body.city, req.body.country, req.body.postcode, req.body.institute_name, req.body.photo, verificationID])
.then((...results) => {
const data = results[0][0][0];
console.log(...results);
Expand All @@ -273,8 +282,16 @@ router.post('/register',
}]);
// res.json(req.body);
// res.redirect("/registrationSuccess")
debug("Response Sent successfully");
res.send("Registration Successful");
// debug("Response Sent successfully");
// res.send("Registration Successful");

return sendVerificationMail(req.body.email, verificationID);
})
.then(results => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

if (results[0].statusCode == 202) {
debug("sent code: " + verificationID);
res.send("<h1>SUCCESSFULLY REGISTERED Please verify from your mail</h1>");
} else throw results;
})
.catch((err) => {
debug(err);
Expand Down Expand Up @@ -327,20 +344,22 @@ router.post("/uploadImage", (req, res) => {
})

router.get('/companyQuizs', (req, res) => {
const { companyId } = req.query;
const {
companyId
} = req.query;
// res.send(companyId);
req.db.query('select q.id, q.quiz_id, q.quiz_time from quiz_list q join company c on q.company_id = c.id where q.company_id = ? and c.active = true and q.isActive = true;', [companyId])
.then((results) => {
if (results[0].length >= 1) {
res.send(results[0]);
} else if (results[0].length === 0) {
res.send("No Quiz");
}
})
.catch((err) => {
console.log(err);
res.status(500).send(err);
});
.then((results) => {
if (results[0].length >= 1) {
res.send(results[0]);
} else if (results[0].length === 0) {
res.send("No Quiz");
}
})
.catch((err) => {
console.log(err);
res.status(500).send(err);
});
});

router.use("/images", express.static(path.join(__dirname, "..", "custom-images")));
Expand Down
2 changes: 1 addition & 1 deletion routes/student.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ router.get('/fetchQuiz/:id/:quizId', (req, res) => {
});

// res.send({id, quizId});
})
});

router.use(express.static(path.join(__dirname, "..", "public", "student")));
module.exports = router;
16 changes: 16 additions & 0 deletions routes/users.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express');
const path = require('path');
const mysql = require('mysql2');
const bcrypt = require('bcrypt');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).


const router = express.Router();
const debug = require('debug')('backend:server:index.js');
Expand All @@ -16,6 +17,21 @@ router.all('/test', function (_req, res) {
debug("into /test");
res.send("TEST SUCCESS");
});
router.get('/verify', (req, res) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

const verificationID = req.query.code;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

const email = req.query.refs;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).

req.db.query('update user set isVerified = TRUE, verificationCode = NULL where verificationCode = ?;', [verificationID])
.then((results) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

if(results[0].changedRows===1) {
res.send("<h1>SUCCESSFULLY Verified</h1>")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.

} else {
res.send("<h1>INVALID Verification</h1>");
}
})
.catch((err) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

console.log(err);
});
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.


router.use("/assets", express.static(path.join(__dirname, "..", "public", "assets")));
router.use("/admin", express.static(path.join(__dirname, "..", "public", "admin")))
Expand Down
File renamed without changes.
Loading