From f3e11c32fc7caa125e9a47e438f6c9d13ecc2c04 Mon Sep 17 00:00:00 2001 From: didayolo Date: Wed, 16 Nov 2022 13:38:15 +0100 Subject: [PATCH 1/6] add condition --- docker/compute_worker/compute_worker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/compute_worker/compute_worker.py b/docker/compute_worker/compute_worker.py index 8f13a5a85..110010ad3 100644 --- a/docker/compute_worker/compute_worker.py +++ b/docker/compute_worker/compute_worker.py @@ -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: From f0fd6bc014fd7ee5ce004da189c67df665feea6a Mon Sep 17 00:00:00 2001 From: didayolo Date: Wed, 16 Nov 2022 13:59:44 +0100 Subject: [PATCH 2/6] Update GPU Dockerfile --- Dockerfile.compute_worker_gpu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile.compute_worker_gpu b/Dockerfile.compute_worker_gpu index a8d9038d8..02db69afd 100644 --- a/Dockerfile.compute_worker_gpu +++ b/Dockerfile.compute_worker_gpu @@ -6,8 +6,8 @@ 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 - From ad6d93725c45d2fe57484fde474009ca0e317f28 Mon Sep 17 00:00:00 2001 From: didayolo Date: Wed, 16 Nov 2022 16:51:50 +0100 Subject: [PATCH 3/6] Make Dockerfiles more robust (amd64 arch) --- Dockerfile.compute_worker | 2 +- Dockerfile.compute_worker_gpu | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile.compute_worker b/Dockerfile.compute_worker index 8934fb37b..77e0ef69d 100644 --- a/Dockerfile.compute_worker +++ b/Dockerfile.compute_worker @@ -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 diff --git a/Dockerfile.compute_worker_gpu b/Dockerfile.compute_worker_gpu index 02db69afd..f2110647c 100644 --- a/Dockerfile.compute_worker_gpu +++ b/Dockerfile.compute_worker_gpu @@ -1,4 +1,4 @@ -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 From b8666cb165d890f5dd26e4d6573210a0e10cfd64 Mon Sep 17 00:00:00 2001 From: bbearce Date: Sun, 27 Nov 2022 19:41:55 +0000 Subject: [PATCH 4/6] email confirmation --- requirements.txt | 1 + src/apps/profiles/tokens.py | 11 +++++ src/apps/profiles/urls.py | 1 + src/apps/profiles/urls_accounts.py | 3 +- src/apps/profiles/views.py | 47 ++++++++++++++++++- src/templates/base.html | 32 +++++++++++++ .../emails/template_activate_account.html | 9 ++++ 7 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 src/apps/profiles/tokens.py create mode 100644 src/templates/profiles/emails/template_activate_account.html diff --git a/requirements.txt b/requirements.txt index b8c5a25b0..5a14473b8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/src/apps/profiles/tokens.py b/src/apps/profiles/tokens.py new file mode 100644 index 000000000..ad6a8ec12 --- /dev/null +++ b/src/apps/profiles/tokens.py @@ -0,0 +1,11 @@ +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() \ No newline at end of file diff --git a/src/apps/profiles/urls.py b/src/apps/profiles/urls.py index 085917008..f989ad405 100644 --- a/src/apps/profiles/urls.py +++ b/src/apps/profiles/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ # url(r'^signup', views.sign_up, name="signup"), + path('activate//', views.activate, name='activate'), path('user//edit/', views.UserEditView.as_view(), name='user_edit'), path('user//notifications/', views.UserNotificationEdit.as_view(), name="user_notifications"), path('user//', views.UserDetailView.as_view(), name="user_profile"), diff --git a/src/apps/profiles/urls_accounts.py b/src/apps/profiles/urls_accounts.py index 7b956f9f7..53a107d82 100644 --- a/src/apps/profiles/urls_accounts.py +++ b/src/apps/profiles/urls_accounts.py @@ -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"), @@ -13,4 +12,4 @@ path('login/', views.LoginView.as_view(), name='login'), # path('logout/', auth_views.LogoutView.as_view(), name='logout'), path('logout/', views.LogoutView.as_view(), name='logout'), -] +] \ No newline at end of file diff --git a/src/apps/profiles/views.py b/src/apps/profiles/views.py index 581112b4f..467622b49 100644 --- a/src/apps/profiles/views.py +++ b/src/apps/profiles/views.py @@ -1,17 +1,24 @@ import json from django.conf import settings +from django.contrib import messages from django.contrib.auth import authenticate, login +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): @@ -56,6 +63,42 @@ def get_context_data(self, **kwargs): context['serialized_user'] = json.dumps(UserSerializer(self.get_object()).data) return context +def activate(request, uidb64, token): + try: + uid = force_str(urlsafe_base64_decode(uidb64)) + user = User.objects.get(pk=uid) + except: + 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 = {} @@ -70,7 +113,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 diff --git a/src/templates/base.html b/src/templates/base.html index fc7221889..850123411 100644 --- a/src/templates/base.html +++ b/src/templates/base.html @@ -25,6 +25,37 @@ {% endblock %} + +{% if messages %} + {% for message in messages %} + {% if message.tags == 'success'%} + + {% elif message.tags == 'info' %} + + {% elif message.tags == 'warning' %} + + {% elif message.tags == 'error' %} + + {% endif %} + {% endfor %} +{% endif %} + +
diff --git a/src/templates/profiles/emails/template_activate_account.html b/src/templates/profiles/emails/template_activate_account.html new file mode 100644 index 000000000..065a02ff5 --- /dev/null +++ b/src/templates/profiles/emails/template_activate_account.html @@ -0,0 +1,9 @@ +{% 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 official email from the University of Paris Saclay. +{% endautoescape %} \ No newline at end of file From 3c585abfcee42bf7f3668bc4abb3688b6e64e4d3 Mon Sep 17 00:00:00 2001 From: bbearce Date: Tue, 29 Nov 2022 19:36:37 +0000 Subject: [PATCH 5/6] flake8 issues --- src/apps/profiles/tokens.py | 9 ++++----- src/apps/profiles/urls_accounts.py | 2 +- src/apps/profiles/views.py | 10 ++++++---- .../profiles/emails/template_activate_account.html | 4 +++- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/apps/profiles/tokens.py b/src/apps/profiles/tokens.py index ad6a8ec12..13439a6b0 100644 --- a/src/apps/profiles/tokens.py +++ b/src/apps/profiles/tokens.py @@ -1,11 +1,10 @@ from django.contrib.auth.tokens import PasswordResetTokenGenerator -import six +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) - ) + return (six.text_type(user.pk) + six.text_type(timestamp) + six.text_type(user.is_active)) -account_activation_token = AccountActivationTokenGenerator() \ No newline at end of file + +account_activation_token = AccountActivationTokenGenerator() diff --git a/src/apps/profiles/urls_accounts.py b/src/apps/profiles/urls_accounts.py index 53a107d82..6266d5216 100644 --- a/src/apps/profiles/urls_accounts.py +++ b/src/apps/profiles/urls_accounts.py @@ -12,4 +12,4 @@ path('login/', views.LoginView.as_view(), name='login'), # path('logout/', auth_views.LogoutView.as_view(), name='logout'), path('logout/', views.LogoutView.as_view(), name='logout'), -] \ No newline at end of file +] diff --git a/src/apps/profiles/views.py b/src/apps/profiles/views.py index 467622b49..93687968f 100644 --- a/src/apps/profiles/views.py +++ b/src/apps/profiles/views.py @@ -2,7 +2,7 @@ from django.conf import settings from django.contrib import messages -from django.contrib.auth import authenticate, login +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 @@ -63,15 +63,16 @@ def get_context_data(self, **kwargs): context['serialized_user'] = json.dumps(UserSerializer(self.get_object()).data) 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: + 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() @@ -81,9 +82,9 @@ def activate(request, uidb64, token): 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', { @@ -100,6 +101,7 @@ def activateEmail(request, user, to_email): 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( diff --git a/src/templates/profiles/emails/template_activate_account.html b/src/templates/profiles/emails/template_activate_account.html index 065a02ff5..e58c40a5f 100644 --- a/src/templates/profiles/emails/template_activate_account.html +++ b/src/templates/profiles/emails/template_activate_account.html @@ -5,5 +5,7 @@ {{ protocol }}://{{ domain }}{% url 'profiles:activate' uidb64=uid token=token %} -This is an official email from the University of Paris Saclay. +Sincerely, +Codabench + {% endautoescape %} \ No newline at end of file From bb68ea0e9f88ce9cabf35b487074bb35df74d5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Pav=C3=A3o?= Date: Tue, 29 Nov 2022 23:36:35 +0100 Subject: [PATCH 6/6] Update template_activate_account.html --- src/templates/profiles/emails/template_activate_account.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/templates/profiles/emails/template_activate_account.html b/src/templates/profiles/emails/template_activate_account.html index e58c40a5f..98ee27122 100644 --- a/src/templates/profiles/emails/template_activate_account.html +++ b/src/templates/profiles/emails/template_activate_account.html @@ -5,7 +5,6 @@ {{ protocol }}://{{ domain }}{% url 'profiles:activate' uidb64=uid token=token %} -Sincerely, -Codabench +This is an automatic message delivered by Codabench. -{% endautoescape %} \ No newline at end of file +{% endautoescape %}