Skip to content

Commit

Permalink
disabling subscribe functionality, I suspect someone is abusing it...
Browse files Browse the repository at this point in the history
  • Loading branch information
arderyp committed Jun 7, 2024
1 parent 7913858 commit 1f105af
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 80 deletions.
6 changes: 3 additions & 3 deletions subscribers/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from subscribers import views

urlpatterns = [
re_path(r'^signup$', views.sign_up, name='sign up'),
re_path(r'^subscribe/(?P<hash_key>[\w{}.-]{20})$', views.subscribe, name='subscribe'),
# re_path(r'^signup$', views.sign_up, name='sign up'),
# re_path(r'^subscribe/(?P<hash_key>[\w{}.-]{20})$', views.subscribe, name='subscribe'),
re_path(r'^unsubscribe/(?P<hash_key>[\w{}.-]{20})$', views.unsubscribe, name='unsubscribe'),
re_path(r'^notifysubscribers', views.notify_subscribers, name='notify subscribers'),
# re_path(r'^notifysubscribers', views.notify_subscribers, name='notify subscribers'),
]
132 changes: 66 additions & 66 deletions subscribers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,68 @@
from scotuswebcites.mail import send_email


def sign_up(request):
if request.method == 'POST':
new_subscriber = False

# App email not configured yet
if settings.EMAIL_HOST_USER == 'YOUR_GMAIL_ADDRESS':
flash_type = messages.WARNING
flash_message = 'It looks like the host is not configured to send emails quite yet'
else:
proceed = True
valid_email = True
email = request.POST.get('email', '')

# Already subscribed
if Subscriber.objects.filter(email=email):
subscriber = Subscriber.objects.get(email=email)
if subscriber.subscribed:
proceed = False
flash_type = messages.SUCCESS
flash_message = 'Good news, it looks like you are already subscribed!'
else:
try:
# Create database record
subscriber = Subscriber(email=email)
subscriber._set_hash()
subscriber.save()
new_subscriber = True
except:
valid_email = False

if valid_email and proceed:
try:
# Success!
_send_confirmation_email(request, subscriber)
flash_type = messages.SUCCESS
flash_message = "Thanks for subscribing! We've sent a confirmation email to %s." % email
except:
valid_email = False
if new_subscriber:
subscriber.delete()

# Bad email provided
if not valid_email:
flash_type = messages.WARNING
flash_message = 'It looks like you submitted an invalid email address'
messages.add_message(request, flash_type, flash_message)

return HttpResponseRedirect(request.META.get('HTTP_REFERER'))


def subscribe(request, hash_key):
subscriber = Subscriber.objects.get(hash_key=hash_key)
if subscriber and not subscriber.subscribed:
subscriber.subscribed = True
subscriber.save()
_notify_admin_of_new_subscriber(subscriber.email)
messages.add_message(
request,
messages.SUCCESS,
'Thanks for confirming your subscription!'
)
return HttpResponseRedirect('/')
# def sign_up(request):
# if request.method == 'POST':
# new_subscriber = False
#
# # App email not configured yet
# if settings.EMAIL_HOST_USER == 'YOUR_GMAIL_ADDRESS':
# flash_type = messages.WARNING
# flash_message = 'It looks like the host is not configured to send emails quite yet'
# else:
# proceed = True
# valid_email = True
# email = request.POST.get('email', '')
#
# # Already subscribed
# if Subscriber.objects.filter(email=email):
# subscriber = Subscriber.objects.get(email=email)
# if subscriber.subscribed:
# proceed = False
# flash_type = messages.SUCCESS
# flash_message = 'Good news, it looks like you are already subscribed!'
# else:
# try:
# # Create database record
# subscriber = Subscriber(email=email)
# subscriber._set_hash()
# subscriber.save()
# new_subscriber = True
# except:
# valid_email = False
#
# if valid_email and proceed:
# try:
# # Success!
# _send_confirmation_email(request, subscriber)
# flash_type = messages.SUCCESS
# flash_message = "Thanks for subscribing! We've sent a confirmation email to %s." % email
# except:
# valid_email = False
# if new_subscriber:
# subscriber.delete()
#
# # Bad email provided
# if not valid_email:
# flash_type = messages.WARNING
# flash_message = 'It looks like you submitted an invalid email address'
# messages.add_message(request, flash_type, flash_message)
#
# return HttpResponseRedirect(request.META.get('HTTP_REFERER'))


# def subscribe(request, hash_key):
# subscriber = Subscriber.objects.get(hash_key=hash_key)
# if subscriber and not subscriber.subscribed:
# subscriber.subscribed = True
# subscriber.save()
# _notify_admin_of_new_subscriber(subscriber.email)
# messages.add_message(
# request,
# messages.SUCCESS,
# 'Thanks for confirming your subscription!'
# )
# return HttpResponseRedirect('/')


def unsubscribe(request, hash_key):
Expand All @@ -85,10 +85,10 @@ def unsubscribe(request, hash_key):
return HttpResponseRedirect('/')


@login_required()
def notify_subscribers(request):
call_command('notifysubscribers')
return HttpResponseRedirect('/citations/')
# @login_required()
# def notify_subscribers(request):
# call_command('notifysubscribers')
# return HttpResponseRedirect('/citations/')


def _send_confirmation_email(request, subscriber):
Expand Down
22 changes: 11 additions & 11 deletions templates/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,17 @@ <h2>How does this work?</h2>
This site was developed by Phil Ardery and is hosted by UC Berkeley Law Library.
</p>

<h2>Subscribe</h2>
<form class="navbar-form navbar-left" method="post" action="/signup">
{% csrf_token %}
<p>
for updates
<input type="text" class="form-control" name="email" placeholder="email@domain.com">
<button type="submit" class="btn btn-primary" title="Get Email Notifications When New Data Is Discovered">
Subscribe
</button>
</p>
</form>
<!-- <h2>Subscribe</h2>-->
<!-- <form class="navbar-form navbar-left" method="post" action="/signup">-->
<!-- {% csrf_token %}-->
<!-- <p>-->
<!-- for updates-->
<!-- <input type="text" class="form-control" name="email" placeholder="email@domain.com">-->
<!-- <button type="submit" class="btn btn-primary" title="Get Email Notifications When New Data Is Discovered">-->
<!-- Subscribe-->
<!-- </button>-->
<!-- </p>-->
<!-- </form>-->
</div>
</div>
</div>
Expand Down

0 comments on commit 1f105af

Please sign in to comment.