-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
231 lines (211 loc) · 8.53 KB
/
script.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
function registration() {
let passValue = document.getElementById("password").value
let confpassValue = document.getElementById("confirmPassword").value
let gametag = document.getElementById("gametag").value
let email = document.getElementById("email").value
let geburtstag = document.getElementById("geburtsdatum").value
let pronomen = document.getElementById("pronomen").value
let interesse = document.getElementById("interessen").value
let interesse_arrey = interesse.split(',')
let interessen = interesse_arrey ?? ""
if (passValue === confpassValue) {
fetch("http://192.168.22.216:8080/signup",
{method: "POST",
credentials:"same-origin",
headers: {"content-type": "application/json"},
body: JSON.stringify({username: gametag, password: passValue, email: email, geburtstag: geburtstag, pronomen: pronomen, interests: interesse})}).then(function(res){
console.log(res)
if (res.status == 200){
location.href="/login.html"
} else {
window.alert("Das hat nicht geklappt, versuche es bitte nochmal")
}
})
} else {
window.alert("Passwort stimmt nicht überein");
return false;
}
}
if (document.getElementById("loginpage")){
document.getElementById("loginform").addEventListener("submit", verification)
}
function verification(event){
event.preventDefault()
let ema = document.getElementById("emalogin").value
let pas = document.getElementById("paslogin").value
fetch("http://192.168.22.216:8080/login",
{method: "POST",
credentials:"same-origin",
headers: {"content-type": "application/json"},
body: JSON.stringify({"username": ema, "password": pas})}).then(function(res){
console.log(res)
if (res.status == 200){
location.href="/indexa.html"
}
else {
window.alert("Benutzername und/oder Passwort falsch")
}
})
}
if (document.getElementById("freundesuche")){
document.getElementById("suchenform").addEventListener("submit", anfragetext)
}
function anfragetext(event){
event.preventDefault()
let text = document.getElementById("eingabesuche").value
fetch("http://192.168.22.216:8080/searchuser",
{method: "POST",
credentials:"same-origin",
headers: {"content-type": "application/json"},
body: JSON.stringify({"search": text})})
.then(function(res){
console.log(res)
if (res.status == 200){
res.json().then((data) => {
queryUsers(data);
});
}
else {
window.alert("Das hat nichts ergeben")
}
})
}
function queryUsers(data) {
tabellenbody.innerHTML = ""
for (let userid of data){
console.log('userid', userid);
queryuser(userid)
}
}
function project_registration(){
}
function queryuser(userid){
fetch("http://192.168.22.216:8080/queryuser",
{method: "POST",
credentials:"same-origin",
headers: {"content-type": "application/json"},
body: JSON.stringify({"id": userid})}).then(function(res){
console.log(res)
res.json()
.then(function (user){
console.log(user)
let pronouns = user.pronouns ?? "N/A"
let interests = user.interests ?? "N/A"
let tr = document.createElement("tr")
let button = document.createElement("button")
let buttonjs = "Button"+user.username
tr.innerHTML = "<td>"+user.username+"</td><td>"+pronouns+"</td><td>"+user.interests+"</td><td>"+"<button id="+buttonjs+">Freundschaftsanfrage</button>"+"</td>"
tabellenbody.appendChild(tr)
document.getElementById(buttonjs)
button = document.getElementById(buttonjs)
button.onclick = function (){
console.log(user.username)
fetch("http://192.168.22.216:8080/requestfriend",
{method: "POST",
credentials:"same-origin",
headers: {"content-type": "application/json"},
body: JSON.stringify({"requested": userid})}).then(function(res){
window.alert("Freundschaftsanfrage gesendet")
}
)
}
})
}
)}
function frage_freunde(){
fetch("http://192.168.22.216:8080/queryfriendrequests",
{method: "POST",
credentials: 'same-origin',
headers: {"content-type": "application/json"},
})
.then(function(res){
console.log(res)
if (res.status == 200){
res.json().then((data) => {
queryUsers_Freunde(date);
});
}
else {
window.alert("Das hat nichts ergeben")
}
})
}
function queryUsers_Freunde(data) {
tabellenbody.innerHTML = ""
for (let userid of data){
console.log('userid', userid);
queryuser(userid)
}
}
function Freundschaftsanfragen(userid){
fetch("http://192.168.22.216:8080/queryuser",
{method: "POST",
credentials:"same-origin",
headers: {"content-type": "application/json"},
body: JSON.stringify({"id": userid})}).then(function(res){
console.log(res)
res.json()
.then(function (user){
console.log(user)
let tr = document.createElement("tr")
let button_annehmen_id = "Button_annehmen"+user.username
let button_ablehnen_id = "Button_ablehnen"+user.usernameablehnen
tr.innerHTML = "<td>"+user.username+
"</td><td>"+user.interests+"</td><td>"+
"<button id="+button_annehmen_id+">Freundschaftsanfrage annehmen</button>"+
"</td><td>"+"<button id="+button_ablehnen_id+">Freundschaftsanfrage ablehnen</button>"+
"</td>"
tabellenanfrage.appendChild(tr)
button_annehmen = document.getElementById(button_annehmen_id)
button_ablehnen = document.getElementById(button_ablehnen_id)
button_annehmen.onclick = function (){
console.log(user.username)
fetch("http://192.168.22.216:8080/acceptfriendrequest",
{method: "POST",
credentials:"same-origin",
headers: {"content-type": "application/json"},
body: JSON.stringify({"requestor": userid})}).then(function(res){
console.log(res);
})
}
button_ablehnen.onclick = function (){
console.log(user.username)
fetch("http://192.168.22.216:8080/denyfriendrequest",
{method: "POST",
credentials:"same-origin",
headers: {"content-type": "application/json"},
body: JSON.stringify({"requestor": userid})}).then(function(res){
console.log(res);
})
}
})
}
)}
function queryUsers_Anfragen(data) {
tabellenbody.innerHTML = ""
for (let userid of data){
console.log('userid', userid);
queryuser(userid)
}
}
if (document.getElementById("proaseite")){
document.getElementById("projektanlegung").addEventListener("submit", veroeffentlichen)
}
function veroeffentlichen(event){
event.preventDefault()
let name = document.getElementById("projektname").value
let description = document.getElementById("Beschreibungprojekt").value
fetch("http://192.168.22.216:8080/createproject",
{method: "POST",
credentials:"same-origin",
headers: {"content-type": "application/json"},
body: JSON.stringify({"title": name, "description": description})}).then(function(res){
console.log(res)
if (res.status == 200){
location.href="/pros.html"
}
else {
window.alert("Das hat nicht geklappt. Bitte versuche es erneut!")
}
})
}