# Path: user/forms.py
# class UserInformationForm(ModelForm):
#     description = forms.CharField(widget=forms.Textarea, required=False)
# 
#     class Meta:
#         model = UserInformation
#         fields = ('public_profile', 'description', 'accepted_privacy_policy')
#         labels = {
#             'public_profile': _('Public Profile'),
#             'description': _('Description'),
#             'accepted_privacy_policy': _('Privacy Policy')
#         }
#         help_texts = {
#             'description': _('Tell something about yourself. (Markdown enabled) Links are allowed.'),
#             'accepted_privacy_policy': _('You have read our <a href="/privacy-policy/" style="color:#9ACC00 !important;">Privacy Policy</a> and consent to it.')
#         }
# 
# class UserForm(UserCreationForm):
#     class Meta(UserCreationForm.Meta):
#         fields = UserCreationForm.Meta.fields + \
#             ('email', 'first_name', 'last_name')
#         labels = {
#             'email': _('E-Mail address'),
#             'first_name': _('First Name'),
#             'last_name': _('Last Name'),
#             'username': _('Username')
#         }
#         help_texts = {
#             'email': _('An email adress where you can be reached. '
#                        'The verification mail will be sent to this adress.'),
#             'first_name': _('First part of your public name, which should be your genuine first name. '
#                             'If you become a teacher this will be visible to any site visitor. '
#                             'Can be modified later.'),
#             'last_name': _('Second part of your public name, which should be your genuine familyname. '
#                            'If you become a teacher this will be visible to any site visitor. '
#                            'Can be modified later'),
#             'username': _('Unique username. Used for login. (cannot be changed later).')
#         }
# 
# Path: user/models.py
# class UserInformation(models.Model):
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
#     description = models.TextField(default="")
#     public_profile = models.BooleanField(default=False)
#     accepted_privacy_policy = models.BooleanField(
#         validators=[privacy_policy_consented])
# 
#     def __str__(self):
#         return '{first} {last}'.format(first=self.user.first_name, last=self.user.last_name)
# 
#     def render_description(self):
#         return clean_for_user_description(markdown(self.description))
# 
#     @staticmethod
#     def create(
#             username,
#             email,
#             password,
#             first_name,
#             last_name,
#     ):
#         user = User.objects.create_user(
#             email=email,
#             username=username,
#             password=password,
#             first_name=first_name,
#             last_name=last_name
#         )
#         user.is_active = False
#         user.save()
# 
#         return UserInformation.objects.create(user=user, accepted_privacy_policy=True)
# 
# class Activation(models.Model):
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
#     token = models.CharField(max_length=50)
#     type = models.CharField(max_length=1,
#                             choices=tuple((v, k)
#                                           for k, v in ACTIVATION_TYPES.items())
#                             )
# 
# ACTIVATION_TYPES = {
#     'email': 'e'
# }


import random
import string
import os
from django.contrib.auth.decorators import login_required
from django.core.mail import send_mail
from django.urls import reverse
from django.shortcuts import render, redirect
from django.conf import settings
from django.utils.translation import ugettext as _
from django.views.decorators.debug import sensitive_post_parameters, sensitive_variables
from user import mailsettings
from user.forms import UserInformationForm, UserForm
from user.models import UserInformation, Activation, ACTIVATION_TYPES
        if (user_form.is_valid()
                and userinformation_form.is_valid()):

            created_user = user_form.save(commit=False)
            created_user.is_active = False
            created_user.save()

            created_user_information = userinformation_form.save(
                commit=False)

            created_user_information.user = created_user

            created_user_information.save()

            verification_mail(created_user, 'email',
                                created_user.email, request)

            acc = created_user.email

            return render(
                request,
                'registration/success.html',
                {
                    'title': _('Registration successfull'),
                    'mail': acc
                }
            )
        else:
            print('validation failed')
    else:

# Path: user/forms.py
# class UserInformationForm(ModelForm):
#     description = forms.CharField(widget=forms.Textarea, required=False)
# 
#     class Meta:
#         model = UserInformation
#         fields = ('public_profile', 'description', 'accepted_privacy_policy')
#         labels = {
#             'public_profile': _('Public Profile'),
#             'description': _('Description'),
#             'accepted_privacy_policy': _('Privacy Policy')
#         }
#         help_texts = {
#             'description': _('Tell something about yourself. (Markdown enabled) Links are allowed.'),
#             'accepted_privacy_policy': _('You have read our <a href="/privacy-policy/" style="color:#9ACC00 !important;">Privacy Policy</a> and consent to it.')
#         }
# 
# class UserForm(UserCreationForm):
#     class Meta(UserCreationForm.Meta):
#         fields = UserCreationForm.Meta.fields + \
#             ('email', 'first_name', 'last_name')
#         labels = {
#             'email': _('E-Mail address'),
#             'first_name': _('First Name'),
#             'last_name': _('Last Name'),
#             'username': _('Username')
#         }
#         help_texts = {
#             'email': _('An email adress where you can be reached. '
#                        'The verification mail will be sent to this adress.'),
#             'first_name': _('First part of your public name, which should be your genuine first name. '
#                             'If you become a teacher this will be visible to any site visitor. '
#                             'Can be modified later.'),
#             'last_name': _('Second part of your public name, which should be your genuine familyname. '
#                            'If you become a teacher this will be visible to any site visitor. '
#                            'Can be modified later'),
#             'username': _('Unique username. Used for login. (cannot be changed later).')
#         }
# 
# Path: user/models.py
# class UserInformation(models.Model):
#     user = models.OneToOneField(User, on_delete=models.CASCADE)
#     description = models.TextField(default="")
#     public_profile = models.BooleanField(default=False)
#     accepted_privacy_policy = models.BooleanField(
#         validators=[privacy_policy_consented])
# 
#     def __str__(self):
#         return '{first} {last}'.format(first=self.user.first_name, last=self.user.last_name)
# 
#     def render_description(self):
#         return clean_for_user_description(markdown(self.description))
# 
#     @staticmethod
#     def create(
#             username,
#             email,
#             password,
#             first_name,
#             last_name,
#     ):
#         user = User.objects.create_user(
#             email=email,
#             username=username,
#             password=password,
#             first_name=first_name,
#             last_name=last_name
#         )
#         user.is_active = False
#         user.save()
# 
#         return UserInformation.objects.create(user=user, accepted_privacy_policy=True)
# 
# class Activation(models.Model):
#     user = models.ForeignKey(User, on_delete=models.CASCADE)
#     token = models.CharField(max_length=50)
#     type = models.CharField(max_length=1,
#                             choices=tuple((v, k)
#                                           for k, v in ACTIVATION_TYPES.items())
#                             )
# 
# ACTIVATION_TYPES = {
#     'email': 'e'
# }


# Path: user/views/register.py
import random
import string
import os
from django.contrib.auth.decorators import login_required
from django.core.mail import send_mail
from django.urls import reverse
from django.shortcuts import render, redirect
from django.conf import settings
from django.utils.translation import ugettext as _
from django.views.decorators.debug import sensitive_post_parameters, sensitive_variables
from user import mailsettings
from user.forms import UserInformationForm, UserForm
from user.models import UserInformation, Activation, ACTIVATION_TYPES

        if (user_form.is_valid()
                and userinformation_form.is_valid()):

            created_user = user_form.save(commit=False)
            created_user.is_active = False
            created_user.save()

            created_user_information = userinformation_form.save(
                commit=False)

            created_user_information.user = created_user

            created_user_information.save()

            verification_mail(created_user, 'email',
                                created_user.email, request)

            acc = created_user.email

            return render(
                request,
                'registration/success.html',
                {
                    'title': _('Registration successfull'),
                    'mail': acc
                }
            )
        else:
            print('validation failed')
    else:

        user_form = UserForm()