Ejemplo n.º 1
0
def register(request):
    if request.user.is_authenticated():
        return redirect('/')
    if request.method == 'POST':
        user_form = UserForm(request.POST)
        user_profile_form = UserProfileForm(request.POST, request.FILES)
        if user_form.is_valid() and user_profile_form.is_valid():
            user = user_form.save()
            userprofile = user_profile_form.save(commit=False)
            userprofile.user = user
            userprofile.save()
            try:
                thumbnail = _handle_uploaded_image(request.FILES['thumbnail'], 300, 300)
                userprofile.thumbnail = thumbnail
                userprofile.save()
            except:
                pass
            user.backend = 'django.contrib.auth.backends.ModelBackend'
            login(request, user)
            return redirect('/' + user.username + '/')
    else:
        user_form = UserForm()
        user_profile_form = UserProfileForm()
    return render(request, 'session/register.html',
                    {'user_form': user_form,
                     'user_profile_form': user_profile_form})
Ejemplo n.º 2
0
def account(request):
    if not request.user.is_authenticated():
        return redirect('/')
    if request.method == 'POST':
        user_profile_form = UserProfileForm(request.POST, request.FILES, instance=request.user.userprofile)
        if user_profile_form.is_valid():
            userprofile = user_profile_form.save()
            try:
                thumbnail = _handle_uploaded_image(request.FILES['thumbnail'], 300, 300)
                userprofile.thumbnail = thumbnail
                userprofile.save()
            except:
                pass
            return redirect('./')
    else:
        user_profile_form = UserProfileForm(instance=request.user.userprofile)
    return render(request, 'session/account.html',
                    {'user_profile_form': user_profile_form})