forked from athithyaramaa1/CN-Website-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
210 lines (184 loc) · 7.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
const express = require('express');
const { createClient } = require('@supabase/supabase-js');
const dotenv = require('dotenv');
const cors = require('cors');
dotenv.config();
const app = express();
const port = process.env.PORT || 3000;
const MAX_TEAMS = 25;
const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_ANON_KEY
);
app.use(cors());
app.use(express.json());
// Get all problem statements
app.get('/api/problems', async (req, res) => {
try {
const { data, error } = await supabase
.from('problem_statements')
.select('*')
.order('title');
if (error) throw error;
res.status(200).json({
success: true,
data
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
// Check registration availability
app.get('/api/registration-status', async (req, res) => {
try {
const { count, error } = await supabase
.from('team_registrations')
.select('*', { count: 'exact' });
if (error) throw error;
res.status(200).json({
success: true,
isOpen: count < MAX_TEAMS,
remainingSlots: MAX_TEAMS - count
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
});
// Register a team
app.post('/api/register', async (req, res) => {
const client = await supabase.rest.connection();
try {
await client.transaction(async (tx) => {
// Check if registration is still open
const { count: teamCount } = await tx
.from('team_registrations')
.select('*', { count: 'exact' });
if (teamCount >= MAX_TEAMS) {
throw new Error('Registration closed: Maximum teams reached');
}
const { teamData, problemStatementId } = req.body;
// Check if problem statement is available
const { data: problem, error: problemError } = await tx
.from('problem_statements')
.select('teams_assigned')
.eq('id', problemStatementId)
.single();
if (problemError) throw problemError;
if (problem.teams_assigned >= 3) {
throw new Error('Problem statement no longer available');
}
// Update problem statement count
const { error: updateError } = await tx
.from('problem_statements')
.update({ teams_assigned: problem.teams_assigned + 1 })
.eq('id', problemStatementId);
if (updateError) throw updateError;
// Register team
const { data, error } = await tx
.from('team_registrations')
.insert([{ ...teamData, problem_statement_id: problemStatementId }]);
if (error) throw error;
res.status(200).json({
success: true,
message: 'Registration successful',
data
});
});
} catch (error) {
res.status(500).json({
success: false,
message: 'Registration failed',
error: error.message
});
}
});
// Initialize problem statements (run once)
// app.get('/api/init-problems', async (req, res) => {
// try {
// const problemStatements = [
// {
// title: "Zero-Day Vulnerability Detection System",
// description: "Design a system to detect and analyze potential zero-day vulnerabilities in web applications."
// },
// {
// title: "Blockchain Security Monitor",
// description: "Develop a monitoring system for detecting suspicious transactions and smart contract vulnerabilities."
// },
// {
// title: "IoT Device Security Framework",
// description: "Create a security framework for protecting IoT devices from common vulnerabilities and attacks."
// },
// {
// title: "Network Intrusion Detection System",
// description: "Build an AI-powered system to detect and prevent network intrusions in real-time."
// },
// {
// title: "Secure Password Manager",
// description: "Develop a secure password management system with encryption and multi-factor authentication."
// },
// {
// title: "Mobile App Security Scanner",
// description: "Create a tool to scan mobile applications for security vulnerabilities and privacy issues."
// },
// {
// title: "Secure File Sharing System",
// description: "Build an end-to-end encrypted file sharing system with access control mechanisms."
// },
// {
// title: "Web Application Firewall",
// description: "Design a WAF to protect web applications from common attacks like XSS and SQL injection."
// },
// {
// title: "Security Awareness Training Platform",
// description: "Develop an interactive platform to train users about cybersecurity best practices."
// },
// {
// title: "Malware Analysis Toolkit",
// description: "Create tools for analyzing and understanding malware behavior in a safe environment."
// },
// {
// title: "Cloud Security Monitor",
// description: "Build a system to monitor and protect cloud infrastructure from security threats."
// },
// {
// title: "Secure Communication Protocol",
// description: "Design a secure protocol for encrypted communication between distributed systems."
// },
// {
// title: "Access Control System",
// description: "Develop a role-based access control system with audit logging capabilities."
// },
// {
// title: "Security Incident Response Platform",
// description: "Create a platform to manage and coordinate responses to security incidents."
// },
// {
// title: "Vulnerability Assessment Tool",
// description: "Build an automated tool for identifying and reporting security vulnerabilities."
// }
// ];
// const { data, error } = await supabase
// .from('problem_statements')
// .insert(problemStatements);
// if (error) throw error;
// res.status(200).json({
// success: true,
// message: 'Problem statements initialized',
// data
// });
// } catch (error) {
// res.status(500).json({
// success: false,
// error: error.message
// });
// }
// });
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});