diff --git a/js/gratipay/packages.js b/js/gratipay/packages.js new file mode 100644 index 0000000000..9edffa7fca --- /dev/null +++ b/js/gratipay/packages.js @@ -0,0 +1,35 @@ +Gratipay.packages = {}; + +Gratipay.packages.post = function(e) { + e.preventDefault(); + var $this = $(this); + var action = 'add-email-and-claim-package'; + var $inputs = $('input, button'); + var $selection = $('input[name=email]:checked'); + var address = $selection.val(); + var package_id = $selection.parent().parent().data('package-id'); + + $inputs.prop('disabled', true); + + $.ajax({ + url: '/~' + Gratipay.username + '/emails/modify.json', + type: 'POST', + data: {action: action, address: address, package_id: package_id}, + dataType: 'json', + success: function (msg) { + if (msg) { + Gratipay.notification(msg, 'success'); + } + if (action == 'add-email') { + $('input.add-email').val(''); + setTimeout(function(){ window.location.reload(); }, 3000); + return; + } + $inputs.prop('disabled', false); + }, + error: [ + function () { $inputs.prop('disabled', false); }, + Gratipay.error + ], + }); +}; diff --git a/tests/ttw/test_package_claiming.py b/tests/ttw/test_package_claiming.py index 4d6a9b7c86..7de9d2de82 100644 --- a/tests/ttw/test_package_claiming.py +++ b/tests/ttw/test_package_claiming.py @@ -8,10 +8,11 @@ class Tests(BrowserHarness): def test_sending_a_confirmation_email_works(self): self.make_package() - self.make_participant('alice', claimed_time='now') - self.sign_in('alice') + self.make_participant('bob', claimed_time='now') + self.sign_in('bob') self.visit('/on/npm/foo/') - self.css('input[type=radio]').click() - self.css('button').click() + self.css('input[type=radio]')[0].click() + #import pdb; pdb.set_trace() + self.css('button')[0].click() assert self.has_element('.notification.notification-success', 1) - assert self.has_text('A confirmation email has been sent') + assert self.has_text('Check your inbox for a confirmation email.') diff --git a/www/on/npm/%package/index.html.spt b/www/on/npm/%package/index.html.spt index 5fa163ba7f..b97a787f9b 100644 --- a/www/on/npm/%package/index.html.spt +++ b/www/on/npm/%package/index.html.spt @@ -26,6 +26,15 @@ url = 'https://npmjs.com/package/' + package.name {% endblock %} +{% block scripts %} + +{{ super() }} +{% endblock %} + {% block content %}

{{ _( '{npm_package} has not been claimed on Gratipay.' , npm_package=('' + 'npm/' + package_name + '')|safe @@ -40,14 +49,13 @@ url = 'https://npmjs.com/package/' + package.name {% else %}

{{ _('Is this yours? You can claim it on Gratipay with one of these email addresses:') }}

-
- - - -
+ + + {% endif %} {% endblock %} diff --git a/www/~/%username/emails/modify.json.spt b/www/~/%username/emails/modify.json.spt index 2451879bb5..96dff4e0c4 100644 --- a/www/~/%username/emails/modify.json.spt +++ b/www/~/%username/emails/modify.json.spt @@ -6,6 +6,7 @@ import re from aspen import Response from gratipay.exceptions import ProblemChangingEmail from gratipay.utils import get_participant +from gratipay.models import Package email_re = re.compile(r'^[^@]+@[^@]+\.[^@]+$') @@ -36,6 +37,10 @@ elif action == 'set-primary': participant.update_email(address) elif action == 'remove': participant.remove_email(address) +elif action == 'add-email-and-claim-package': + package_id = request.body['package_id'] + package = Package.from_id(package_id) + package.send_confirmation_email(address) else: raise Response(400, 'unknown action "%s"' % action)