def register_user(request): if request.method == 'POST': form = UserCreationForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] email = form.cleaned_data['email'] password = form.cleaned_data['password'] if User.objects.filter(username=username): error = 'Пользователь с таким логином уже существует' return render(request, 'register.html', locals()) first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] user = User.objects.create_user(username, email, password=password) user.first_name = first_name user.last_name = last_name user.save() user_profile = UserProfile(user=user) user_profile.save() return redirect(settings.SERVER_PREFIX + 'accounts/login/') form = UserCreationForm() return render(request, 'register.html', locals())
def register_callback(user): user_profile = UserProfile(user=user) user_profile.save()