示例#1
0
def register(request):
    if request.method == 'POST':  # If the form has been submitted...
        #creamos el formulario de doble password
        #creamos el formulario completo de email etc
        form = UserCreationForm(request.POST)
        profile = UserProfileForm(request.POST)
        if form.is_valid() and profile.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            user = form.save()  # Save new user attributes and get the user in the return

            profile = profile.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']
            else:
                picture = "anonymous.png"
                profile.picture = picture
            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True
            #Pasamos una variable para que marque el registro como correcto
            return HttpResponseRedirect('/perfil',{'registered': True})  # Redirect after POST
    else:
        form = UserCreationForm()
        profile = UserProfileForm()
    return render_to_response('register.html', {'user_form': form,'profile_form': profile}, context_instance=RequestContext(request))
示例#2
0
def register(request):
    if request.method == 'POST':  # If the form has been submitted...
        #creamos el formulario de doble password
        #creamos el formulario completo de email etc
        form = UserCreationForm(request.POST)
        profile = UserProfileForm(request.POST)
        if form.is_valid() and profile.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            user = form.save(
            )  # Save new user attributes and get the user in the return

            profile = profile.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']
            else:
                picture = "anonymous.png"
                profile.picture = picture
            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

            #Como el formulario se supone valido procedemos a una vez guardado el usuario logearlo directamente
            username = request.POST.get('username')
            password = request.POST.get('password1')
            # Use Django's machinery to attempt to see if the username/password
            # combination is valid - a User object is returned if it is.
            user = authenticate(username=username, password=password)
            login(request, user)
            #Pasamos una variable para que marque el registro como correcto
            return HttpResponseRedirect(
                '/perfil', {'registered': True})  # Redirect after POST
    else:
        form = UserCreationForm()
        profile = UserProfileForm()
    return render_to_response('register.html', {
        'user_form': form,
        'profile_form': profile
    },
                              context_instance=RequestContext(request))
示例#3
0
def register(request):
    if request.method == 'POST':  # If the form has been submitted...
        #creamos el formulario de doble password
        #creamos el formulario completo de email etc
        form = UserCreationForm(request.POST)
        profile = UserProfileForm(request.POST)
        if form.is_valid() and profile.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            user = form.save()  # Save new user attributes and get the user in the return

            profile = profile.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']
            else:
                picture = "anonymous.png"
                profile.picture = picture
            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

            #Como el formulario se supone valido procedemos a una vez guardado el usuario logearlo directamente
            username = request.POST.get('username')
            password = request.POST.get('password1')
            # Use Django's machinery to attempt to see if the username/password
            # combination is valid - a User object is returned if it is.
            user = authenticate(username=username, password=password)
            login(request, user)
            #Pasamos una variable para que marque el registro como correcto
            return HttpResponseRedirect('/perfil',{'registered': True})  # Redirect after POST
    else:
        form = UserCreationForm()
        profile = UserProfileForm()
    return render_to_response('register.html', {'user_form': form,'profile_form': profile}, context_instance=RequestContext(request))
示例#4
0
def register(request):
    if request.method == 'POST':  # If the form has been submitted...
        #creamos el formulario de doble password
        #creamos el formulario completo de email etc
        form = UserCreationForm(request.POST)
        profile = UserProfileForm(request.POST)
        if form.is_valid() and profile.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            user = form.save(
            )  # Save new user attributes and get the user in the return

            profile = profile.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']
            else:
                picture = "anonymous.png"
                profile.picture = picture
            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True
            #Pasamos una variable para que marque el registro como correcto
            return HttpResponseRedirect(
                '/perfil', {'registered': True})  # Redirect after POST
    else:
        form = UserCreationForm()
        profile = UserProfileForm()
    return render_to_response('register.html', {
        'user_form': form,
        'profile_form': profile
    },
                              context_instance=RequestContext(request))