#views.py
from django.shortcuts import render, redirect
from accounts.forms import RegistrationForm, EditProfileForm, UserProfile
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserChangeForm, PasswordChangeForm
from django.contrib.auth import update_session_auth_hash
from django.contrib.auth.decorators import login_required
def register(request):
registered = False
if request.method == "POST":
user_form = RegistrationForm(request.POST)
profile_form = UserProfile(request.POST)
if user_form.is_valid() and profile_form.is_valid():
user = user_form.save()
user.set_password(user.password)
user.save()
profile = profile_form.save(commit=False)
profile.user = user
if 'profile_pic' in request.FILES:
profile.profile_pic = request.FILES['profile_pic']
profile.save()
registered = True
return redirect('accounts/')
else:
user_form = RegistrationForm()
profile_form = UserProfile()
args = {'user_form': user_form, 'profile_form': profile_form}
return render(request, 'registration/reg_form.html', args)