diff --git a/.github/workflows/ssh-deploy.yml b/.github/workflows/ssh-deploy.yml index b60c98a..6e069f5 100644 --- a/.github/workflows/ssh-deploy.yml +++ b/.github/workflows/ssh-deploy.yml @@ -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: @@ -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 }} diff --git a/server/src/controllers/EthVJTIController.js b/server/src/controllers/EthVJTIController.js new file mode 100644 index 0000000..428e129 --- /dev/null +++ b/server/src/controllers/EthVJTIController.js @@ -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 +} \ No newline at end of file diff --git a/server/src/models/EthVJTIWallet.js b/server/src/models/EthVJTIWallet.js new file mode 100644 index 0000000..f8ea325 --- /dev/null +++ b/server/src/models/EthVJTIWallet.js @@ -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; diff --git a/server/src/routes.js b/server/src/routes.js index 432a32a..cec1738 100644 --- a/server/src/routes.js +++ b/server/src/routes.js @@ -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"); @@ -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); + } +