Skip to content

Commit

Permalink
updated settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajurna committed Apr 6, 2018
1 parent 5f6ce8a commit 8d9422e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 56 deletions.
1 change: 1 addition & 0 deletions cbreader/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@

UNRAR_TOOL = 'C:/Program Files/WinRAR/unrar'

CBREADER_USE_RECAPTCHA = True
RECAPTCHA_PRIVATE_KEY = '6Ld50TUUAAAAAD6tQ4pR7HoBZ80EW_Mp2TyoS8Dz'
RECAPTCHA_PUBLIC_KEY = '6Ld50TUUAAAAANJmBFM0lUVqwuFyyCdoejfpdema'
32 changes: 1 addition & 31 deletions comic/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,27 +203,6 @@ class SettingsForm(forms.Form):
'class': 'form-control'
}
))
recaptcha = forms.BooleanField(help_text='Use Recaptcha',
required=False,
widget=forms.CheckboxInput(
attrs={
'class': 'checkbox'
}
))
recaptcha_public_key = forms.CharField(help_text='Recaptcha Public Key',
required=False,
widget=forms.TextInput(
attrs={
'class': 'form-control'
}
))
recaptcha_private_key = forms.CharField(help_text='Recaptcha Private Key',
required=False,
widget=forms.TextInput(
attrs={
'class': 'form-control'
}
))

def clean_base_dir(self):
data = self.cleaned_data['base_dir']
Expand All @@ -234,17 +213,8 @@ def clean_base_dir(self):
@staticmethod
def get_initial_values():
base_dir, _ = Setting.objects.get_or_create(name='BASE_DIR')
recaptcha_public_key, _ = Setting.objects.get_or_create(name='RECAPTCHA_PUBLIC_KEY')
recaptcha_private_key, _ = Setting.objects.get_or_create(name='RECAPTCHA_PRIVATE_KEY')
recaptcha, _ = Setting.objects.get_or_create(name='RECAPTCHA')
if recaptcha.value == '1':
recaptcha = True
else:
recaptcha = False

initial = {
'base_dir': base_dir.value,
'recaptcha': recaptcha,
'recaptcha_public_key': recaptcha_public_key.value,
'recaptcha_private_key': recaptcha_private_key.value,
}
return initial
12 changes: 0 additions & 12 deletions comic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,6 @@ def settings_page(request):
base_dir = Setting.objects.get(name='BASE_DIR')
base_dir.value = form.cleaned_data['base_dir']
base_dir.save()
recap = Setting.objects.get(name='RECAPTCHA')
if form.cleaned_data['recaptcha']:
recap.value = '1'
else:
recap.value = '0'
recap.save()
recaptcha_private_key = Setting.objects.get(name='RECAPTCHA_PRIVATE_KEY')
recaptcha_private_key.value = form.cleaned_data['recaptcha_private_key']
recaptcha_private_key.save()
recaptcha_public_key = Setting.objects.get(name='RECAPTCHA_PUBLIC_KEY')
recaptcha_public_key.value = form.cleaned_data['recaptcha_public_key']
recaptcha_public_key.save()
success_message.append('Settings updated.')
form = SettingsForm(initial=SettingsForm.get_initial_values())
context = {
Expand Down
15 changes: 2 additions & 13 deletions comic_auth/forms.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django import forms
from django.conf import settings
from snowpenguin.django.recaptcha2.fields import ReCaptchaField
from snowpenguin.django.recaptcha2.widgets import ReCaptchaWidget

from comic.models import Setting


class LoginForm(forms.Form):

Expand All @@ -28,15 +27,5 @@ class LoginForm(forms.Form):

def __init__(self, *args, **kwargs):
super(LoginForm, self).__init__(*args, **kwargs)
setting, created = Setting.objects.get_or_create(name='RECAPTCHA')
if created:
setting.value = '0'
if setting.value == '1':
# public_key = Setting.objects.get(name='RECAPTCHA_PUBLIC_KEY').value
# private_key = Setting.objects.get(name='RECAPTCHA_PRIVATE_KEY').value
#
# captcha = ReCaptchaField(
# public_key=public_key,
# private_key=private_key,
# )
if settings.CBREADER_USE_RECAPTCHA if hasattr(settings, 'CBREADER_USE_RECAPTCHA') else False:
self.fields['captcha'] = ReCaptchaField(widget=ReCaptchaWidget())

0 comments on commit 8d9422e

Please sign in to comment.