<commit_before># -*- coding: utf-8 -*-

import uuid

from django.conf import settings
from django.contrib import auth
from django.contrib import messages
from django.contrib import auth
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect, get_object_or_404
from django.views.decorators.debug import sensitive_post_parameters
from django.utils.translation import ugettext as _

from apps.authentication.forms import (LoginForm, RegisterForm, 
                            RecoveryForm, ChangePasswordForm)
from apps.authentication.models import RegisterToken
from apps.misc.forms import InlineSpanErrorList
from apps.userprofile.models import UserProfile

@sensitive_post_parameters()
def login(request):
    redirect_url = request.REQUEST.get('next', '')
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.login(request):
            messages.success(request, _(u'You have successfully logged in.'))
            if redirect_url:
                return HttpResponseRedirect(redirect_url)
            return HttpResponseRedirect('/')
        else: form = LoginForm(request.POST, auto_id=True, error_class=InlineSpanErrorList)
    else:
        form = LoginForm()

    response_dict = { 'form' : form, 'next' : redirect_url}
    return render(request, 'auth/login.html', response_dict)

def logout(request):
    auth.logout(request)
    messages.success(request, _(u'You have successfully logged out.'))
    return HttpResponseRedirect('/')

@sensitive_post_parameters()
def register(request):
    if request.user.is_authenticated():
        messages.error(request, _(u'You cannot be logged in when registering.'))
        return HttpResponseRedirect('/')
    else:
        if request.method == 'POST':
            form = RegisterForm(request.POST)
            if form.is_valid():
                cleaned = form.cleaned_data
                
                # Create user
                user = User(
                    username=cleaned['desired_username'], 
                    first_name=cleaned['first_name'], 
                    last_name=cleaned['last_name'],
                    email=cleaned['email'],
                )
                user.set_password(cleaned['password'])
                user.is_active = False
                user.save()

                # Create userprofile
                up = UserProfile(
                    user=user, 
                    nick=cleaned['desired_username'],
                    date_of_birth=cleaned['date_of_birth'],
                    zip_code=cleaned['zip_code'],
                    address=cleaned['address'],
                    phone=cleaned['phone'],
                )
                up.save() 

                # Create the registration token
                token = uuid.uuid4().hex
                rt = RegisterToken(user=user, token=token)
                rt.save()

                email_message = create_verify_message(request.META['HTTP_HOST'], token) 
                

                send_mail(_(u'Verify your account'), email_message, settings.STUDLAN_FROM_MAIL, [user.email,])

                messages.success(request, _(u'Registration successful. Check your email for verification instructions.'))

                return HttpResponseRedirect('/')        
            else:
                form = RegisterForm(request.POST, auto_id=True, error_class=InlineSpanErrorList)
        else:
            form = RegisterForm()

        return render(request, 'auth/register.html', {'form': form, })

def verify(request, token):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    else:
        rt = get_object_or_404(RegisterToken, token=token)
        
        if rt.is_valid:<commit_msg>Disable silent fail on mail sending<commit_after># -*- coding: utf-8 -*-

import uuid

from django.conf import settings
from django.contrib import auth
from django.contrib import messages
from django.contrib import auth
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect, get_object_or_404
from django.views.decorators.debug import sensitive_post_parameters
from django.utils.translation import ugettext as _

from apps.authentication.forms import (LoginForm, RegisterForm, 
                            RecoveryForm, ChangePasswordForm)
from apps.authentication.models import RegisterToken
from apps.misc.forms import InlineSpanErrorList
from apps.userprofile.models import UserProfile

@sensitive_post_parameters()
def login(request):
    redirect_url = request.REQUEST.get('next', '')
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.login(request):
            messages.success(request, _(u'You have successfully logged in.'))
            if redirect_url:
                return HttpResponseRedirect(redirect_url)
            return HttpResponseRedirect('/')
        else: form = LoginForm(request.POST, auto_id=True, error_class=InlineSpanErrorList)
    else:
        form = LoginForm()

    response_dict = { 'form' : form, 'next' : redirect_url}
    return render(request, 'auth/login.html', response_dict)

def logout(request):
    auth.logout(request)
    messages.success(request, _(u'You have successfully logged out.'))
    return HttpResponseRedirect('/')

@sensitive_post_parameters()
def register(request):
    if request.user.is_authenticated():
        messages.error(request, _(u'You cannot be logged in when registering.'))
        return HttpResponseRedirect('/')
    else:
        if request.method == 'POST':
            form = RegisterForm(request.POST)
            if form.is_valid():
                cleaned = form.cleaned_data
                
                # Create user
                user = User(
                    username=cleaned['desired_username'], 
                    first_name=cleaned['first_name'], 
                    last_name=cleaned['last_name'],
                    email=cleaned['email'],
                )
                user.set_password(cleaned['password'])
                user.is_active = False
                user.save()

                # Create userprofile
                up = UserProfile(
                    user=user, 
                    nick=cleaned['desired_username'],
                    date_of_birth=cleaned['date_of_birth'],
                    zip_code=cleaned['zip_code'],
                    address=cleaned['address'],
                    phone=cleaned['phone'],
                )
                up.save() 

                # Create the registration token
                token = uuid.uuid4().hex
                rt = RegisterToken(user=user, token=token)
                rt.save()

                email_message = create_verify_message(request.META['HTTP_HOST'], token) 
                

                send_mail(_(u'Verify your account'), email_message, settings.STUDLAN_FROM_MAIL, [user.email,], fail_silently=False)

                messages.success(request, _(u'Registration successful. Check your email for verification instructions.'))

                return HttpResponseRedirect('/')        
            else:
                form = RegisterForm(request.POST, auto_id=True, error_class=InlineSpanErrorList)
        else:
            form = RegisterForm()

        return render(request, 'auth/register.html', {'form': form, })

def verify(request, token):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    else:
        rt = get_object_or_404(RegisterToken, token=token)
        
        if rt.is_valid:
{'fraction_non_alphanumeric': 0.09442504203854611, 'fraction_numerical': 0.002069589962488682, 'mean_word_length': 2.2365006278777733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7560816', 'n_tokens_mistral': 2017, 'n_tokens_neox': 1916, 'n_words': 453}