diff --git a/addresses/forms.py b/addresses/forms.py index 78625501..d72ba992 100644 --- a/addresses/forms.py +++ b/addresses/forms.py @@ -6,6 +6,9 @@ class KnownUserAddressSubscriptionForm(forms.Form): + + # TODO: add advanced granulatiry for confirms (broadcast/1/6), amount, & send/receive + coin_address = forms.CharField( label=_('Address to Subscribe To'), required=True, diff --git a/addresses/models.py b/addresses/models.py index d5aa9eca..5bfc70d8 100644 --- a/addresses/models.py +++ b/addresses/models.py @@ -28,6 +28,7 @@ def get_currency_display_name(self): return COIN_SYMBOL_MAPPINGS[self.coin_symbol]['display_name'] def send_welcome_email(self): + # TODO: add abuse check so you can only send this email to an unconvirmed user X times b58_address = self.b58_address context_dict = { 'b58_address': b58_address, diff --git a/addresses/views.py b/addresses/views.py index b6f9f4dc..d161fbc1 100644 --- a/addresses/views.py +++ b/addresses/views.py @@ -2,6 +2,7 @@ from django.core.urlresolvers import reverse from django.contrib import messages from django.contrib.auth import login +from django.contrib.auth.decorators import login_required from django.utils.translation import ugettext_lazy as _ from django.utils.timezone import now from django.views.decorators.csrf import csrf_exempt @@ -175,9 +176,6 @@ def subscribe_address(request, coin_symbol): api_key=BLOCKCYPHER_API_KEY, ) - print('bcy_id') - print(bcy_id) - address_subscription = AddressSubscription.objects.create( coin_symbol=coin_symbol, b58_address=coin_address, @@ -185,7 +183,7 @@ def subscribe_address(request, coin_symbol): blockcypher_id=bcy_id, ) - if already_authenticated: + if already_authenticated and auth_user.email_verified: msg = _('You will now be emailed notifications for %(coin_address)s' % {'coin_address': coin_address}) messages.success(request, msg, extra_tags='safe') return HttpResponseRedirect(reverse('dashboard')) @@ -208,7 +206,33 @@ def subscribe_address(request, coin_symbol): } +@login_required +def user_unsubscribe_address(request, address_subscription_id): + ''' + For logged-in users to unsubscribe an address + ''' + address_subscription = get_object_or_404(AddressSubscription, id=address_subscription_id) + assert address_subscription.auth_user == request.user + + if address_subscription.unsubscribed_at: + msg = _("You've already unsubscribed from this alert") + messages.info(request, msg) + else: + address_subscription.unsubscribed_at = now() + address_subscription.save() + + msg = _("You've been unsubscribed from notifications on %(b58_address)s" % { + 'b58_address': address_subscription.b58_address, + }) + messages.info(request, msg) + + return HttpResponseRedirect(reverse('dashboard')) + + def unsubscribe_address(request, unsub_code): + ''' + 1-click unsubscribe an address via email + ''' sent_email = get_object_or_404(SentEmail, unsub_code=unsub_code) auth_user = sent_email.auth_user @@ -229,7 +253,7 @@ def unsubscribe_address(request, unsub_code): address_subscription = sent_email.address_subscription assert address_subscription - address_subscription.deleted_at = now() + address_subscription.unsubscribed_at = now() address_subscription.save() msg = _("You've been unsubscribed from notifications on %(b58_address)s" % { diff --git a/blockexplorer/urls.py b/blockexplorer/urls.py index 680867d3..dd770c42 100644 --- a/blockexplorer/urls.py +++ b/blockexplorer/urls.py @@ -15,6 +15,7 @@ url(r'^set-password/?$', 'users.views.password_upsell', name='password_upsell'), url(r'^change-password/?$', 'users.views.change_password', name='change_password'), url(r'^unsubscribe/(?P[-\w]+)/$', 'addresses.views.unsubscribe_address', name='unsubscribe_address'), + url(r'^remove-subscription/(?P[-\w]+)/$', 'addresses.views.user_unsubscribe_address', name='user_unsubscribe_address'), url(r'^dashboard/?$', 'users.views.dashboard', name='dashboard'), # Webhooks: diff --git a/templates/base.html b/templates/base.html index 6c04649d..be6a72db 100644 --- a/templates/base.html +++ b/templates/base.html @@ -169,6 +169,16 @@ {# Including the messages for the homepage in the home template #} {% else %}
+ {# Page Header Stuff #} + {% include "partials/messages.html" %} {% endif %} @@ -176,7 +186,7 @@ {% block content %} {% endblock content %} -
+ {# Footer #} diff --git a/templates/dashboard.html b/templates/dashboard.html index 418d24f0..6d0dd7c9 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -5,24 +5,16 @@ {% load btc_formats %} {% load static %} -{% block title %} - Dashboard -{% endblock title %} +{% block title %}Dashboard{% endblock title %} -{% block content %} +{% block page_header %}Dashboard{% endblock page_header %} - +{% block content %} {% if not user.email_verified %}
-
+
Your email address ({{ user.email }}) has not been confirmed.
Please check your email and click the link to activate subscriptions. @@ -38,7 +30,12 @@

User Info

    -
  • Email: {{ user.email }}
  • +
  • + Email: {{ user.email }} + {% if user.email_verified %} + (verified) + {% endif %} +
  • Change Password
@@ -50,7 +47,7 @@

  • {{ address_subscription.coin_symbol|coin_symbol_to_display_name }} address {{ address_subscription.b58_address }} - (delete) + (delete)
  • {% endfor %} @@ -59,7 +56,7 @@

    You have no subscriptions.

    {% endif %} - Subscribe to Another Address + + Subscribe to Another Address

    diff --git a/templates/signup.html b/templates/signup.html index 847a66ab..7045bcca 100644 --- a/templates/signup.html +++ b/templates/signup.html @@ -16,7 +16,6 @@

    - {% include "partials/messages.html" %}
    diff --git a/users/forms.py b/users/forms.py index 758081dc..eccfd7a1 100644 --- a/users/forms.py +++ b/users/forms.py @@ -122,7 +122,7 @@ class ChangePWForm(forms.Form): required=True, label=_('New Password'), widget=forms.PasswordInput(attrs={'autocomplete': 'off'}), - min_length=7, + min_length=8, help_text=_('Please choose a new secure password'), ) diff --git a/users/models.py b/users/models.py index 69b9074a..b4be652d 100644 --- a/users/models.py +++ b/users/models.py @@ -16,7 +16,8 @@ def create_user(self, email, password, creation_ip, creation_user_agent): if not email: raise ValueError('Users must have an email address') - user = self.model(email=self.normalize_email(email)) + # force whole email to lowercase. violates spec but better usability. + user = self.model(email=email.lower().strip()) # if no password it calls set_unusuable_password() under the hood: user.set_password(password) user.creation_ip = creation_ip diff --git a/users/views.py b/users/views.py index d8e3261e..9c87df7e 100644 --- a/users/views.py +++ b/users/views.py @@ -198,6 +198,7 @@ def confirm_subscription(request, verif_code): @login_required @render_to('dashboard.html') def dashboard(request): + messages.info(request, 'foo bar baz') user = request.user return { 'user': user,