Exemplo n.º 1
0
def user_registration_validate(request):
    """Handle the account creation logic when the form is submitted

This function is overloaded to handle either one or two phase reg"""

    if not Tag.getBooleanTag("ask_about_duplicate_accounts", default=False):
        form = SinglePhaseUserRegForm(request.POST)
    else:
        form = UserRegForm(request.POST)

    if form.is_valid():
        try:
            #there is an email-only account with that email address to upgrade
            user = ESPUser.objects.get(email=form.cleaned_data['email'],
                                       password='******')
        except ESPUser.DoesNotExist:
            try:
                #there is an inactive account with that username
                user = ESPUser.objects.filter(
                    username=form.cleaned_data['username'],
                    is_active=False).latest('date_joined')

            except ESPUser.DoesNotExist:
                user = ESPUser.objects.create_user(
                    username=form.cleaned_data['username'],
                    email=form.cleaned_data['email'])

        user.username = form.cleaned_data['username']
        user.last_name = form.cleaned_data['last_name']
        user.first_name = form.cleaned_data['first_name']
        user.set_password(form.cleaned_data['password'])

        #   Append key to password and disable until activation if desired
        if Tag.getBooleanTag('require_email_validation', default=False):
            userkey = random.randint(0, 2**31 - 1)
            user.password += "_%d" % userkey
            user.is_active = False

        user.save()

        user.groups.add(
            Group.objects.get(name=form.cleaned_data['initial_role']))

        if not Tag.getBooleanTag('require_email_validation', default=False):
            user = authenticate(username=form.cleaned_data['username'],
                                password=form.cleaned_data['password'])

            login(request, user)
            return HttpResponseRedirect('/myesp/profile/')
        else:
            send_activation_email(user, userkey)
            return render_to_response(
                'registration/account_created_activation_required.html',
                request, {
                    'user': user,
                    'site': Site.objects.get_current()
                })
    else:
        return render_to_response('registration/newuser.html', request,
                                  {'form': form})
Exemplo n.º 2
0
def user_registration_phase2(request):
    """Displays the second part of account creation, and when that form is submitted, call a function to handle the actual validation and creation."""   
    if request.method == 'POST':
        return user_registration_validate(request)

    if not Tag.getBooleanTag("ask_about_duplicate_accounts",default=False):
        return HttpResponseRedirect(reverse("users.views.user_registration_phase1"))

    try:
        email = urllib.unquote(request.GET['email'])
    except MultiValueDictKeyError:
        return HttpResponseRedirect(reverse("users.views.user_registration_phase1"))
    form = UserRegForm(initial={'email':email,'confirm_email':email})
    return render_to_response('registration/newuser.html',
                              request, {'form':form, 'email':email})