Пример #1
0
def usercreate(request):
    if request.method == 'POST':
        form = NewUserForm(request.POST) 
        if form.is_valid():
            error = False
            if form.is_username_taken() or form.is_username_invalid() or form.are_passwords_invalid():
                error = True 
            if not error: 
                bwu = form.make_user()
                user = authenticate(username=bwu.authuser.username, password=form.cleaned_data['password1'])
                r = EmailChangeManager.begin_change(bwu, form.cleaned_data['email'])
                if user is not None:
                    if user.is_active:
                        login(request, user)
                        return HttpResponseRedirect('/profile')
                    else:
                        return oops(request)
                else:
                    return oops(request)
                return HttpResponseRedirect('/authors/%s' % u.pk) # Redirect after POST
            else:
                return render_to_response('newuser.html', {'form': form, }, context_instance=RequestContext(request)) 
    else:
        if request.user.is_authenticated():
            django.contrib.auth.logout(request)
        form = NewUserForm() # An unbound form
    return render_to_response('newuser.html', {'form': form, }, context_instance=RequestContext(request)) 
Пример #2
0
def changeemail(request, bwuid=None, bwuser=None):
    if not bwuser:
        bwuser = BeatwritUser.objects.get(pk=bwuid)
    
    emailform = EmailChangeForm(request.POST)
    if emailform.is_valid():
        #begin emailing process
        r = EmailChangeManager.begin_change(bwuser, emailform.cleaned_data['emailaddress'], params='settings=1')
        if r.issuccess():
            return message(request, header="More more step...", message="We have sent a confirmation email you the email address you gave.  Please click the link in the email to confirm that the email address is yours.")
        else:
            emsg = "We had a problem when trying to send a confirmation email.  Try reentering the email address and submitting again."
            dummy, passform, optionsform = default_settings_forms(bwuser)
            return render_to_response('settings.html', {'optionsform': optionsform, 'emailform':emailform, 'passform':passform, 'email_error_message': emsg}, context_instance=RequestContext(request)) 
    else:
        #recreate other unbound forms
        pwform = PasswordChangeForm() 
        sform = OptionsForm()
        return render_to_response('settings.html', {'optionsform': sform, 'emailform':eform, 'passform':pwform}, context_instance=RequestContext(request)) 
Пример #3
0
def changeemail(request, bwuid=None, bwuser=None):
    if not bwuser:
        bwuser = BeatwritUser.objects.get(pk=bwuid)

    emailform = EmailChangeForm(request.POST)
    if emailform.is_valid():
        #begin emailing process
        r = EmailChangeManager.begin_change(
            bwuser,
            emailform.cleaned_data['emailaddress'],
            params='settings=1')
        if r.issuccess():
            return message(
                request,
                header="More more step...",
                message=
                "We have sent a confirmation email you the email address you gave.  Please click the link in the email to confirm that the email address is yours."
            )
        else:
            emsg = "We had a problem when trying to send a confirmation email.  Try reentering the email address and submitting again."
            dummy, passform, optionsform = default_settings_forms(bwuser)
            return render_to_response('settings.html', {
                'optionsform': optionsform,
                'emailform': emailform,
                'passform': passform,
                'email_error_message': emsg
            },
                                      context_instance=RequestContext(request))
    else:
        #recreate other unbound forms
        pwform = PasswordChangeForm()
        sform = OptionsForm()
        return render_to_response('settings.html', {
            'optionsform': sform,
            'emailform': eform,
            'passform': pwform
        },
                                  context_instance=RequestContext(request))
Пример #4
0
def usercreate(request):
    if request.method == 'POST':
        form = NewUserForm(request.POST)
        if form.is_valid():
            error = False
            if form.is_username_taken() or form.is_username_invalid(
            ) or form.are_passwords_invalid():
                error = True
            if not error:
                bwu = form.make_user()
                user = authenticate(username=bwu.authuser.username,
                                    password=form.cleaned_data['password1'])
                r = EmailChangeManager.begin_change(bwu,
                                                    form.cleaned_data['email'])
                if user is not None:
                    if user.is_active:
                        login(request, user)
                        return HttpResponseRedirect('/profile')
                    else:
                        return oops(request)
                else:
                    return oops(request)
                return HttpResponseRedirect('/authors/%s' %
                                            u.pk)  # Redirect after POST
            else:
                return render_to_response(
                    'newuser.html', {
                        'form': form,
                    },
                    context_instance=RequestContext(request))
    else:
        if request.user.is_authenticated():
            django.contrib.auth.logout(request)
        form = NewUserForm()  # An unbound form
    return render_to_response('newuser.html', {
        'form': form,
    },
                              context_instance=RequestContext(request))