-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
tem1 #55
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Module dependencies. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 { | ||
sendVerificationMail | ||
} = require('../tools/sendEmails'); | ||
|
||
const router = express.Router(); | ||
const debug = require('debug')('backend:server:index.js'); | ||
const { | ||
|
@@ -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; | ||
|
@@ -256,12 +264,13 @@ router.post('/register', | |
errors: results.array() | ||
}); | ||
} else { | ||
const verificationID = nanoid(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -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 => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -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"))); | ||
|
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
|
@@ -16,6 +17,21 @@ router.all('/test', function (_req, res) { | |
debug("into /test"); | ||
res.send("TEST SUCCESS"); | ||
}); | ||
router.get('/verify', (req, res) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing semicolon. |
||
} else { | ||
res.send("<h1>INVALID Verification</h1>"); | ||
} | ||
}) | ||
.catch((err) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
}); | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"))) | ||
|
There was a problem hiding this comment.
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).