diff --git a/OpenBench/urls.py b/OpenBench/urls.py index d6bb38a..95cd84e 100644 --- a/OpenBench/urls.py +++ b/OpenBench/urls.py @@ -8,11 +8,12 @@ urlpatterns = [ path(r'logout/', OpenBench.views.logout), path(r'viewProfile/', OpenBench.views.viewProfile), - path(r'viewUser//', OpenBench.views.viewUser), + path(r'editProfile/', OpenBench.views.editProfile), path(r'index/', OpenBench.views.index), path(r'index//', OpenBench.views.index), path(r'users/', OpenBench.views.users), + path(r'viewUser//', OpenBench.views.viewUser), path(r'machines/', OpenBench.views.machines), path(r'eventLog/', OpenBench.views.eventLog), diff --git a/OpenBench/utils.py b/OpenBench/utils.py index cf56809..b35fb90 100644 --- a/OpenBench/utils.py +++ b/OpenBench/utils.py @@ -1,4 +1,4 @@ -from OpenBench.models import Engine, Test +from OpenBench.models import Engine, Profile, Machine, Test import math, requests @@ -70,6 +70,11 @@ def newTest(request): basesha, basesource = getSourceLocation(basename, request.POST['source']) test.base = newEngine(basename, basesource, baseprotocol, basesha, basebench) + # Track # of tests by this user + profile = Profile.objects.get(user=request.user) + profile.tests += 1 + profile.save() + # Nothing seems to have gone wrong test.save() return test \ No newline at end of file diff --git a/OpenBench/views.py b/OpenBench/views.py index c4b5976..eb22acd 100644 --- a/OpenBench/views.py +++ b/OpenBench/views.py @@ -68,7 +68,7 @@ def login(request): # Bad data, kick back to index with error except Exception as error: - return index(request, error=str(error)) + return index(request, error='Invalid Login Credentials') def logout(request): @@ -76,11 +76,35 @@ def logout(request): logoutUser(request) return HttpResponseRedirect('/index/') +@login_required(login_url='/login/') def viewProfile(request): - pass -def viewUser(request, username): - return index(request, username=username) + # Build context dictionary for template + profile = Profile.objects.get(user=request.user) + data = {'profile' : profile} + return render(request, 'viewProfile.html', data) + +@login_required(login_url='/login/') +def editProfile(request): + + # Update Email & Source Repo + profile = Profile.objects.get(user=request.user) + profile.user.email = request.POST['email'] + profile.repo = request.POST['repo'] + profile.save() + + # Change Passwords + password1 = request.POST['password1'] + password2 = request.POST['password2'] + if password1 != '' and password1 == password2: + profile.user.set_password(password1) + profile.user.save() + user = authenticate(username=request.user.username, password=password1) + loginUser(request, user) + + # Send back to see the changes + return HttpResponseRedirect('/viewProfile/') + def index(request, page=0, username=None, error=''): @@ -122,6 +146,11 @@ def users(request): data = {'profiles' : Profile.objects.all()} return render(request, 'users.html', data) +def viewUser(request, username): + + # Index but with only username's tests + return index(request, username=username) + def machines(request): pass @@ -136,13 +165,14 @@ def newTest(request): # User trying to view the new test page if request.method == 'GET': - return render(request, 'newTest.html', {"user" : request.user}) + profile = Profile.objects.get(user=request.user) + return render(request, 'newTest.html', {'profile' : profile}) try: # Throw out non-approved / disabled users profile = Profile.objects.get(user=request.user) if not profile.enabled: - raise Exception("Account not Enabled") + raise Exception('Account not Enabled') # Create test and verify fields test = OpenBench.utils.newTest(request) @@ -180,7 +210,7 @@ def editTest(request, id): test = Test.objects.get(id=id) profile = Profile.objects.get(user=request.user) if not profile.approver and test.author != profile.user.username: - raise Exception("Only Admins Or Test Owners Can Edit A Test") + raise Exception('Only Admins Or Test Owners Can Edit A Test') # Edit the provided test test = Test.objects.get(id=id) @@ -200,7 +230,6 @@ def editTest(request, id): except Exception as error: return index(request, error=str(error)) - @login_required(login_url='/login/') def approveTest(request, id): @@ -208,7 +237,7 @@ def approveTest(request, id): # Throw out users without approver status profile = Profile.objects.get(user=request.user) if not profile.approver: - raise Exception("No Approver Permissions on Account") + raise Exception('No Approver Permissions on Account') # Approve the provided test test = Test.objects.get(id=id) @@ -235,12 +264,12 @@ def restartTest(request, id): test = Test.objects.get(id=id) profile = Profile.objects.get(user=request.user) if not profile.approver and test.author != profile.user.username: - raise Exception("Only Admins Or Test Owners Can Restart A Test") + raise Exception('Only Admins Or Test Owners Can Restart A Test') # Restart the provided test test = Test.objects.get(id=id) if test.passed or test.failed: - raise Exception("Test Already Finished via SPRT") + raise Exception('Test Already Finished via SPRT') test.finished = False test.save() @@ -264,7 +293,7 @@ def stopTest(request, id): test = Test.objects.get(id=id) profile = Profile.objects.get(user=request.user) if not profile.approver and test.author != profile.user.username: - raise Exception("Only Admins Or Test Owners Can Stop A Test") + raise Exception('Only Admins Or Test Owners Can Stop A Test') # Stop the provided test test = Test.objects.get(id=id) @@ -291,7 +320,7 @@ def deleteTest(request, id): test = Test.objects.get(id=id) profile = Profile.objects.get(user=request.user) if not profile.approver and test.author != profile.user.username: - raise Exception("Only Admins Or Test Owners Can Delete A Test") + raise Exception('Only Admins Or Test Owners Can Delete A Test') # Delete the provided test test = Test.objects.get(id=id) @@ -310,7 +339,6 @@ def deleteTest(request, id): except Exception as error: return index(request, error=str(error)) - def getFiles(request): pass diff --git a/Templates/OpenBench/base.html b/Templates/OpenBench/base.html index 89b9445..bb87547 100644 --- a/Templates/OpenBench/base.html +++ b/Templates/OpenBench/base.html @@ -19,6 +19,7 @@
  • ADMIN
  • {% if user.is_authenticated %}
  • Logout
  • +
  • Profile
  • {% else %}
  • Login
  • Register
  • diff --git a/Templates/OpenBench/newTest.html b/Templates/OpenBench/newTest.html index fe45677..e283bd3 100644 --- a/Templates/OpenBench/newTest.html +++ b/Templates/OpenBench/newTest.html @@ -29,7 +29,7 @@
    - +
    diff --git a/Templates/OpenBench/users.html b/Templates/OpenBench/users.html index 45d309e..e3a28a7 100644 --- a/Templates/OpenBench/users.html +++ b/Templates/OpenBench/users.html @@ -19,7 +19,7 @@ {{profile.user.username}} {{profile.games}} {{profile.tests}} - {{profile.repo}} + {{profile.repo}} {{profile.enabled}} {{profile.approver}} diff --git a/Templates/OpenBench/viewProfile.html b/Templates/OpenBench/viewProfile.html new file mode 100644 index 0000000..89142c5 --- /dev/null +++ b/Templates/OpenBench/viewProfile.html @@ -0,0 +1,22 @@ +{% extends "OpenBench/base.html" %} + +{% block style %} +{% load static %} +{% endblock %} + +{% block content %} +
    + {% csrf_token %} + +
    + +
    + +
    + +
    + +
    + +
    +{% endblock %} diff --git a/db.sqlite3 b/db.sqlite3 index 67d8108..4d7c4a3 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ