Exemplo n.º 1
0
def register(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('survey.views.survey'))
    else:
        errors = {}
        registered =  False
        if request.POST:
            username = request.POST['user']
            password = request.POST['password']
            repeat_password = request.POST['password-repeat']
            user_form = UserForm(data={'username': username})
            if len(password) <= 0:
                errors['empty_password'] = '******'
            elif password != repeat_password:
                errors['different_passwords'] = 'Passwords do not match!'
            else:
                try:
                    user = User()
                    user.username = username
                    user.set_password(password)
                    user.save()
                    user_profile = UserProfile()
                    user_profile.user = user
                    user_profile.points = 0
                    user_profile.save()
                    user = authenticate(username=username,password=password)
                    registered = True
                    login(request, user)
                except IntegrityError:
                    errors['user_error'] = 'User already exists!'
        else:
            user_form = UserForm()
        return render(request, 'survey/register.html', {'user_form': user_form, 'errors': errors, 'registered': registered})
Exemplo n.º 2
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)

        if form.is_valid():
            new_user = form.save()
            new_user.is_active = False
            new_user.save()

            confirmation_code = sha.new(new_user.username).hexdigest()
            profile = UserProfile(user=new_user, confirmation_code=confirmation_code[0:9])
            profile.save()

            send_registration_confirmation(new_user)

            return render_to_response("account/registration_complete.html")
    else:
        form = RegistrationForm()
    return render_to_response("account/register.html", {'form': form}, context_instance=RequestContext(request))
Exemplo n.º 3
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)

        if form.is_valid():
            new_user = form.save()
            new_user.is_active = False
            new_user.save()

            confirmation_code = sha.new(new_user.username).hexdigest()
            profile = UserProfile(user=new_user, confirmation_code=confirmation_code[0:9])
            profile.save()

            send_registration_confirmation(new_user)

            return render_to_response("account/registration_complete.html")
    else:
        form = RegistrationForm()
    return render_to_response("account/register.html", {'form': form}, context_instance=RequestContext(request))