Skip to content

Commit

Permalink
Set as minted function for EthVJTI Minter (#227)
Browse files Browse the repository at this point in the history
* for rebuilding

* allow all origins

* test api

* set minted function added for ethvjti minter
  • Loading branch information
Ravi Maurya authored Apr 8, 2023
1 parent d152d8f commit 265ea68
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
10 changes: 7 additions & 3 deletions server/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var corsOptions = {
};

if (process.env.NODE_ENV === "production") {
corsOptions.origin = "https://communityofcoders.in";
// corsOptions.origin = "https://communityofcoders.in";
corsOptions.origin = "*";
}

app.use(cors(corsOptions));
Expand All @@ -34,8 +35,11 @@ routes(app);

dbconnect(rescheduler.reschedule);

app.use(compression());
app.use(express.static(path.join(__dirname, "../../new_client/build")));
app.get("/ethvjti", (req, res) => {
res.send({"ok": "ok"});
});

app.use(express.static(path.resolve(__dirname, "../../new_client/build")));

app.get("/*", (req, res) => {
res.sendFile(path.join(__dirname, "../../new_client/build/index.html"));
Expand Down
28 changes: 24 additions & 4 deletions server/src/controllers/EthVJTIController.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ const sendOTP = async (req, res) => {
const { email, walletAddress } = req.body;
const newOTP = generateOTP();

sendMailToSingerUser(newOTP, email);

const userDetails = {
email,
walletAddress,
Expand All @@ -41,6 +39,7 @@ const sendOTP = async (req, res) => {
if(userCheck.isMinted){
return res.status(400).json({ error: "NFT is already minted for this user" });
}
sendMailToSingerUser(newOTP, email);
newUser = await EthUser.findByIdAndUpdate(
userCheck._id,
userDetails,
Expand Down Expand Up @@ -70,7 +69,8 @@ const verifyOTP = async (req, res) => {
})
.lean();
if(userCheck && userCheck.emailVerificationOTP == otp){
await EthUser.findByIdAndUpdate(userCheck._id, {isMinted: true, emailVerificationOTP: ""});
// await EthUser.findByIdAndUpdate(userCheck._id, {isMinted: true, emailVerificationOTP: ""});
await EthUser.findByIdAndUpdate(userCheck._id, {emailVerificationOTP: ""});
return res.status(200).json({ message: "OTP Correct", email: email });
}
return res.status(400).json({ error: "OTP not valid" });
Expand All @@ -79,7 +79,27 @@ const verifyOTP = async (req, res) => {
}
};

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

const userCheck = await EthUser.findOne({
email: email,
})
.lean();
if(userCheck){
await EthUser.findByIdAndUpdate(userCheck._id, {isMinted: true, emailVerificationOTP: ""});
return res.status(200).json({ message: "User set as minted", email: email });
}
return res.status(400).json({ error: "Email not found" });
} catch (error) {
return res.status(400).json({ error: error.message });
}
};


module.exports = {
sendOTP,
verifyOTP
verifyOTP,
setMinted
}
1 change: 1 addition & 0 deletions server/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ module.exports = (app) => {
// EthVJTI
app.post('/api/ethvjti/sendotp', EthVJTIController.sendOTP);
app.get('/api/ethvjti/verifyotp', EthVJTIController.verifyOTP);
app.get('/api/ethvjti/setminted', EthVJTIController.setMinted);

}

0 comments on commit 265ea68

Please sign in to comment.