Skip to content

Commit 265ea68

Browse files
author
Ravi Maurya
authored
Set as minted function for EthVJTI Minter (#227)
* for rebuilding * allow all origins * test api * set minted function added for ethvjti minter
1 parent d152d8f commit 265ea68

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

server/src/app.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ var corsOptions = {
1919
};
2020

2121
if (process.env.NODE_ENV === "production") {
22-
corsOptions.origin = "https://communityofcoders.in";
22+
// corsOptions.origin = "https://communityofcoders.in";
23+
corsOptions.origin = "*";
2324
}
2425

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

3536
dbconnect(rescheduler.reschedule);
3637

37-
app.use(compression());
38-
app.use(express.static(path.join(__dirname, "../../new_client/build")));
38+
app.get("/ethvjti", (req, res) => {
39+
res.send({"ok": "ok"});
40+
});
41+
42+
app.use(express.static(path.resolve(__dirname, "../../new_client/build")));
3943

4044
app.get("/*", (req, res) => {
4145
res.sendFile(path.join(__dirname, "../../new_client/build/index.html"));

server/src/controllers/EthVJTIController.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ const sendOTP = async (req, res) => {
2222
const { email, walletAddress } = req.body;
2323
const newOTP = generateOTP();
2424

25-
sendMailToSingerUser(newOTP, email);
26-
2725
const userDetails = {
2826
email,
2927
walletAddress,
@@ -41,6 +39,7 @@ const sendOTP = async (req, res) => {
4139
if(userCheck.isMinted){
4240
return res.status(400).json({ error: "NFT is already minted for this user" });
4341
}
42+
sendMailToSingerUser(newOTP, email);
4443
newUser = await EthUser.findByIdAndUpdate(
4544
userCheck._id,
4645
userDetails,
@@ -70,7 +69,8 @@ const verifyOTP = async (req, res) => {
7069
})
7170
.lean();
7271
if(userCheck && userCheck.emailVerificationOTP == otp){
73-
await EthUser.findByIdAndUpdate(userCheck._id, {isMinted: true, emailVerificationOTP: ""});
72+
// await EthUser.findByIdAndUpdate(userCheck._id, {isMinted: true, emailVerificationOTP: ""});
73+
await EthUser.findByIdAndUpdate(userCheck._id, {emailVerificationOTP: ""});
7474
return res.status(200).json({ message: "OTP Correct", email: email });
7575
}
7676
return res.status(400).json({ error: "OTP not valid" });
@@ -79,7 +79,27 @@ const verifyOTP = async (req, res) => {
7979
}
8080
};
8181

82+
const setMinted = async (req, res) => {
83+
try {
84+
const { email, walletAddress } = req.body;
85+
86+
const userCheck = await EthUser.findOne({
87+
email: email,
88+
})
89+
.lean();
90+
if(userCheck){
91+
await EthUser.findByIdAndUpdate(userCheck._id, {isMinted: true, emailVerificationOTP: ""});
92+
return res.status(200).json({ message: "User set as minted", email: email });
93+
}
94+
return res.status(400).json({ error: "Email not found" });
95+
} catch (error) {
96+
return res.status(400).json({ error: error.message });
97+
}
98+
};
99+
100+
82101
module.exports = {
83102
sendOTP,
84-
verifyOTP
103+
verifyOTP,
104+
setMinted
85105
}

server/src/routes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ module.exports = (app) => {
324324
// EthVJTI
325325
app.post('/api/ethvjti/sendotp', EthVJTIController.sendOTP);
326326
app.get('/api/ethvjti/verifyotp', EthVJTIController.verifyOTP);
327+
app.get('/api/ethvjti/setminted', EthVJTIController.setMinted);
327328

328329
}
329330

0 commit comments

Comments
 (0)