Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Shelve
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Feb 8, 2017
1 parent 9e090cb commit af0ea7b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 14 deletions.
35 changes: 35 additions & 0 deletions js/gratipay/packages.js
Original file line number Diff line number Diff line change
@@ -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
],
});
};
11 changes: 6 additions & 5 deletions tests/ttw/test_package_claiming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
26 changes: 17 additions & 9 deletions www/on/npm/%package/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ url = 'https://npmjs.com/package/' + package.name
</a>
{% endblock %}

{% block scripts %}
<script>
$(document).ready(function() {
$('button.send').on('click', Gratipay.packages.post);
});
</script>
{{ super() }}
{% endblock %}

{% block content %}
<h2>{{ _( '{npm_package} has not been claimed on Gratipay.'
, npm_package=('<a href="' + url + '">' + 'npm/' + package_name + '</a>')|safe
Expand All @@ -40,14 +49,13 @@ url = 'https://npmjs.com/package/' + package.name
{% else %}
<p>{{ _('Is this yours? You can claim it on Gratipay with one of these email addresses:')
}}</p>
<form action="" method="POST">
<input type="hidden" name="csrf_token" value="{{ csrf_token }}">
<ul>
{% for email in package.emails %}
<li><input type="radio" name="email"> {{ email }}</li>
{% endfor %}
</ul>
<button type="submit">{{ _('Send confirmation link') }}</button>
</form>

<ul data-package-id="{{ package.id }}">
{% for i, email in enumerate(package.emails) %}
<li><input type="radio" name="email" value="{{ email }}" id="email-{{i}}">
<label for="email-{{ i }}">{{ email }}</a></li>
{% endfor %}
</ul>
<button type="submit" class="send">{{ _('Send confirmation link') }}</button>
{% endif %}
{% endblock %}
5 changes: 5 additions & 0 deletions www/~/%username/emails/modify.json.spt
Original file line number Diff line number Diff line change
Expand Up @@ -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'^[^@]+@[^@]+\.[^@]+$')

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit af0ea7b

Please sign in to comment.