<commit_before>from datetime import datetime
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import authenticate, login
from django.db import transaction
from django.http import HttpResponseRedirect
from django.shortcuts import redirect, render
from django.template.loader import render_to_string
from corehq.apps.domain.decorators import login_required_late_eval_of_LOGIN_URL
from corehq.apps.domain.models import Domain
from corehq.apps.orgs.views import orgs_landing
from corehq.apps.registration.models import RegistrationRequest
from corehq.apps.registration.forms import NewWebUserRegistrationForm, DomainRegistrationForm, OrganizationRegistrationForm
from corehq.apps.registration.utils import *
from dimagi.utils.couch.resource_conflict import retry_resource
from dimagi.utils.web import get_ip
from corehq.apps.domain.decorators import require_superuser
from corehq.apps.orgs.models import Organization

DOMAIN_TYPES = (
    'commcare',
    'commtrack'
)

def registration_default(request):
    return redirect(register_user)

@transaction.commit_on_success
def register_user(request, domain_type=None):
    domain_type = domain_type or 'commcare'
    assert domain_type in DOMAIN_TYPES

    if request.user.is_authenticated():
        # Redirect to a page which lets user choose whether or not to create a new account
        vals = {}
        domains_for_user = Domain.active_for_user(request.user)
        if len(domains_for_user) == 0:
            return redirect("registration_domain")
        else:
            return redirect("domain_list")
    else:
        if request.method == 'POST':
            form = NewWebUserRegistrationForm(request.POST)
            if form.is_valid():
                activate_new_user(form, ip=get_ip(request))
                new_user = authenticate(username=form.cleaned_data['email'],<commit_msg>Fix error on /register/user if already logged in<commit_after>from datetime import datetime
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import authenticate, login
from django.db import transaction
from django.http import HttpResponseRedirect
from django.shortcuts import redirect, render
from django.template.loader import render_to_string
from corehq.apps.domain.decorators import login_required_late_eval_of_LOGIN_URL
from corehq.apps.domain.models import Domain
from corehq.apps.orgs.views import orgs_landing
from corehq.apps.registration.models import RegistrationRequest
from corehq.apps.registration.forms import NewWebUserRegistrationForm, DomainRegistrationForm, OrganizationRegistrationForm
from corehq.apps.registration.utils import *
from dimagi.utils.couch.resource_conflict import retry_resource
from dimagi.utils.web import get_ip
from corehq.apps.domain.decorators import require_superuser
from corehq.apps.orgs.models import Organization

DOMAIN_TYPES = (
    'commcare',
    'commtrack'
)

def registration_default(request):
    return redirect(register_user)

@transaction.commit_on_success
def register_user(request, domain_type=None):
    domain_type = domain_type or 'commcare'
    assert domain_type in DOMAIN_TYPES

    if request.user.is_authenticated():
        # Redirect to a page which lets user choose whether or not to create a new account
        vals = {}
        domains_for_user = Domain.active_for_user(request.user)
        if len(domains_for_user) == 0:
            return redirect("registration_domain")
        else:
            return redirect("homepage")
    else:
        if request.method == 'POST':
            form = NewWebUserRegistrationForm(request.POST)
            if form.is_valid():
                activate_new_user(form, ip=get_ip(request))
                new_user = authenticate(username=form.cleaned_data['email'],
{'fraction_non_alphanumeric': 0.06715634837355719, 'fraction_numerical': 0.0005246589716684155, 'mean_word_length': 4.31058495821727, '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': '3607891', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1027, 'n_words': 276}