def signup(request): if is_ip_banned(request): messages.error(request, "Your account was disabled.") return redirect('home') if request.method == 'POST': captcha = CaptchaQuestion.objects.get( id=request.session.get('captcha_id')) form = UserSignupForm(request.POST, captcha=captcha) if form.is_valid(): form.save() user = authenticate( username=form.cleaned_data['username'], password=form.cleaned_data['password1'], ) login(request, user) messages.success(request, 'Account created') return redirect('home') else: captcha = CaptchaQuestion.objects.order_by('?')[0] request.session['captcha_id'] = captcha.id form = UserSignupForm(captcha=captcha) return render(request, 'accounts/signup.html', { 'form': form, })
def signup(request): if is_ip_banned(request): messages.error(request, "Your account was disabled.") return redirect('home') if request.method == 'POST': captcha = CaptchaQuestion.objects.get(id=request.session.get('captcha_id')) form = UserSignupForm(request.POST, captcha=captcha) if form.is_valid(): form.save() user = authenticate( username=form.cleaned_data['username'], password=form.cleaned_data['password1'], ) login(request, user) messages.success(request, 'Account created') return redirect('home') else: captcha = CaptchaQuestion.objects.order_by('?')[0] request.session['captcha_id'] = captcha.id form = UserSignupForm(captcha=captcha) return render(request, 'accounts/signup.html', { 'form': form, })
def read_only_mode(request): return { 'site_is_writeable': settings.SITE_IS_WRITEABLE, 'is_ip_banned': is_ip_banned(request), }
def dispatch(self, request, *args, **kwargs): if is_ip_banned(request): messages.error(request, "Your account was disabled.") return redirect('home') else: return super().dispatch(request, *args, **kwargs)
def custom_login(request): if is_ip_banned(request): messages.error(request, "Your account was disabled.") return redirect('home') else: return base_login(request)