Skip to content

Commit

Permalink
EthVJTI Apis (#223)
Browse files Browse the repository at this point in the history
* Update ssh-deploy.yml

* Update ssh-deploy.yml

* ethvjti apis (#222)

---------

Co-authored-by: Shubhankar Kanchan Gupta <shubhankar.gupto.11@gmail.com>
  • Loading branch information
Ravi Maurya and ShubhankarKG authored Apr 7, 2023
1 parent 3fa059d commit f624922
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/workflows/ssh-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Deploy via SSH
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'debug'
workflow_run:
workflows: ["Build and Release"]
types:
Expand All @@ -9,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Deploying
uses: appleboy/ssh-action@master
uses: appleboy/ssh-action@v0.1.4
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
Expand Down
84 changes: 84 additions & 0 deletions server/src/controllers/EthVJTIController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const EthUser = require("../models/EthVJTIWallet");
const sendEmail = require("../utility/sendEmail");

const generateOTP = () => {
var digits = "0123456789";
let OTP = "";
for (let i = 0; i < 4; i++) {
OTP += digits[Math.floor(Math.random() * 10)];
}
return OTP;
};

const sendMailToSingerUser = async (otp, email) => {
const mailSubject = "EthVJTI Launch NFT One Time Password";
const mailData = `Your OTP for EthVJTI Launch NFT is: ${otp}`;
await sendEmail(email, mailSubject, mailData);
};

const sendOTP = async (req, res) => {
try {
const { email, walletAddress } = req.body;
const newOTP = generateOTP();

sendMailToSingerUser(newOTP, email);

const userDetails = {
email,
walletAddress,
isMinted: false,
emailVerificationOTP: newOTP,
};

const userCheck = await EthUser.findOne({
email: email,
})
.lean();

let newUser;
if(userCheck){
if(userCheck.isMinted){
return res.status(400).json({ error: "NFT is already minted for this user" });
}
newUser = await EthUser.findByIdAndUpdate(
userCheck._id,
userDetails,
{new: true}
);
}else{
res.status(404).json({error: "Email ID was not registered"});
}

return res
.status(200)
.json({
message: `OTP Sent to ${email}`,
user: newUser,
});
} catch (error) {
return res.status(400).json({ error: error.message });
}
};

const verifyOTP = async (req, res) => {
try {
const { email, otp } = req.body;

const userCheck = await EthUser.findOne({
email: email,
})
.lean();
if(userCheck && userCheck.emailVerificationOTP == otp){
await EthUser.findByIdAndUpdate(userCheck._id, {isMinted: true, emailVerificationOTP: ""});
return res.status(200).json({ message: "OTP Correct", email: email });
}
return res.status(400).json({ error: "OTP not valid" });
} catch (error) {
return res.status(400).json({ error: error.message });
}
};

module.exports = {
sendOTP,
verifyOTP
}
27 changes: 27 additions & 0 deletions server/src/models/EthVJTIWallet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const mongoose = require('mongoose')

const ethuser = new mongoose.Schema({
email: {
type: String,
required: true
},
walletAddress: {
type: String,
required: false
},
isMinted: {
type: Boolean,
required: false,
default: false,
},
emailVerificationOTP: {
type: String,
required: false
}
})

ethuser.index({ email: 1 })

const EthUser = mongoose.model('ethuser', ethuser)

module.exports = EthUser;
7 changes: 7 additions & 0 deletions server/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const AchievementsController = require("./controllers/AchievementsController");
const MagazineController = require("./controllers/MagazineController");
const CompanyController = require("./controllers/CompanyController");
const InterviewController = require("./controllers/InterviewController");
const EthVJTIController = require("./controllers/EthVJTIController");
const upload = require("./middleware/upload");
const auth = require("./middleware/auth");
const blog = require("./middleware/blog");
Expand Down Expand Up @@ -319,4 +320,10 @@ module.exports = (app) => {
app.post('/api/interview/draft', auth.verifyToken, InterviewController.saveDraftInterview, cache.deleteCache);
app.post('/api/interview/verify', auth.verifyToken, user.isMember, InterviewController.verifyInterview, cache.deleteCache);
app.post('/api/interviewImageUpload', auth.verifyToken, upload.single('expImage'), InterviewController.uploadImage, cache.deleteCache);

// EthVJTI
app.post('/api/ethvjti/sendotp', EthVJTIController.sendOTP);
app.get('/api/ethvjti/verifyotp', EthVJTIController.verifyOTP);

}

0 comments on commit f624922

Please sign in to comment.