Skip to content

Commit

Permalink
getting closer
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Flaxman committed Apr 1, 2015
1 parent 9f4d115 commit 58a59a4
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 24 deletions.
3 changes: 3 additions & 0 deletions addresses/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions addresses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 29 additions & 5 deletions addresses/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -175,17 +176,14 @@ 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,
auth_user=auth_user,
blockcypher_id=bcy_id,
)

if already_authenticated:
if already_authenticated and auth_user.email_verified:
msg = _('You will now be emailed notifications for <b>%(coin_address)s</b>' % {'coin_address': coin_address})
messages.success(request, msg, extra_tags='safe')
return HttpResponseRedirect(reverse('dashboard'))
Expand All @@ -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
Expand All @@ -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" % {
Expand Down
1 change: 1 addition & 0 deletions blockexplorer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsub_code>[-\w]+)/$', 'addresses.views.unsubscribe_address', name='unsubscribe_address'),
url(r'^remove-subscription/(?P<address_subscription_id>[-\w]+)/$', 'addresses.views.user_unsubscribe_address', name='user_unsubscribe_address'),
url(r'^dashboard/?$', 'users.views.dashboard', name='dashboard'),

# Webhooks:
Expand Down
12 changes: 11 additions & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,24 @@
{# Including the messages for the homepage in the home template #}
{% else %}
<div class="main-container">
{# Page Header Stuff #}
<div class="page-header">
<div class="container">
<h1>
{% block page_header %}
Dashboard
{% endblock page_header %}
</h1>
</div>
</div>
{% include "partials/messages.html" %}
{% endif %}

{# Begin page content #}
{% block content %}
{% endblock content %}

</div>
</div>

{# Footer #}

Expand Down
27 changes: 12 additions & 15 deletions templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

<div class="page-header">
<div class="container">
<h1>
Dashboard
</h1>
</div>
</div>
{% block content %}

{% if not user.email_verified %}
<div class="container">
<div class="row">
<div class="col-sm-12" id="messages">
<div class="col-sm-12">
<div class="nofadeout alert alert-danger">
Your email address (<b>{{ user.email }}</b>) has not been confirmed.<br />
Please check your email and click the link to activate subscriptions.
Expand All @@ -38,7 +30,12 @@ <h1>
<div class="row">
<p>User Info</p>
<ul>
<li>Email: {{ user.email }}</li>
<li>
Email: {{ user.email }}
{% if user.email_verified %}
(verified)
{% endif %}
</li>
<li><a href="{% url 'change_password' %}">Change Password</a></li>
</ul>
</div>
Expand All @@ -50,7 +47,7 @@ <h1>
<li>
<a href="{% url 'address_overview' address_subscription.coin_symbol address_subscription.b58_address %}"
>{{ address_subscription.coin_symbol|coin_symbol_to_display_name }} address {{ address_subscription.b58_address }}</a>
(<a href="#">delete</a>)
(<a href="{% url 'user_unsubscribe_address' address_subscription.id %}">delete</a>)
</li>
{% endfor %}
</ul>
Expand All @@ -59,7 +56,7 @@ <h1>
You have no subscriptions.
</p>
{% endif %}
<a href="{% url 'subscribe_address' 'btc' %}">Subscribe to Another Address</a>
<a href="{% url 'subscribe_address' 'btc' %}">+ Subscribe to Another Address</a>
</div>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion templates/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ <h1>
</div>

<div class="form-page">
{% include "partials/messages.html" %}
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
Expand Down
2 changes: 1 addition & 1 deletion users/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)

Expand Down
3 changes: 2 additions & 1 deletion users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 58a59a4

Please sign in to comment.