-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
133 lines (122 loc) · 5.07 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href='https://unpkg.com/[email protected]/css/boxicons.min.css' rel='stylesheet'>
<link rel="stylesheet" href="style2.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
<title>B.Y.T.E. | Login & Registration</title>
</head>
<body>
<!-- Navigation and Forms as you provided -->
<!-- Poem Publishing Section -->
<div class="poem-publish" id="poemPublishSection" style="display: none;">
<h2>Publish Your Poem</h2>
<form id="poemForm">
<div class="input-field">
<label for="poemTitle">Poem Title</label>
<input type="text" name="poemTitle" id="poemTitle" placeholder="Enter title">
</div>
<div class="input-field">
<label for="poemContent">Poem Content</label>
<textarea name="poemContent" id="poemContent" placeholder="Write your poem"></textarea>
</div>
<div class="input-field">
<input type="submit" value="Publish Poem">
</div>
</form>
</div>
<script>
function myMenuFunction() {
// Menu Toggle
}
// Login and registration script
document.addEventListener('DOMContentLoaded', function () {
const registerForm = document.getElementById('registrationForm');
registerForm.addEventListener('submit', function (event) {
event.preventDefault();
const userData = {
firstname: document.getElementById('firstname').value,
lastname: document.getElementById('lastname').value,
email: document.getElementById('email').value,
password: document.getElementById('password').value,
};
fetch('http://panel.mait.ac.in:8001/auth/register/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(userData),
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Registration Successful');
window.location.href = "index.html";
} else {
alert('Registration failed');
}
})
.catch(error => {
alert('Registration failed');
});
});
const loginForm = document.getElementById('loginForm');
loginForm.addEventListener('submit', function (event) {
event.preventDefault();
const loginData = {
usernameOrEmail: document.getElementById('loginUsernameOrEmail').value,
password: document.getElementById('loginPassword').value,
};
fetch('http://panel.mait.ac.in:8001/auth/login/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(loginData),
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Login Successful');
const poemPublishSection = document.getElementById('poemPublishSection');
poemPublishSection.style.display = 'block';
} else {
alert('Login failed');
}
})
.catch(error => {
alert('Login failed');
});
});
const poemForm = document.getElementById('poemForm');
poemForm.addEventListener('submit', function (event) {
event.preventDefault();
const poemData = {
title: document.getElementById('poemTitle').value,
content: document.getElementById('poemContent').value,
};
fetch('http://panel.mait.ac.in:8001/poems', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(poemData),
})
.then(response => {
if (response.ok) {
alert('Poem Published Successfully');
} else {
alert('Poem publishing failed');
}
})
.catch(error => {
alert('Poem publishing failed');
});
});
});
</script>
</body>
</html>