Merge pull request #3 from yashrajverma/main

Google isVerified
This commit is contained in:
yashraj verma 2021-05-29 14:45:15 +05:30 committed by GitHub
commit 4de1f04c96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 67 additions and 44 deletions

View File

@ -220,9 +220,25 @@ module.exports.verfiyemail = async (req, res, next) => {
module.exports.postSignin = async (req, res, next) => { module.exports.postSignin = async (req, res, next) => {
try { try {
//we need email and password as input //we need email and password as input
let email = req.body.email; let { email, password, isGoogle } = req.body;
let password = req.body.password;
let user = await User.findOne({ email: email }); let user = await User.findOne({ email: email });
if (isGoogle) {
user.isVerified = true;
user = await user.save();
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 {
if (user) { if (user) {
if (user.isVerified) { if (user.isVerified) {
const isMatched = await bcrypt.compare(password, user.password); const isMatched = await bcrypt.compare(password, user.password);
@ -252,6 +268,7 @@ module.exports.postSignin = async (req, res, next) => {
}); });
return; return;
} }
}
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
@ -278,11 +295,13 @@ module.exports.postSignin = async (req, res, next) => {
// Phone verification Starts. // Phone verification Starts.
// ----------------------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------------------
module.exports.sendOTP = (req, res, next) => { module.exports.sendOTP = async (req, res, next) => {
//uNNYosMopvvCW9RTR1tRWJmYC test //uNNYosMopvvCW9RTR1tRWJmYC test
//llVKD53ve6QRpbCKOHzWBADaS live //llVKD53ve6QRpbCKOHzWBADaS live
const { phoneNumber } = req.body; const { phoneNumber, _id } = req.body;
try { try {
let user = await User.findOne({ _id });
if (user) {
if (!phoneNumber) { if (!phoneNumber) {
res.status(422).json({ message: "Please Add All Required Fields" }); res.status(422).json({ message: "Please Add All Required Fields" });
return; return;
@ -303,6 +322,10 @@ module.exports.sendOTP = (req, res, next) => {
} }
); );
} }
} else {
res.status(422).json({ error: "User Doesn't Exists!" });
return;
}
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }