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

Commit

Permalink
branch merge with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
shivkumarsah committed Jul 14, 2017
2 parents 75fac8b + 9c9bdeb commit 45a856a
Show file tree
Hide file tree
Showing 6 changed files with 689 additions and 49 deletions.
87 changes: 86 additions & 1 deletion cloud/endagaweb/templates/dashboard/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,45 @@ <h4>No events match these filters!</h4>
</span>
</div>
</div>
<div class='modal fade' id='pwd-dialog-modal'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header'>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 class='modal-title'>
<p>Hello <strong>{{ user_profile.display_name }}</strong>, please enter your password for authorization.</p>
</h4>
</div>
<div class='modal-body'>
<div id='messages-container'></div>
<form id='password-authorization'>
<div class='form-group'>
<div class='controls'>
<input class='textinput textInput form-control' id='pwd-input' name='pwd' type='password'>
</div>
</div><!-- /.form-group -->

</form>
</div> <!-- /.modal-body -->
<div class='modal-footer' id="modal-footerId">
<button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
<button class='btn btn-primary' type='button' id='pwd-dialog-submit'>
OK
</button>
</div>
</div>
</div>
</div>

<div class="row">
<div class="col-xs-12">
<p>
{% if event_count > 100000 %}
Too many results to export, try a shorter date range.
{% elif event_count > 0 %}
<a href="?page={{ events.number }}&csv=1">Export results as CSV</a>
<a href='#' data-toggle='modal' data-target='#pwd-dialog-modal'>Export results as CSV</a>
{% endif %}
</p>
</div>
Expand All @@ -175,4 +206,58 @@ <h4>No events match these filters!</h4>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.14.30/js/bootstrap-datetimepicker.min.js"></script>
<script src="/static/js/dashboard/activity.js"></script>
<script>

// Handle clicks on the pwd-dialog-submit button.
$('#pwd-dialog-submit').click(function() {
submitPwdDialogData();
});

// Handle <enter> keypress on pwd-dialog-submit.
$('input, #pwd-dialog-submit').keypress(function(e) {
if (e.keyCode == 13) {
e.preventDefault();
submitPwdDialogData();
}
});

$('#pwd-dialog-modal').on('hide.bs.modal', function (e) {
$(this).find('form').trigger('reset');
});

function submitPwdDialogData() {

var data = {
password: $('#pwd-input').val(),
csrfmiddlewaretoken: '{{ csrf_token }}',
};
$.post('/dashboard/activity', data, function(response) {
if (response['status'] == 'ok') {
// Clear out any old messages and show the div again.
$('#messages-container').html();
$('#messages-container').css('opacity', 1);
var message = 'Password Authorization Successful.';
var html = '<div class="alert alert-success">' + message + '</div>';
$('#messages-container').html(html);
setTimeout(function() {
window.location="?page={{ events.number }}&csv=1"
$('#pwd-dialog-modal').modal('hide');
$('#messages-container').fadeTo(200, 0);
}, 2000);
} else {
$('#messages-container').html();
$('#messages-container').css('opacity', 1);
var message = 'Incorrect password.';
var html = '<div class="alert alert-danger">' + message + '</div>';
$('#messages-container').html(html);
setTimeout(function() {
$('#messages-container').html("")
$('#pwd-input').val("");
}, 2000);
}
});
}

</script>

{% endblock %}
10 changes: 8 additions & 2 deletions cloud/endagaweb/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
import stripe
from guardian.shortcuts import get_objects_for_user

from ccm.common.currency import parse_credits, humanize_credits, \
CURRENCIES, Money
from ccm.common.currency import parse_credits, humanize_credits, CURRENCIES
from endagaweb.models import (UserProfile, Subscriber, UsageEvent,
Network, PendingCreditUpdate, Number, BTS)
from endagaweb.util.currency import cents2mc
from endagaweb.forms import dashboard_forms as dform
from endagaweb import tasks
from endagaweb.views import django_tables
import json

class ProtectedView(View):
""" A class-based view that requires a login. """
Expand Down Expand Up @@ -693,6 +693,12 @@ def _handle_request(self, request):
request.session['end_date'] = request.POST.get('end_date', None)
request.session['services'] = request.POST.getlist('services[]',
None)
# Added to check password to download the csv
if (request.user.check_password(request.POST.get('password'))):
response = {'status': 'ok'}
return HttpResponse(json.dumps(response),
content_type="application/json")

# We always just do a redirect to GET. We include page reference
# to retain the search parameters in the session.
return redirect(urlresolvers.reverse('network-activity') +
Expand Down
Loading

0 comments on commit 45a856a

Please sign in to comment.