Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
393 lines (312 loc) · 12.6 KB

File metadata and controls

393 lines (312 loc) · 12.6 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
#from decorator import view_new_notification
from django.contrib.auth.models import User
from forms import UserForm, CreateProjectForm, FilterForm, SolutionForm, PagesForm
from models import Projects, Solution, Notifications
### CUSTOM FUNCTIONS
import uuid
def genid(prefix):
return prefix+str(uuid.uuid4())
def is_a_num(s):
try:
float(s)
return True
except ValueError:
return False
def create_notification(username, link, title):
Notifications.objects.create(username=username, link=link, title=title)
def remove_notification(remove_notification_title):
if remove_notification_title != None:
noti =Notifications.objects.get(title=remove_notification_title)
noti.is_new = False
noti.save()
def notifications(request):
user = request.user.username
notifications = {}
notifications["nots"] = []
for noti in Notifications.objects.filter(username=user):
if noti.is_new:
notifications["nots"].append({"link":noti.link,"title":noti.title})
if notifications["nots"] != []:
notifications["is_new"] = True
else:
notifications["is_new"] = False
notifications["number"] = str(len(notifications["nots"]))
return notifications
def get_pages(request, items_length):
pages={}
pages["page_limit"] = 5
pages["page_links"] = []
if request.method == 'POST':
pages["form"] = PagesForm(request.POST)
pages["page_limit"] = int(request.POST.get("page"))
else:
pages["form"] = PagesForm()
for x in range(items_length/pages["page_limit"]): pages["page_links"].append(str(x))
pages["page_links"] = "".join(pages["page_links"])
if items_length%pages["page_limit"] != 0 and pages["page_links"] != "":
pages["page_links"] = pages["page_links"]+str(int(pages["page_links"][-1])+1)
return pages
def malicious_activity(request, user, description):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
create_notification("emckerrow1", "/all_users/", user+" ("+ip+")"+" - "+description)
### MAPPED FUNCTIONS
def register(request):
error_msg = False
if request.method == 'POST':
error_msg = []
uf = UserForm(request.POST, prefix='user')
#print User.objects.all()
if request.POST.get('user-password1') != request.POST.get('user-password2'):
error_msg.append("Password do not match")
if len(request.POST.get('user-password1')) < 8 or len(request.POST.get('user-password1')) > 75:
error_msg.append("Password must be between 8 and 75 characthers")
try:
username_error = User.objects.get(username=request.POST.get('user-username'))
error_msg.append("Username is taken")
except User.DoesNotExist:
pass
if uf.is_valid():
#user = uf.save(commit=False)
user = uf.save(commit=True)
new_user = User.objects.get(username=request.POST.get('user-username'))
new_user.userprofile.balance = 0
new_user.userprofile.is_admin = False
#user.userprofile.balance = 0
#user.userprofile.is_admin = False
#
new_user.save()
return HttpResponseRedirect("/success")
else:
uf = UserForm(prefix='user')
return render(request,"BuildPythonPleaseGUI/register.html", {
"userform":uf,
"error_msg":error_msg,
})
def success(request):
return render(request, 'BuildPythonPleaseGUI/success.html')
def terms_and_conditions(request):
return render(request, 'BuildPythonPleaseGUI/terms_and_conditions.html', {'notifications':notifications(request)})
#@login_required(login_url="login")
def home(request):
return render(request,"BuildPythonPleaseGUI/home.html", {
'notifications':notifications(request),
})
def about_us(request):
#print UserProxy
#print request
#create_notification(request.user.username, "/", "Visited About Us page")
return render(request, 'BuildPythonPleaseGUI/about_us.html', {'notifications':notifications(request)})
#return render(request, 'BuildPythonPleaseGUI/about_us.html')
@login_required(login_url="login")
def projects(request):
form = FilterForm()
if request.method == 'POST':
form = FilterForm(request.POST)
# DOESNT WORK without print statement?????
print form
search = form.clean().get("search")
if search == 'Open Projects':
projects = Projects.objects.filter(status="Open")
search_title = "Available Projects"
elif search == 'Closed Projects':
projects = Projects.objects.filter(status="Closed")
search_title = "Closed Projects"
elif search == 'My Projects':
projects = Projects.objects.filter(owner=request.user.username)
search_title = "My Projects"
elif search == "All Projects":
projects = Projects.objects.all()
search_title = "All Projects"
else:
projects = Projects.objects.filter(status="Open")
search_title = "Available Projects"
pages={}
pages["page_limit"] = 5
pages["page_links"] = []
if request.method == 'POST':
pages["form"] = PagesForm(request.POST)
pages["page_limit"] = int(request.POST.get("page"))
for x in range(len(projects)/pages["page_limit"]): pages["page_links"].append(str(x))
pages["page_links"] = "".join(pages["page_links"])
if len(projects)%pages["page_limit"] != 0 and pages["page_links"] != "":
pages["page_links"] = pages["page_links"]+str(int(pages["page_links"][-1])+1)
else:
pages["form"] = PagesForm()
return render(request, 'BuildPythonPleaseGUI/projects.html', {
"search_title":search_title,
"projects":projects,
"form":form,
'notifications':notifications(request),
"pages":pages
})
@login_required(login_url="login")
def create_project(request):
form = CreateProjectForm()
if request.method == 'POST':
title = request.POST.get("title")
owner = request.user.username
version = request.POST.get("version")
client = request.POST.get("client")
description = request.POST.get("description")
status = "Open"
payout = request.POST.get("payout")
projects = Projects(title=title, owner=owner, version=version, client=client, description=description, status=status, payout=payout)
if is_a_num(request.POST.get("payout")):
if int(request.POST.get("payout")) <= int(User.objects.get(username=owner).userprofile.balance):
new_balance = int(User.objects.get(username=owner).userprofile.balance) - int(request.POST.get("payout"))
user = User.objects.get(username=owner)
user.userprofile.balance = new_balance
#update balance
user.save()
#add project
projects.save()
return HttpResponseRedirect("/projects/")
else:
return render(request, 'BuildPythonPleaseGUI/create_project.html', {
"form":CreateProjectForm(initial={"title":title,
"version":version,
"client":client,
"description":description,
}),
"form_error":True,
})
else:
return render(request, 'BuildPythonPleaseGUI/create_project.html', {
"form":CreateProjectForm(initial={"title":title,
"version":version,
"client":client,
"description":description,
"payout":payout
}),
"form_error":True,
})
else:
return render(request, 'BuildPythonPleaseGUI/create_project.html', {
"form":form,
"form_error":False,
'notifications':notifications(request),
})
@login_required(login_url="login")
def project(request, id):
project = Projects.objects.get(id=id)
user = User.objects.get(username=request.user.username)
remove_notification(request.GET.get("remove_notification"))
if project.owner == request.user.username: is_owner = True
else: is_owner = False
if project.status == "Closed": is_closed = True
else: is_closed = False
if request.GET.get('Close') == "Close Project":
if project.status == "Open" and is_owner:
Projects.objects.select_related().filter(id=project.id).update(status="Closed")
user.userprofile.balance = int(user.userprofile.balance) + int(project.payout)
user.save()
return HttpResponseRedirect("/projects/")
elif request.GET.get('submit_solution') == "Submit Solution":
form = SolutionForm()
return render(request, 'BuildPythonPleaseGUI/project_solution.html', {
"project":project,
"form":form,
"id":id,
'notifications':notifications(request),
})
elif request.GET.get('accept_solution') == "Accept Solution":
if project.status == "Open":
solution_id = request.GET.get('solution_id')
sol = Solution.objects.get(id=solution_id)
#update senders balance
user = User.objects.get(username=sol.sender)
new_balance = str(int(user.userprofile.balance) + int(project.payout))
user.userprofile.balance = new_balance
user.save()
#closed project
project.status = "Closed"
project.save()
create_notification(sol.sender, "/project/"+id+"/", "Solution accepted for "+project.id+" with "+sol.id+" - "+project.payout+" added to balance")
for sol_in_proj in Solution.objects.filter(project_id=sol.project_id):
sol_in_proj.delete()
create_notification(sol_in_proj.sender, "/project/"+id+"/", sol.id+" declined for "+project.id)
return HttpResponseRedirect("/projects/")
elif request.GET.get('decline') == "Decline":
solution_id = request.GET.get('solution_id')
sol =Solution.objects.get(id=solution_id)
create_notification(sol.sender, "/project/"+id+"/", sol.id+" declined for "+project.id)
sol.delete()
return HttpResponseRedirect("/project/"+id+"/")
if is_owner:
solutions = []
for sol in Solution.objects.filter(project_id=id):
solutions.append(sol)
if len(solutions) > 0:
pages = get_pages(request, len(solutions))
return render(request, 'BuildPythonPleaseGUI/project.html', {
"project":project,
"is_owner":is_owner,
"is_closed":is_closed,
"solutions":solutions,
'notifications':notifications(request),
"pages":pages,
})
if request.method == 'POST':
sf = SolutionForm(request.POST)
#print request.POST
if sf.is_valid():
solution = sf.save(commit=False)
solution.id = genid("Solution:")
solution.owner = project.owner
solution.sender = user.username
solution.project_id = id
solution = sf.save(commit=True)
create_notification(project.owner, "/project/"+id+"/#"+solution.id, "New Solution - "+solution.id)
#for sol in Solution.objects.all(): print sol.solution
return render(request, 'BuildPythonPleaseGUI/project.html', {
"project":project,
"is_owner":is_owner,
"is_closed":is_closed,
"solutions":False,
'notifications':notifications(request),
})
@login_required(login_url="login")
def all_users(request):
remove_notification(request.GET.get("remove_notification"))
#warning can change request.user
#look how to use session id
#same issue in messages, projects, create_project and project, notifications
user = User.objects.get(username=request.user.username)
#print user
#is_admin = user.userprofile.is_admin
if user.userprofile.is_admin:
every_user = User.objects.all()
if request.GET.get('delete_user') == "Delete User":
user = request.GET.get("username")
User.objects.get(username=user).delete()
return render(request, 'BuildPythonPleaseGUI/all_users.html', {
"every_user":every_user,
'notifications':notifications(request),
})
malicious_activity(request, user.username, "attempted access to /all_users/")
return render(request, "BuildPythonPleaseGUI/malicious_activity.html", {
'notifications':notifications(request),
})
def messages(request):
user = User.objects.get(username=request.user.username)
user_notifications = Notifications.objects.filter(username=user)
if request.GET.get("notification_id") != None and request.GET.get("delete")=="Delete":
notification = Notifications.objects.get(id=request.GET.get("notification_id"))
if notification.username == user.username:
notification.delete()
elif request.GET.get("delete_all")=="Delete All":
user_notifications.delete()
user_notifications.update(is_new=False)
pages = get_pages(request, len(user_notifications))
return render(request, "BuildPythonPleaseGUI/messages.html", {
'notifications':notifications(request),
'user_notifications':user_notifications,
'pages':pages,
})
Morty Proxy This is a proxified and sanitized view of the page, visit original site.