def register_view(request, *args, **kwargs): user = request.user if user.is_authenticated: return HttpResponse("You are already authenticated as " + str(user.email)) context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() email = form.cleaned_data.get('email').lower() raw_password = form.cleaned_data.get('password1') account = authenticate(email=email, password=raw_password) login(request, account) destination = "" if destination: return redirect(destination) return redirect('home') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'register.html', context)
def registration_view(request): context = {} if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): form.save() email = form.cleaned_data.get('email') raw_password = form.cleaned_data.get('password1') account = authenticate(email=email, password=raw_password) login(request, account) return redirect('home') else: context['registration_form'] = form else: form = RegistrationForm() context['registration_form'] = form return render(request, 'account/register.html', context)
def register(request): if request.method == "POST": user_form = RegistrationForm(request.POST) user_profile_from = UserProfileForm(request.POST) if user_form.is_valid(): new_user = user_form.save(False) new_user.set_password(user_form.cleaned_data["password"]) new_user.save() new_user_profile = user_profile_from.save(False) new_user_profile.user = new_user new_user_profile.save() new_user_info = UserInfo.objects.create(user=new_user) new_user_info.save() return redirect(reverse('Account:user_login')) else: return HttpResponse("Register failed!!!") elif request.method == "GET": form = RegistrationForm() user_profile_from = UserProfileForm() context = {"form": form, "user_profile_form": user_profile_from} return render(request, "Account/register.html", context)