<commit_before>from django.shortcuts import render, redirect
from django.template import loader, RequestContext
from django.contrib.auth.models import User
from django.conf import settings
from django.contrib.auth import authenticate
from django.contrib.auth.decorators import login_required
from django.contrib.auth import login as auth_login
from django.contrib.auth import logout as auth_logout
from django.http import HttpResponse, JsonResponse
from django.core.mail import send_mail
from django.utils import translation
from django.utils.translation import ugettext as _
from django.forms.forms import NON_FIELD_ERRORS
from django.core.mail import EmailMultiAlternatives
from django.core.mail import EmailMessage
from django.template.loader import render_to_string, get_template

from email.mime.image import MIMEImage
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.message import EmailMessage
from email.headerregistry import Address
from email.utils import make_msgid
import smtplib

import datetime
import pytz

from .utils import isEmailAddressValid
from .models import Activation, Reset
from .forms import LoginForm, RegistrationForm, PasswordChangeForm, LostPasswordForm, PasswordResetForm
from data_cube_ui.models import Area, Application

# Create your views here.

def activate(request, uuid):
    message = _("Your account has been activated, please log in.")
    try:
        activation = Activation.objects.get(url=uuid)
        if (datetime.datetime.utcnow().replace(tzinfo=pytz.utc) - activation.time).days > 0:
            # invalid since you waited too long.
            message = _("Your activation url has expired. Please reregister.")
            user = User.objects.get(username=activation.username)
            user.delete()
            activation.delete()
        else:
            user = User.objects.get(username=activation.username)
            user.is_active = True
            user.save()
            activation.delete()
    except:
        message = _("Invalid activation url. Please try again.")

    form = LoginForm()
    form.cleaned_data = {}
    form.add_error(NON_FIELD_ERRORS, message)
    context = {
        'title': _("Log in"),
        'form': form,
    }
    return render(request, 'registration/login.html', context)


def lost_password(request):
    if request.method == "POST":
        import pdb; pdb.set_trace()
        form = LostPasswordForm(request.POST)
        if form.is_valid():
            user = User.objects.filter(email=form.cleaned_data['email'])
            reset = Reset(username=user[0].username, time=datetime.datetime.now())
            reset.save()

            send_mail(_('DataCube Password Reset'),
                      _('Reset your password here: ') +
                      settings.BASE_HOST + "accounts/" + str(reset.url) + "/reset",
                      '<EMAIL>',
                      [form.cleaned_data['email']],
                      fail_silently=False)

            form = LoginForm()
            form.cleaned_data = {}
            form.add_error(NON_FIELD_ERRORS, _("We have sent an email containing the url required to reset your password. Please use that link then log back in."))
            context = {
                'title': _("Log in"),
                'form': form,
            }
            return render(request, 'registration/login.html', context)
        else:
            context = {'title': _("Password Reset"), 'form': form}
            return render(request, 'registration/lost_password.html', context)

    else:
        context = {'title': _("Password Reset"), 'form': LostPasswordForm()}
        return render(request, 'registration/lost_password.html', context)


def reset(request, uuid):
    try:
        reset = Reset.objects.get(url=uuid)
        if request.method == "POST":
            form = PasswordResetForm(request.POST)<commit_msg>Updated email related stuff and removed a debug statement that caused an error<commit_after>from django.shortcuts import render, redirect
from django.template import loader, RequestContext
from django.contrib.auth.models import User
from django.conf import settings
from django.contrib.auth import authenticate
from django.contrib.auth.decorators import login_required
from django.contrib.auth import login as auth_login
from django.contrib.auth import logout as auth_logout
from django.http import HttpResponse, JsonResponse
from django.core.mail import send_mail
from django.utils import translation
from django.utils.translation import ugettext as _
from django.forms.forms import NON_FIELD_ERRORS
from django.core.mail import EmailMultiAlternatives
from django.core.mail import EmailMessage
from django.template.loader import render_to_string, get_template

from email.mime.image import MIMEImage
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.message import EmailMessage
from email.headerregistry import Address
from email.utils import make_msgid
import smtplib

import datetime
import pytz

from .utils import isEmailAddressValid
from .models import Activation, Reset
from .forms import LoginForm, RegistrationForm, PasswordChangeForm, LostPasswordForm, PasswordResetForm
from data_cube_ui.models import Area, Application

# Create your views here.

def activate(request, uuid):
    message = _("Your account has been activated, please log in.")
    try:
        activation = Activation.objects.get(url=uuid)
        if (datetime.datetime.utcnow().replace(tzinfo=pytz.utc) - activation.time).days > 0:
            # invalid since you waited too long.
            message = _("Your activation url has expired. Please reregister.")
            user = User.objects.get(username=activation.username)
            user.delete()
            activation.delete()
        else:
            user = User.objects.get(username=activation.username)
            user.is_active = True
            user.save()
            activation.delete()
    except:
        message = _("Invalid activation url. Please try again.")

    form = LoginForm()
    form.cleaned_data = {}
    form.add_error(NON_FIELD_ERRORS, message)
    context = {
        'title': _("Log in"),
        'form': form,
    }
    return render(request, 'registration/login.html', context)


def lost_password(request):
    if request.method == "POST":
        #import pdb; pdb.set_trace()
        form = LostPasswordForm(request.POST)
        if form.is_valid():
            user = User.objects.filter(email=form.cleaned_data['email'])
            reset = Reset(username=user[0].username, time=datetime.datetime.now())
            reset.save()

            msg = EmailMessage()
            msg['From'] = '<EMAIL>'
            msg['To'] = form.cleaned_data['email']
            msg['Subject'] = _('DataCube Password Reset')
            msg.set_content(_('Reset your password here: ') + settings.BASE_HOST + "/accounts/" + str(reset.url) + "/reset")
            # Sending the email:
            with smtplib.SMTP('localhost') as s:
                s.send_message(msg)

            form = LoginForm()
            form.cleaned_data = {}
            form.add_error(NON_FIELD_ERRORS, _("We have sent an email containing the url required to reset your password. Please use that link then log back in."))
            context = {
                'title': _("Log in"),
                'form': form,
            }
            return render(request, 'registration/login.html', context)
        else:
            context = {'title': _("Password Reset"), 'form': form}
            return render(request, 'registration/lost_password.html', context)

    else:
        context = {'title': _("Password Reset"), 'form': LostPasswordForm()}
        return render(request, 'registration/lost_password.html', context)


def reset(request, uuid):
    try:
        reset = Reset.objects.get(url=uuid)
        if request.method == "POST":
            form = PasswordResetForm(request.POST)
{'fraction_non_alphanumeric': 0.09581815898530704, 'fraction_numerical': 0.0005023232450081628, 'mean_word_length': 2.900097943192948, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 7, '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': '732409', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2067, 'n_words': 615}