Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ultmaster committed Mar 28, 2017
2 parents d837cf0 + f42c475 commit 0efebd3
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 47 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ eoj3: A new version of eoj.
+ images and files in problems
+ submission privileges
+ special judge (already available on judge server but n/a on this side)
+ async send email
+ concurrency limiter
+ online compiler v
+ online compiler
+ sum time limit in oi rules
+ contest accept / submit
Expand Down
11 changes: 10 additions & 1 deletion account/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms
from .models import User, Privilege
from django.contrib.auth import authenticate
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth.forms import PasswordChangeForm, SetPasswordForm


class RegisterForm(forms.ModelForm):
Expand Down Expand Up @@ -58,6 +58,15 @@ def clean(self):


class MyPasswordChangeForm(PasswordChangeForm):
new_password1 = forms.CharField(
label="New password",
widget=forms.PasswordInput,
strip=False,
help_text='',
)


class MySetPasswordForm(SetPasswordForm):
new_password1 = forms.CharField(
label="New password",
widget=forms.PasswordInput,
Expand Down
14 changes: 9 additions & 5 deletions account/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from django.conf.urls import url

from .views import my_password_change, profile_view
from . import views

urlpatterns = [
url(r'^profile/$', profile_view, name='profile'),
url(r'^security/$', my_password_change, name='security'),
]
url(r'^profile/$', views.profile_view, name='profile'),
url(r'^security/$', views.my_password_change, name='security'),
url(r'^password_reset/$', views.my_password_reset, name='reset_password'),
url(r'^password_reset_done/$', views.my_password_reset_done, name='password_reset_done'),
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
views.my_password_reset_confirm, name='password_reset_confirm'),
]

36 changes: 28 additions & 8 deletions account/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.shortcuts import render, redirect, HttpResponseRedirect, reverse
from django.views import View
from django.contrib import messages

from utils.auth_view import password_change, login
from .forms import RegisterForm, MyPasswordChangeForm
from django.contrib.auth import login
from utils import auth_view
from .forms import RegisterForm, MyPasswordChangeForm, MySetPasswordForm


def profile_view(request):
Expand All @@ -23,11 +23,31 @@ def register_view(request):


def my_password_change(request):
return password_change(request, template_name='account/security.jinja2',
post_change_redirect=reverse('account:profile'),
password_change_form=MyPasswordChangeForm,
message="Your password was changed successfully")
return auth_view.password_change(request, template_name='account/security.jinja2',
post_change_redirect=reverse('account:profile'),
password_change_form=MyPasswordChangeForm,
message="Your password was changed successfully")


def my_login(request):
return login(request, template_name='login.jinja2')
return auth_view.login(request, template_name='login.jinja2')


def my_password_reset(request):
return auth_view.password_reset(request,
from_email="[email protected]",
template_name='account/password_reset.jinja2',
post_reset_redirect='account:password_reset_done',
email_template_name='account/password_reset_email.jinja2')


def my_password_reset_done(request):
return auth_view.password_reset_done(request, template_name='account/password_reset_done.jinja2')


def my_password_reset_confirm(request, **kwargs):
return auth_view.password_reset_confirm(request,
template_name='account/password_reset_confirm.jinja2',
post_reset_redirect=reverse('login'),
set_password_form=MySetPasswordForm,
**kwargs)
44 changes: 23 additions & 21 deletions contest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from problem.models import Problem
from submission.forms import ContestSubmitForm
from dispatcher.tasks import submit_code_for_contest
from account.permissions import is_admin_or_root


def time_formatter(seconds):
Expand All @@ -39,8 +40,7 @@ def test_func(self):
self.permission_denied_message = "Contest hasn't started."
return False
if user.is_authenticated and (ContestParticipant.objects.filter(contest=contest, user=user).exists()
or contest.public
or user.privilege in (Privilege.ROOT, Privilege.ADMIN)):
or contest.public or is_admin_or_root(user)):
return True
else:
self.permission_denied_message = "Did you forget to register for the contest?"
Expand All @@ -63,15 +63,15 @@ def get_context_data(self, **kwargs):
data['progress'] = 0
data['time_delta'] = int((contest.start_time - timezone.now()).total_seconds())
data['contest_problem_list'] = contest.contestproblem_set.all()
data['contest_started'] = contest.start_time <= timezone.now()
data['has_permission'] = self.test_func()
return data


class DashboardView(BaseContestMixin, TemplateView):
template_name = 'contest/index.jinja2'

def test_func(self):
return True
def get_test_func(self):
return lambda: True

def get_context_data(self, **kwargs):
data = super(DashboardView, self).get_context_data(**kwargs)
Expand All @@ -81,22 +81,24 @@ def get_context_data(self, **kwargs):
problem_status = {}
for contest_problem in data['contest_problem_list']:
problem_as_contest_problem[contest_problem.problem.pk] = contest_problem.identifier
submissions = contest.submission_set.filter(author=user).all()
for submission in submissions:
contest_problem = problem_as_contest_problem[submission.problem.pk]
if problem_status.get(contest_problem) != 'success':
if submission.status == SubmissionStatus.ACCEPTED:
problem_status[contest_problem] = 'success'
elif not SubmissionStatus.is_judged(submission.status):
problem_status[contest_problem] = 'warning'
elif SubmissionStatus.is_penalty(submission.status):
problem_status[contest_problem] = 'danger'

for contest_problem in data['contest_problem_list']:
contest_problem.status = problem_status.get(contest_problem.identifier)

if contest.contestparticipant_set.filter(user=user).exists():
data['registered'] = True
if user.is_authenticated:

submissions = contest.submission_set.filter(author=user).all()
for submission in submissions:
contest_problem = problem_as_contest_problem[submission.problem.pk]
if problem_status.get(contest_problem) != 'success':
if submission.status == SubmissionStatus.ACCEPTED:
problem_status[contest_problem] = 'success'
elif not SubmissionStatus.is_judged(submission.status):
problem_status[contest_problem] = 'warning'
elif SubmissionStatus.is_penalty(submission.status):
problem_status[contest_problem] = 'danger'

for contest_problem in data['contest_problem_list']:
contest_problem.status = problem_status.get(contest_problem.identifier)

if contest.contestparticipant_set.filter(user=user).exists():
data['registered'] = True

return data

Expand Down
2 changes: 1 addition & 1 deletion eoj3/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
url(r'^backstage/', include('backstage.urls', namespace='backstage')),
url(r'^account/', include('account.urls', namespace='account')),
url(r'^upload/(?P<path>.*)$', serve, {'document_root': UPLOAD_DIR}, name='upload'),
url(r'^api/', include('eoj3.api_urls', namespace='api')) # not safe?
url(r'^api/', include('eoj3.api_urls', namespace='api'))
]

if DEBUG:
Expand Down
15 changes: 15 additions & 0 deletions templates/account/password_reset.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends 'base.jinja2' %}

{% block content %}

<div class="bd-pageheader">
<div class="container">
<h1>Reset your password</h1>
</div>
</div>

<div class="container">
{% include 'components/form.jinja2' %}
</div>

{% endblock %}
15 changes: 15 additions & 0 deletions templates/account/password_reset_confirm.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends 'base.jinja2' %}

{% block content %}

<div class="bd-pageheader">
<div class="container">
<h1>Reset your password</h1>
</div>
</div>

<div class="container">
{% include 'components/form.jinja2' %}
</div>

{% endblock %}
17 changes: 17 additions & 0 deletions templates/account/password_reset_done.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends 'base.jinja2' %}

{% block content %}

<div class="bd-pageheader">
<div class="container">
<h1>Password reset sent</h1>
</div>
</div>
<div class="container">
<p>
We've emailed you instructions for setting your password, if an account exists with the email you entered. You should receive them shortly.
<br>
If you don't receive an email, please make sure you've entered the address you registered with, and check your spam folder.
</p>
</div>
{% endblock %}
14 changes: 14 additions & 0 deletions templates/account/password_reset_email.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% autoescape off %}
You're receiving this email because you requested a password reset for your user account at {{ site_name }}.

Please go to the following page and choose a new password:
{% block reset_link %}
{{ protocol }}://{{ domain }}{{ url('account:password_reset_confirm', uidb64=uid, token=token) }}
{% endblock %}
"Your username, in case you've forgotten:" {{ user.get_username() }}

Thanks for using our site!

The {{ site_name }} team

{% endautoescape %}
18 changes: 8 additions & 10 deletions templates/contest/base.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@
</div>
<a class="link-lg {{ active('contest:dashboard') }}" href="{{ url('contest:dashboard', contest.pk) }}">Dashboard</a>
<a class="link-lg {{ active('contest:problem') }}">Problem</a>
{% for contest_problem in contest_problem_list %}
<a class="link-sm {{ active('contest:problem', cid=contest.pk, pid=contest_problem.identifier) }}"
href="{{ url('contest:problem', contest.pk, contest_problem.identifier) }}">
{% if contest_started %}
{{ contest_problem.identifier }}. {{ contest_problem.problem.title }}
{% else %}
{{ contest_problem.identifier }}
{% endif %}
</a>
{% endfor %}
{% if has_permission %}
{% for contest_problem in contest_problem_list %}
<a class="link-sm {{ active('contest:problem', cid=contest.pk, pid=contest_problem.identifier) }}"
href="{{ url('contest:problem', contest.pk, contest_problem.identifier) }}">
{{ contest_problem.identifier }}. {{ contest_problem.problem.title }}
</a>
{% endfor %}
{% endif %}
<a class="link-lg {{ active('contest:submit') }}" href="{{ url('contest:submit', contest.pk) }}{% if contest_problem %}?pid={{ contest_problem.identifier }}{% endif %}">Submit</a>
<a class="link-lg {{ active('contest:submission') }}" href="{{ url('contest:submission', contest.pk) }}">My submissions</a>
<a class="link-lg {{ active('contest:status') }}" href="{{ url('contest:status', contest.pk) }}">Status</a>
Expand Down
2 changes: 1 addition & 1 deletion templates/contest/index.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</table>
</div>
{% endif %}
{% if not contest.public and (not registered or contest_status == 'pending') %}
{% if not contest.public and not registered and contest_status == 'pending' %}
<div class="content-section">
<h4>Register</h4>
{% if not registered %}
Expand Down
1 change: 1 addition & 0 deletions utils/auth_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def password_reset_confirm(request, uidb64=None, token=None,
form = set_password_form(user, request.POST)
if form.is_valid():
form.save()
messages.success(request, 'Password reset complete.')
return HttpResponseRedirect(post_reset_redirect)
else:
form = set_password_form(user)
Expand Down

0 comments on commit 0efebd3

Please sign in to comment.