diff --git a/app/authentification/forms.py b/app/authentification/forms.py index 4baa354a..19abc1f2 100644 --- a/app/authentification/forms.py +++ b/app/authentification/forms.py @@ -2,6 +2,7 @@ from django import forms from django.contrib.auth.forms import UserCreationForm from django.contrib.auth.models import User + class SignupForm(UserCreationForm): email = forms.EmailField(max_length=200, help_text='Required') diff --git a/app/authentification/templates/base_auth.html b/app/authentification/templates/base_auth.html index 2fd0f41c..31992722 100644 --- a/app/authentification/templates/base_auth.html +++ b/app/authentification/templates/base_auth.html @@ -1,11 +1,11 @@ {% extends 'base.html' %} {% block content %} -
-
-
- {% block content_auth %}{% endblock %} -
+
+
+
+ {% block content_auth %}{% endblock %}
+
{% endblock %} diff --git a/app/authentification/templates/password_reset_confirm.html b/app/authentification/templates/password_reset_confirm.html index 89314e24..b4d0a716 100644 --- a/app/authentification/templates/password_reset_confirm.html +++ b/app/authentification/templates/password_reset_confirm.html @@ -1,25 +1,25 @@ {% extends "base_auth.html" %} {% block content_auth %} - {% if validlink %} -
-
-

Change password

-
- -
- {% csrf_token %} - {{ form.as_p }} -
- -
-
- +{% if validlink %} +
+
+

Change password

- {% else %} -
- The password reset link was invalid, possibly because it has already been used. - Please request a new password reset. + +
+ {% csrf_token %} + {{ form.as_p }} +
+
- {% endif %} +
+ +
+{% else %} +
+ The password reset link was invalid, possibly because it has already been used. + Please request a new password reset. +
+{% endif %} {% endblock %} diff --git a/app/authentification/templates/password_reset_form.html b/app/authentification/templates/password_reset_form.html index 78295d27..d9bf458d 100644 --- a/app/authentification/templates/password_reset_form.html +++ b/app/authentification/templates/password_reset_form.html @@ -11,7 +11,7 @@ {% csrf_token %} {{ form.as_p }}
- +
diff --git a/app/authentification/templates/signup.html b/app/authentification/templates/signup.html index c8b4c752..811fc508 100644 --- a/app/authentification/templates/signup.html +++ b/app/authentification/templates/signup.html @@ -9,23 +9,23 @@
-->
{% csrf_token %} - {% for field in form %} -
- -
- {{ field|addcss:'input' }} - {% if field.help_text %} - {{ field.help_text }} - {% endif %} - {% for error in field.errors %} -

{{ error }}

- {% endfor %} -
+ {% for field in form %} +
+ +
+ {{ field|addcss:'input' }} + {% if field.help_text %} + {{ field.help_text }} + {% endif %} + {% for error in field.errors %} +

{{ error }}

+ {% endfor %}
+
- {% endfor %} + {% endfor %}
- +
diff --git a/app/authentification/templatetags/utils_templating.py b/app/authentification/templatetags/utils_templating.py index bd747cba..ced2894d 100644 --- a/app/authentification/templatetags/utils_templating.py +++ b/app/authentification/templatetags/utils_templating.py @@ -2,6 +2,7 @@ from django import template register = template.Library() + @register.filter(name='addcss') def addcss(value, arg): css_classes = value.field.widget.attrs.get('class', '').split(' ') diff --git a/app/authentification/tokens.py b/app/authentification/tokens.py index ad5ab594..e8b35d21 100644 --- a/app/authentification/tokens.py +++ b/app/authentification/tokens.py @@ -1,9 +1,13 @@ from django.contrib.auth.tokens import PasswordResetTokenGenerator from django.utils import six + + class TokenGenerator(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 = TokenGenerator() diff --git a/app/authentification/urls.py b/app/authentification/urls.py index 11717dff..51d1a809 100644 --- a/app/authentification/urls.py +++ b/app/authentification/urls.py @@ -1,14 +1,17 @@ from django.urls import path from django.contrib.auth.views import PasswordResetDoneView, PasswordResetConfirmView, PasswordResetCompleteView -from .views import SignupView -from .utils import activate +from .views import SignupView +from .utils import activate urlpatterns = [ - path('password_reset/done/', PasswordResetDoneView.as_view(),name='password_reset_done'), - path('reset/done/', PasswordResetCompleteView.as_view(),name='password_reset_complete'), - path('reset///', PasswordResetConfirmView.as_view(),name='password_reset_confirm'), + path('password_reset/done/', PasswordResetDoneView.as_view(), + name='password_reset_done'), + path('reset/done/', PasswordResetCompleteView.as_view(), + name='password_reset_complete'), + path('reset///', PasswordResetConfirmView.as_view(), + name='password_reset_confirm'), path('signup/', SignupView.as_view(), name='signup'), path('activate//', activate, name='activate'), ] diff --git a/app/authentification/utils.py b/app/authentification/utils.py index 3c9856fe..deba90f4 100644 --- a/app/authentification/utils.py +++ b/app/authentification/utils.py @@ -6,6 +6,7 @@ from django.utils.http import urlsafe_base64_decode from .tokens import account_activation_token from django.contrib.auth.models import User + def activate(request, uidb64, token): try: uid = force_text(urlsafe_base64_decode(uidb64)) @@ -15,7 +16,8 @@ def activate(request, uidb64, token): if user is not None and account_activation_token.check_token(user, token): user.is_active = True user.save() - login(request=request, user=user, backend='django.contrib.auth.backends.ModelBackend') + login(request=request, user=user, + backend='django.contrib.auth.backends.ModelBackend') return redirect('projects') else: return render(request, 'validate_mail_address_invalid.html') diff --git a/app/authentification/views.py b/app/authentification/views.py index 24b0fe60..7b01a693 100644 --- a/app/authentification/views.py +++ b/app/authentification/views.py @@ -10,6 +10,7 @@ from django.views.generic import TemplateView from app import settings + class SignupView(TemplateView): template_name = 'signup.html' form_class = SignupForm @@ -35,12 +36,12 @@ class SignupView(TemplateView): message = render_to_string('acc_active_email.html', { 'user': user, 'domain': current_site.domain, - 'uid':urlsafe_base64_encode(force_bytes(user.pk)).decode(), - 'token':account_activation_token.make_token(user), + 'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(), + 'token': account_activation_token.make_token(user), }) to_email = form.cleaned_data.get('email') email = EmailMessage( - mail_subject, message, to=[to_email] + mail_subject, message, to=[to_email] ) email.send() return render(request, 'validate_mail_address_complete.html') diff --git a/app/server/views.py b/app/server/views.py index 8d520ccc..785e8c79 100644 --- a/app/server/views.py +++ b/app/server/views.py @@ -90,7 +90,7 @@ class LoginView(BaseLoginView): extra_context = { 'github_login': bool(settings.SOCIAL_AUTH_GITHUB_KEY), 'aad_login': bool(settings.SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_TENANT_ID), - 'allow_signup' : bool(settings.ALLOW_SIGNUP), + 'allow_signup': bool(settings.ALLOW_SIGNUP), } def get_context_data(self, **kwargs):