feat: Make account activation use html e-mail
This commit is contained in:
		
							
								
								
									
										29
									
								
								src/fellchensammlung/registration_views.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/fellchensammlung/registration_views.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,29 @@
 | 
			
		||||
from django.utils.html import strip_tags
 | 
			
		||||
from django_registration.backends.activation.views import RegistrationView
 | 
			
		||||
from django.core.mail import EmailMultiAlternatives
 | 
			
		||||
from django.template.loader import render_to_string
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class HTMLMailRegistrationView(RegistrationView):
 | 
			
		||||
    def send_activation_email(self, user):
 | 
			
		||||
        """
 | 
			
		||||
        overwrites the function in django registration
 | 
			
		||||
        """
 | 
			
		||||
        activation_key = self.get_activation_key(user)
 | 
			
		||||
        context = self.get_email_context(activation_key)
 | 
			
		||||
        context["user"] = user
 | 
			
		||||
        subject = render_to_string(
 | 
			
		||||
            template_name=self.email_subject_template,
 | 
			
		||||
            context=context,
 | 
			
		||||
            request=self.request,
 | 
			
		||||
        )
 | 
			
		||||
        # Force subject to a single line to avoid header-injection issues.
 | 
			
		||||
        subject = "".join(subject.splitlines())
 | 
			
		||||
        message = render_to_string(
 | 
			
		||||
            template_name=self.email_body_template,
 | 
			
		||||
            context=context,
 | 
			
		||||
            request=self.request,
 | 
			
		||||
        )
 | 
			
		||||
        plain_message = strip_tags(message)
 | 
			
		||||
        user.email_user(subject, plain_message, settings.DEFAULT_FROM_EMAIL, html_message=message)
 | 
			
		||||
@@ -0,0 +1,24 @@
 | 
			
		||||
{% extends "fellchensammlung/mail/base.html" %}
 | 
			
		||||
{% load i18n %}
 | 
			
		||||
{% block title %}
 | 
			
		||||
    {{ site.name }}: {% trans "Account aktivieren" %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
    <p>
 | 
			
		||||
        {% trans 'Hier ist dein Aktivierungs-Key. Mit diesem kannst du deinen Account freischalten.' %}
 | 
			
		||||
    </p>
 | 
			
		||||
    <code>
 | 
			
		||||
        {{ activation_key }}
 | 
			
		||||
    </code>
 | 
			
		||||
 | 
			
		||||
    <p>
 | 
			
		||||
        {% trans "Öffne den folgenden link im Browser und gib den Aktivierungs-Key dort ein" %}
 | 
			
		||||
    </p>
 | 
			
		||||
    <a href="https://{{ site.domain }}{% url 'django_registration_activate' %}"
 | 
			
		||||
       class="cta-button">{% translate 'Jetzt aktivieren' %}</a>
 | 
			
		||||
 | 
			
		||||
    <p>
 | 
			
		||||
        {% blocktrans %}Der Link ist für {{ expiration_days }} Tage gültig.{% endblocktrans %}
 | 
			
		||||
    </p>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@@ -1,10 +1,9 @@
 | 
			
		||||
from django.urls import path, include
 | 
			
		||||
from django_registration.backends.activation.views import RegistrationView
 | 
			
		||||
 | 
			
		||||
from .forms import CustomRegistrationForm
 | 
			
		||||
from .feeds import LatestAdoptionNoticesFeed
 | 
			
		||||
 | 
			
		||||
from . import views
 | 
			
		||||
from . import views, registration_views
 | 
			
		||||
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
 | 
			
		||||
 | 
			
		||||
from django.contrib.sitemaps.views import sitemap
 | 
			
		||||
@@ -79,8 +78,9 @@ urlpatterns = [
 | 
			
		||||
    path('user/me/export/', views.export_own_profile, name='user-me-export'),
 | 
			
		||||
 | 
			
		||||
    path('accounts/register/',
 | 
			
		||||
         RegistrationView.as_view(
 | 
			
		||||
             form_class=CustomRegistrationForm
 | 
			
		||||
         registration_views.HTMLMailRegistrationView.as_view(
 | 
			
		||||
             form_class=CustomRegistrationForm,
 | 
			
		||||
             email_body_template="fellchensammlung/mail/activation_email.html",
 | 
			
		||||
         ),
 | 
			
		||||
         name='django_registration_register',
 | 
			
		||||
         ),
 | 
			
		||||
 
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
{% load i18n %}
 | 
			
		||||
{{ site.name }}: {% trans "Account aktivieren" %}
 | 
			
		||||
 | 
			
		||||
{% trans 'Hier ist dein Aktivierungs-Key. Mit diesem kannst du deinen Account freischalten.' %}
 | 
			
		||||
{{ activation_key }}
 | 
			
		||||
 | 
			
		||||
{% trans "Öffne den folgenden link im Browser und gib den Aktivierungs-Key dort ein" %}:
 | 
			
		||||
https://{{ site.domain }}{% url 'django_registration_activate' %}
 | 
			
		||||
 | 
			
		||||
{% blocktrans %}Der Link ist für {{ expiration_days }} Tage gültig.{% endblocktrans %}
 | 
			
		||||
		Reference in New Issue
	
	Block a user