commit
4de1f04c96
|
@ -220,37 +220,54 @@ module.exports.verfiyemail = async (req, res, next) => {
|
|||
module.exports.postSignin = async (req, res, next) => {
|
||||
try {
|
||||
//we need email and password as input
|
||||
let email = req.body.email;
|
||||
let password = req.body.password;
|
||||
let { email, password, isGoogle } = req.body;
|
||||
let user = await User.findOne({ email: email });
|
||||
if (user) {
|
||||
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;
|
||||
}
|
||||
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.status(403).json({
|
||||
message: "User Not Verified!",
|
||||
res.json({
|
||||
message: "email and password doesn't match",
|
||||
type: "error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
res.status(201).json({
|
||||
message: "No user with this email exists",
|
||||
type: "error",
|
||||
});
|
||||
return;
|
||||
if (user) {
|
||||
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.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) {
|
||||
console.log(err);
|
||||
|
@ -278,30 +295,36 @@ module.exports.postSignin = async (req, res, next) => {
|
|||
// Phone verification Starts.
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
module.exports.sendOTP = (req, res, next) => {
|
||||
module.exports.sendOTP = async (req, res, next) => {
|
||||
//uNNYosMopvvCW9RTR1tRWJmYC test
|
||||
//llVKD53ve6QRpbCKOHzWBADaS live
|
||||
const { phoneNumber } = req.body;
|
||||
const { phoneNumber, _id } = req.body;
|
||||
try {
|
||||
if (!phoneNumber) {
|
||||
res.status(422).json({ message: "Please Add All Required Fields" });
|
||||
return;
|
||||
} else {
|
||||
messagebird.verify.create(
|
||||
phoneNumber,
|
||||
{
|
||||
template: "Your verification code is %token",
|
||||
},
|
||||
function (err, response) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
res.status(422).json({ message: err.errors[0].description });
|
||||
} else {
|
||||
console.log(response);
|
||||
res.json({ id: response.id });
|
||||
let user = await User.findOne({ _id });
|
||||
if (user) {
|
||||
if (!phoneNumber) {
|
||||
res.status(422).json({ message: "Please Add All Required Fields" });
|
||||
return;
|
||||
} else {
|
||||
messagebird.verify.create(
|
||||
phoneNumber,
|
||||
{
|
||||
template: "Your verification code is %token",
|
||||
},
|
||||
function (err, response) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
res.status(422).json({ message: err.errors[0].description });
|
||||
} else {
|
||||
console.log(response);
|
||||
res.json({ id: response.id });
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
} else {
|
||||
res.status(422).json({ error: "User Doesn't Exists!" });
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
|
Loading…
Reference in New Issue