Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile.compute_worker
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8
FROM --platform=linux/amd64 python:3.8

# This makes output not buffer and return immediately, nice for seeing results in stdout
ENV PYTHONUNBUFFERED 1
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.compute_worker_gpu
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM python:3.8.1-buster
FROM --platform=linux/amd64 python:3.8.1-buster

# We need curl to get docker/nvidia-docker
RUN apt-get update && apt-get install curl wget -y

# This makes output not buffer and return immediately, nice for seeing results in stdout
ENV PYTHONUNBUFFERED 1

# Install a specific version of docker
RUN curl -sSL https://get.docker.com/ | sed 's/docker-ce/docker-ce=18.03.0~ce-0~debian/' | sh
# Install Docker
RUN apt-get update && curl -fsSL https://get.docker.com | sh

# nvidia-docker jazz
RUN curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | apt-key add -
Expand Down
2 changes: 1 addition & 1 deletion docker/compute_worker/compute_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ async def _run_program_directory(self, program_dir, kind, can_be_output=False):
with open(os.path.join(program_dir, metadata_path), 'r') as metadata_file:
metadata = yaml.load(metadata_file.read(), Loader=yaml.FullLoader)
logger.info(f"Metadata contains:\n {metadata}")
command = metadata.get("command")
command = metadata.get("command") if metadata is not None else None # in case the file exists but is empty
if not command and kind == "ingestion":
raise SubmissionException("Program directory missing 'command' in metadata")
elif not command:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ django-oauth-toolkit==1.0.0
django-cors-middleware==1.5.0
social-auth-core==2.0.0
social-auth-app-django==3.1.0
six==1.16.0
django-extensions==2.2.6
channels==2.4
channels_redis==3.2.0
Expand Down
10 changes: 10 additions & 0 deletions src/apps/profiles/tokens.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.contrib.auth.tokens import PasswordResetTokenGenerator
import six


class AccountActivationTokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):
return (six.text_type(user.pk) + six.text_type(timestamp) + six.text_type(user.is_active))


account_activation_token = AccountActivationTokenGenerator()
1 change: 1 addition & 0 deletions src/apps/profiles/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

urlpatterns = [
# url(r'^signup', views.sign_up, name="signup"),
path('activate/<uidb64>/<token>', views.activate, name='activate'),
path('user/<slug:username>/edit/', views.UserEditView.as_view(), name='user_edit'),
path('user/<slug:username>/notifications/', views.UserNotificationEdit.as_view(), name="user_notifications"),
path('user/<slug:username>/', views.UserDetailView.as_view(), name="user_profile"),
Expand Down
1 change: 0 additions & 1 deletion src/apps/profiles/urls_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

app_name = "accounts"


urlpatterns = [
url(r'^signup', views.sign_up, name="signup"),
# url(r'^user_profile', views.user_profile, name="user_profile"),
Expand Down
51 changes: 49 additions & 2 deletions src/apps/profiles/views.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import json

from django.conf import settings
from django.contrib.auth import authenticate, login
from django.contrib import messages
from django.contrib.auth import authenticate
from django.contrib.sites.shortcuts import get_current_site
from django.core.mail import EmailMessage
from django.http import Http404
from django.shortcuts import render, redirect
from django.contrib.auth import views as auth_views
from django.contrib.auth.mixins import LoginRequiredMixin
from django.template.loader import render_to_string
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
from django.utils.encoding import force_bytes, force_str
from django.views.generic import DetailView, TemplateView

from api.serializers.profiles import UserSerializer, OrganizationDetailSerializer, OrganizationEditSerializer, \
UserNotificationSerializer
from .forms import SignUpForm
from .models import User, Organization, Membership
from .tokens import account_activation_token


class LoginView(auth_views.LoginView):
Expand Down Expand Up @@ -57,6 +64,44 @@ def get_context_data(self, **kwargs):
return context


def activate(request, uidb64, token):
try:
# import pdb; pdb.set_trace();
uid = force_str(urlsafe_base64_decode(uidb64))
user = User.objects.get(pk=uid)
except User.DoesNotExist:
user = None
messages.error(request, f"User not found. Please sign up again.")
return redirect('accounts:signup')
if user is not None and account_activation_token.check_token(user, token):
user.is_active = True
user.save()
messages.success(request, f'Your account is fully setup! Please login.')
return redirect('accounts:login')
else:
user.delete()
messages.error(request, f"Activation link is invalid. Please sign up again.")
return redirect('accounts:signup')
return redirect('pages:home')


def activateEmail(request, user, to_email):
mail_subject = 'Activate your user account.'
message = render_to_string('profiles/emails/template_activate_account.html', {
'user': user.username,
'domain': get_current_site(request).domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user),
'protocol': 'https' if request.is_secure() else 'http'
})
email = EmailMessage(mail_subject, message, to=[to_email])
if email.send():
messages.success(request, f'Dear {user.username}, please go to you email {to_email} inbox and click on \
received activation link to confirm and complete the registration. *Note: Check your spam folder.')
else:
messages.error(request, f'Problem sending confirmation email to {to_email}, check if you typed it correctly.')


def sign_up(request):
context = {}
context['chahub_signup_url'] = "{}/profiles/signup?next={}/social/login/chahub".format(
Expand All @@ -70,7 +115,9 @@ def sign_up(request):
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=raw_password)
login(request, user, backend='django.contrib.auth.backends.ModelBackend')
user.is_active = False
user.save()
activateEmail(request, user, form.cleaned_data.get('email'))
return redirect('pages:home')
else:
context['form'] = form
Expand Down
32 changes: 32 additions & 0 deletions src/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,37 @@
{% endblock %}
</head>
<body>

{% if messages %}
{% for message in messages %}
{% if message.tags == 'success'%}
<script type=text/javascript>
window.addEventListener('load', function () {
toastr.{{ message.tags }}('{{ message }}')
})
</script>
{% elif message.tags == 'info' %}
<script type=text/javascript>
window.addEventListener('load', function () {
toastr.{{ message.tags }}('{{ message }}')
})
</script>
{% elif message.tags == 'warning' %}
<script type=text/javascript>
window.addEventListener('load', function () {
toastr.{{ message.tags }}('{{ message }}')
})
</script>
{% elif message.tags == 'error' %}
<script type=text/javascript>
window.addEventListener('load', function () {
toastr.{{ message.tags }}('{{ message }}')
})
</script>
{% endif %}
{% endfor %}
{% endif %}

<!-- Sidebar Menu -->
<div class="ui thin sidebar left inverted vertical overlay menu">
<div class="ui container">
Expand All @@ -33,6 +64,7 @@
<a href="https://chagrade.lri.fr/" class="item">Chagrade</a>
</div>
</div>

<div class="pusher">
<div id="hamburger_button">
<div class="ui icon button">
Expand Down
10 changes: 10 additions & 0 deletions src/templates/profiles/emails/template_activate_account.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% autoescape off %}
Hi {{ user.username }},

Please click on the link below to confirm your registration:

{{ protocol }}://{{ domain }}{% url 'profiles:activate' uidb64=uid token=token %}

This is an automatic message delivered by Codabench.

{% endautoescape %}