Google isVerified
This commit is contained in:
parent
7d14f3c3a5
commit
db6f4210e6
|
@ -220,37 +220,54 @@ 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 (user) {
|
if (isGoogle) {
|
||||||
if (user.isVerified) {
|
user.isVerified = true;
|
||||||
const isMatched = await bcrypt.compare(password, user.password);
|
user = await user.save();
|
||||||
if (isMatched) {
|
const isMatched = await bcrypt.compare(password, user.password);
|
||||||
const token = jwt.sign({ _id: user._id }, JWT_secret);
|
if (isMatched) {
|
||||||
res.json({
|
const token = jwt.sign({ _id: user._id }, JWT_secret);
|
||||||
token: token,
|
res.json({
|
||||||
});
|
token: token,
|
||||||
} else {
|
});
|
||||||
res.json({
|
|
||||||
message: "email and password doesn't match",
|
|
||||||
type: "error",
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
res.status(403).json({
|
res.json({
|
||||||
message: "User Not Verified!",
|
message: "email and password doesn't match",
|
||||||
type: "error",
|
type: "error",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
res.status(201).json({
|
if (user) {
|
||||||
message: "No user with this email exists",
|
if (user.isVerified) {
|
||||||
type: "error",
|
const isMatched = await bcrypt.compare(password, user.password);
|
||||||
});
|
if (isMatched) {
|
||||||
return;
|
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.status(403).json({
|
||||||
|
message: "User Not Verified!",
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res.status(201).json({
|
||||||
|
message: "No user with this email exists",
|
||||||
|
type: "error",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
@ -278,30 +295,36 @@ 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 {
|
||||||
if (!phoneNumber) {
|
let user = await User.findOne({ _id });
|
||||||
res.status(422).json({ message: "Please Add All Required Fields" });
|
if (user) {
|
||||||
return;
|
if (!phoneNumber) {
|
||||||
} else {
|
res.status(422).json({ message: "Please Add All Required Fields" });
|
||||||
messagebird.verify.create(
|
return;
|
||||||
phoneNumber,
|
} else {
|
||||||
{
|
messagebird.verify.create(
|
||||||
template: "Your verification code is %token",
|
phoneNumber,
|
||||||
},
|
{
|
||||||
function (err, response) {
|
template: "Your verification code is %token",
|
||||||
if (err) {
|
},
|
||||||
console.log(err);
|
function (err, response) {
|
||||||
res.status(422).json({ message: err.errors[0].description });
|
if (err) {
|
||||||
} else {
|
console.log(err);
|
||||||
console.log(response);
|
res.status(422).json({ message: err.errors[0].description });
|
||||||
res.json({ id: response.id });
|
} else {
|
||||||
|
console.log(response);
|
||||||
|
res.json({ id: response.id });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
}
|
||||||
|
} else {
|
||||||
|
res.status(422).json({ error: "User Doesn't Exists!" });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
|
Loading…
Reference in New Issue