Skip to content

Commit

Permalink
Merge pull request #495 from AKSHITHA-CHILUKA/patch-8
Browse files Browse the repository at this point in the history
Update otpController.js
  • Loading branch information
hustlerZzZ authored Aug 7, 2024
2 parents 6886309 + b243cde commit f385a21
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions server/controllers/otpController.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const OTP = require("../models/otp-model.js");
const OTP = require("../models/otp-model");
const User = require("../models/studentLoginInfo");
const otpGenerator = require("otp-generator");
const { sendMail } = require("../utils/Mailer.js");
const {
forgotPasswordToken,
verifyToken,
findUserByEmail,
findUserById,
} = require("../utils/PasswordTokenAndUser.js");
const { sendMail } = require("../utils/Mailer");
const { findUserByEmail, forgotPasswordToken } = require("../utils/PasswordTokenAndUser");
// Function to generate OTP
const generateOTP = () => {
return otpGenerator.generate(6, {
upperCaseAlphabets: false,
lowerCaseAlphabets: false,
specialChars: false,
});
};
// Function to send OTP
const sendOTP = async (req, res) => {
try {
const { email } = req.body;
Expand All @@ -24,18 +28,10 @@ const sendOTP = async (req, res) => {
message: "No user with the given email is registered!",
});
}
let otp = otpGenerator.generate(6, {
upperCaseAlphabets: false,
lowerCaseAlphabets: false,
specialChars: false,
});
let otp = generateOTP();
let result = await OTP.findOne({ otp });
while (result) {
otp = otpGenerator.generate(6, {
upperCaseAlphabets: false,
lowerCaseAlphabets: false,
specialChars: false,
});
otp = generateOTP();
result = await OTP.findOne({ otp });
}
const otpSent = await OTP.create({
Expand Down Expand Up @@ -70,6 +66,7 @@ const sendOTP = async (req, res) => {
});
}
};
// Function to verify OTP
const verifyOTP = async (req, res) => {
try {
const { email, otp } = req.body;
Expand Down

0 comments on commit f385a21

Please sign in to comment.