diff --git a/controllers/auth.js b/controllers/auth.js
index 07a4a01..633fe4c 100644
--- a/controllers/auth.js
+++ b/controllers/auth.js
@@ -53,7 +53,7 @@ module.exports.postSignup = async (req, res, next) => {
email: email,
password: hashedPass,
isAdmin: false,
- // email_otp,
+ email_otp,
});
user = await user.save();
await Student.deleteOne({ user: user._id });
@@ -63,21 +63,115 @@ module.exports.postSignup = async (req, res, next) => {
student = await student.save();
user.student = student._id;
await user.save();
- // const message = {
- // from: `${sending_company_email}`, // Sender address
- // to: `${email}`, // List of recipients
- // subject: `${subject}`, // Subject line
- // html: '', // design html for email message.
- // };
- // transport.sendMail(message, function (err, info) {
- // if (err) {
- // console.log(err);
- // } else {
- // console.log(info);
- // }
- // });
+ const message = {
+ from: `${sending_company_email}`, // Sender address
+ to: `${email}`, // List of recipients
+ subject: `${subject}`, // Subject line
+ html: `
+
+
+
+
+
+ Verify Email Template
+
+
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+ |
+
+
+
+
+ |
+
+ |
+
+
+
+
+ 
+ copyright 2018 Cantilever Labs
+
+ |
+
+
+
+ |
+
+
+ |
+
+
+
+
+
+ `, // design html for email message.
+ };
+ transport.sendMail(message, function (err, info) {
+ if (err) {
+ console.log(err);
+ } else {
+ console.log(info);
+ }
+ });
res.json({
- message: "You Are Registered, Please Login",
+ message: "Email with 6 Digit OTP has been sent.",
type: "success",
});
}
@@ -130,23 +224,33 @@ module.exports.postSignin = async (req, res, next) => {
let password = req.body.password;
let user = await User.findOne({ email: email });
if (user) {
- const isMatched = await bcrypt.compare(password, user.password);
- if (isMatched) {
- const token = jwt.sign({ _id: user._id }, JWT_secret);
- res.json({
- token: token,
- });
+ if (user.isVerified) {
+ const isMatched = await bcrypt.compare(password, user.password);
+ if (isMatched) {
+ const token = jwt.sign({ _id: user._id }, JWT_secret);
+ res.json({
+ token: token,
+ });
+ } else {
+ res.json({
+ message: "email and password doesn't match",
+ type: "error",
+ });
+ return;
+ }
} else {
- res.json({
- message: "email and password doesn't match",
+ res.status(403).json({
+ message: "User Not Verified!",
type: "error",
});
+ return;
}
} else {
- res.json({
+ res.status(201).json({
message: "No user with this email exists",
type: "error",
});
+ return;
}
} catch (err) {
console.log(err);
diff --git a/routes/auth.js b/routes/auth.js
index ecaaff0..57951e9 100644
--- a/routes/auth.js
+++ b/routes/auth.js
@@ -19,6 +19,6 @@ router.post("/resetpassword/:_id/:token", authController.resetpassword);
// router.post("/googleSignIn/:tokenId", authController.googleSignIn);
-// router.post("/verifyemail", authController.verfiyemail);
+router.post("/verifyemail", authController.verfiyemail);
module.exports = router;