Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def CreateNewUserView(request):
- if request.method == 'POST':
- user_form = UserCreationForm(request.POST, prefix='user_form')
- user_profile_form = UserProfileCreationForm(request.POST, request.FILES, prefix='user_profile_form')
- if user_form.is_valid():
- new_user = user_form.save()
- if user_profile_form.is_valid():
- profile_picture = request.FILES['profile_picture']
- new_user_profile = UserProfile(user=new_user, profile_picture=profile_picture,
- )
- new_user_profile.save()
- username = user_form.cleaned_data['username']
- password = user_form.cleaned_data['password1']
- user = authenticate(username=username, password=password)
- login(request, user)
- return HttpResponseRedirect('/dashboard/')
- else:
- # Allow user to select a role
- user_form = UserCreationForm(prefix='user_form')
- user_profile_form = UserProfileCreationForm(prefix='user_profile_form')
- return render(request, 'dashboard/create_user.html', {
- 'user_form':user_form,
- 'user_profile_form':user_profile_form,
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement