# Path: user/models.py
# 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
# def verification_mail(user, type_, email, request):
#     type_ = type_.lower()
#     type_val = ACTIVATION_TYPES[type_]
# 
#     user_token = generateToken()
# 
#     Activation.objects.create(user=user, token=user_token, type=type_val)
#     activateurl = request.build_absolute_uri(
#         reverse('verify', args=[type_])) + '?token=' + user_token
#     # print(activateurl)
#     with open(os.path.join(settings.BASE_DIR, 'res/registrationmail.txt')) as f:
#         message = f.read()
#         message = message.format(
#             user=user.first_name,
#             url=activateurl
#         )
# 
#     userinf = user.userinformation
#     # print(message)
#     send_mail(
#         _('Your {} verification at the iFSR course enrollment system.'.format(type_)),
#         message,
#         mailsettings.sender,
#         [email],
#         mailsettings.auth_user,
#         mailsettings.auth_pass
#     )
#     # print(user_token)


from django.shortcuts import redirect, render
from django.utils.translation import ugettext as _
from django.core.exceptions import ObjectDoesNotExist
from django.views.decorators.http import require_GET
from django.contrib.auth.decorators import login_required
from user.models import Activation, ACTIVATION_TYPES
from user.views.register import verification_mail
        self.action = action
        if view:
            self.view = view
        else:
            self.view = no_verify_view
        self.name = name


def no_verify_view(request):
    return render(
        request,
        'view-error.html',
        { 'message': _('This verification does not have an associated view.') }
    )


def verify(request, type_):

    if 'token' not in request.GET or type_.lower() not in VERIFICATIONS:
        try:
            return VERIFICATIONS[type_.lower()].view(request)
        except KeyError:
            return render(
                request,
                'view-error.html',
                { 'message': _('This verification does not exist') }
            )
    else:
        try:
            db_entry = Activation.objects.get(token=request.GET['token'], type=ACTIVATION_TYPES[type_])

# Path: user/models.py
# 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
# def verification_mail(user, type_, email, request):
#     type_ = type_.lower()
#     type_val = ACTIVATION_TYPES[type_]
# 
#     user_token = generateToken()
# 
#     Activation.objects.create(user=user, token=user_token, type=type_val)
#     activateurl = request.build_absolute_uri(
#         reverse('verify', args=[type_])) + '?token=' + user_token
#     # print(activateurl)
#     with open(os.path.join(settings.BASE_DIR, 'res/registrationmail.txt')) as f:
#         message = f.read()
#         message = message.format(
#             user=user.first_name,
#             url=activateurl
#         )
# 
#     userinf = user.userinformation
#     # print(message)
#     send_mail(
#         _('Your {} verification at the iFSR course enrollment system.'.format(type_)),
#         message,
#         mailsettings.sender,
#         [email],
#         mailsettings.auth_user,
#         mailsettings.auth_pass
#     )
#     # print(user_token)


# Path: user/views/verify.py
from django.shortcuts import redirect, render
from django.utils.translation import ugettext as _
from django.core.exceptions import ObjectDoesNotExist
from django.views.decorators.http import require_GET
from django.contrib.auth.decorators import login_required
from user.models import Activation, ACTIVATION_TYPES
from user.views.register import verification_mail

        self.action = action
        if view:
            self.view = view
        else:
            self.view = no_verify_view
        self.name = name


def no_verify_view(request):
    return render(
        request,
        'view-error.html',
        { 'message': _('This verification does not have an associated view.') }
    )


def verify(request, type_):

    if 'token' not in request.GET or type_.lower() not in VERIFICATIONS:
        try:
            return VERIFICATIONS[type_.lower()].view(request)
        except KeyError:
            return render(
                request,
                'view-error.html',
                { 'message': _('This verification does not exist') }
            )
    else:
        try:
            db_entry = Activation.objects.get(token=request.GET['token'], type=ACTIVATION_TYPES[type_])

        except Activation.DoesNotExist: