def user_registration(request): if not settings.USE_INTERNAL_AUTH: raise SuspiciousOperation redirect_to = request.REQUEST.get("next", reverse("root")) if not is_safe_url(url=redirect_to, host=request.get_host()): redirect_to = settings.LOGIN_REDIRECT_URL if request.user.is_authenticated(): # Already registered, redirect back to index page return redirect(redirect_to) if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): u = User.objects.create_user(form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password1']) u.is_active = True u.save() user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1']) if user is not None: logger.debug(user) if user.is_active: login(request, user) return redirect(redirect_to) else: form = RegistrationForm() context = { 'form': form, 'next': redirect_to, } return render(request, 'register.html', context)
def user_registration(request): if not settings.USE_INTERNAL_AUTH: raise SuspiciousOperation try: redirect_to = request.GET["next"] except KeyError: try: redirect_to = request.POST["next"] except KeyError: redirect_to = reverse("hk_root") if not is_safe_url(url=redirect_to, host=request.get_host()): redirect_to = settings.LOGIN_REDIRECT_URL if request.user.is_authenticated(): # Already registered, redirect back to index page return redirect(redirect_to) if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): user = form.save() user.backend = "django.contrib.auth.backends.ModelBackend" logger.info("New registered user: %s", user.username) if user.is_active: login(request, user) return redirect(redirect_to) else: form = RegistrationForm() context = { 'form': form, 'next': redirect_to, } return render(request, 'hyperkitty/register.html', context)
def user_registration(request): if not settings.USE_INTERNAL_AUTH and \ request.META["SERVER_NAME"] != "testserver": # work with unit tests raise SuspiciousOperation redirect_to = request.REQUEST.get("next", reverse("root")) if not is_safe_url(url=redirect_to, host=request.get_host()): redirect_to = settings.LOGIN_REDIRECT_URL if request.user.is_authenticated(): # Already registered, redirect back to index page return redirect(redirect_to) if request.POST: form = RegistrationForm(request.POST) if form.is_valid(): u = User.objects.create_user(form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password1']) u.is_active = True u.save() user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password1']) if user is not None: logger.debug(user) if user.is_active: login(request, user) return redirect(redirect_to) else: form = RegistrationForm() context = { 'form': form, 'next': redirect_to, } return render(request, 'register.html', context)