mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Added API access display to the profile page
This commit is contained in:
7
app/eve_api/templates/eve_api/accessview.html
Normal file
7
app/eve_api/templates/eve_api/accessview.html
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<div class="content">
|
||||||
|
{% for x, y in access %}
|
||||||
|
{% if y %}
|
||||||
|
<span class="label {% if y %}success{% else %}important{% endif %}">{{ x }}</span><br/>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
from django.conf.urls.defaults import *
|
from django.conf.urls.defaults import *
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
from eve_api import views
|
from eve_api import views
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^eveapi/add/', views.eveapi_add, name="eveapi-add"),
|
url(r'^eveapi/add/$', views.eveapi_add, name="eveapi-add"),
|
||||||
url(r'^eveapi/update/(?P<userid>\d+)/$', views.eveapi_update, name="eveapi-update"),
|
url(r'^eveapi/update/(?P<userid>\d+)/$', views.eveapi_update, name="eveapi-update"),
|
||||||
url(r'^eveapi/delete/(?P<userid>\d+)/$', views.eveapi_del, name="eveapi-delete"),
|
url(r'^eveapi/delete/(?P<userid>\d+)/$', views.eveapi_del, name="eveapi-delete"),
|
||||||
url(r'^eveapi/refresh/(?P<userid>\d+)/$', views.eveapi_refresh, name="eveapi-refresh"),
|
url(r'^eveapi/refresh/(?P<userid>\d+)/$', views.eveapi_refresh, name="eveapi-refresh"),
|
||||||
url(r'^eveapi/log/(?P<userid>\d+)/$', views.eveapi_log, name="eveapi-log"),
|
url(r'^eveapi/log/(?P<userid>\d+)/$', views.eveapi_log, name="eveapi-log"),
|
||||||
|
url(r'^eveapi/access/(?P<slug>\d+)/$', login_required(views.EVEAPIAccessView.as_view()), name="eveapi-accessview"),
|
||||||
|
|
||||||
url(r'^character/list/$', views.eveapi_character, name="eveapi-characters-list"),
|
url(r'^character/list/$', views.eveapi_character, name="eveapi-characters-list"),
|
||||||
url(r'^character/(?P<charid>\d+)/$', views.eveapi_character, name="eveapi-character"),
|
url(r'^character/(?P<charid>\d+)/$', views.eveapi_character, name="eveapi-character"),
|
||||||
|
|||||||
@@ -1,24 +1,25 @@
|
|||||||
import csv
|
import csv
|
||||||
|
|
||||||
import celery
|
from django.core import serializers
|
||||||
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.shortcuts import render_to_response, get_object_or_404, redirect
|
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.http import HttpResponse, Http404
|
||||||
|
from django.shortcuts import render_to_response, get_object_or_404, redirect
|
||||||
|
from django.template import RequestContext
|
||||||
|
from django.views.generic import DetailView
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.template import RequestContext
|
|
||||||
from django.http import Http404
|
|
||||||
from django.core import serializers
|
|
||||||
|
|
||||||
|
import celery
|
||||||
from gargoyle import gargoyle
|
from gargoyle import gargoyle
|
||||||
|
|
||||||
from eve_proxy.models import ApiAccessLog
|
from eve_proxy.models import ApiAccessLog, CachedDocument
|
||||||
from eve_proxy.exceptions import DocumentRetrievalError
|
from eve_proxy.exceptions import DocumentRetrievalError
|
||||||
from eve_api.app_defines import *
|
from eve_api.app_defines import *
|
||||||
from eve_api.forms import EveAPIForm
|
from eve_api.forms import EveAPIForm
|
||||||
from eve_api.models import EVEAccount, EVEPlayerCharacter, EVEPlayerCorporation, EVEPlayerAlliance
|
from eve_api.models import EVEAccount, EVEPlayerCharacter, EVEPlayerCorporation, EVEPlayerAlliance
|
||||||
from eve_api.tasks import import_apikey_result
|
from eve_api.tasks import import_apikey_result
|
||||||
|
from eve_api.utils import basic_xml_parse_doc
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@@ -233,3 +234,34 @@ def eveapi_alliance(request, allianceid, template='eve_api/alliance.html'):
|
|||||||
}
|
}
|
||||||
return render_to_response(template, context, context_instance=RequestContext(request))
|
return render_to_response(template, context, context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
|
class EVEAPIAccessView(DetailView):
|
||||||
|
|
||||||
|
model = EVEAccount
|
||||||
|
template_name = 'eve_api/accessview.html'
|
||||||
|
slug_field = 'api_user_id'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def lowestSet(int_type):
|
||||||
|
low = (int_type & -int_type)
|
||||||
|
lowBit = -1
|
||||||
|
while (low):
|
||||||
|
low >>= 1
|
||||||
|
lowBit += 1
|
||||||
|
return(lowBit)
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
ctx = super(EVEAPIAccessView, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
|
calls = basic_xml_parse_doc(CachedDocument.objects.api_query('/api/CallList.xml.aspx'))['eveapi']['result']
|
||||||
|
if self.object.api_keytype == API_KEYTYPE_CORPORATION:
|
||||||
|
typ = 'Corporation'
|
||||||
|
else:
|
||||||
|
typ = 'Character'
|
||||||
|
|
||||||
|
ctx['access'] = []
|
||||||
|
for row in [x for x in calls['calls'] if x['type'] == typ]:
|
||||||
|
bit = self.lowestSet(int(row['accessMask']))
|
||||||
|
ctx['access'].append((row['name'], self.object.has_access(bit)))
|
||||||
|
|
||||||
|
return ctx
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
<script src="{{ STATIC_URL }}bootstrap/js/bootstrap-tabs.js"></script>
|
<script src="{{ STATIC_URL }}bootstrap/js/bootstrap-tabs.js"></script>
|
||||||
<script src="{{ STATIC_URL }}js/jquery.tablesorter.min.js"></script>
|
<script src="{{ STATIC_URL }}js/jquery.tablesorter.min.js"></script>
|
||||||
|
<script src="{{ STATIC_URL }}bootstrap/js/bootstrap-twipsy.js"></script>
|
||||||
|
<script src="{{ STATIC_URL }}bootstrap/js/bootstrap-popover.js"></script>
|
||||||
|
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>Your Profile</h1>
|
<h1>Your Profile</h1>
|
||||||
@@ -91,7 +93,7 @@
|
|||||||
<td>{{ acc.api_user_id }}</td>
|
<td>{{ acc.api_user_id }}</td>
|
||||||
<td>{{ acc.api_key|slice:":10" }}…</td>
|
<td>{{ acc.api_key|slice:":10" }}…</td>
|
||||||
<td>{{ acc.description }}</td>
|
<td>{{ acc.description }}</td>
|
||||||
<td>{{ acc.get_api_keytype_display }}{% if acc.api_keytype == 4 %} <b><sup style="color: red;">*</sup></b>{% endif %}</td>
|
<td><a href="#" class="accesspopup" id="{{ acc.api_user_id}}" data-original-title="Access for Key {{ acc.api_user_id }}" data-content="test" rel="popover">{{ acc.get_api_keytype_display }}</a>{% if acc.api_keytype == 4 %} <b><sup style="color: red;">*</sup></b>{% endif %}</td>
|
||||||
<td id="api-status-{{ acc.api_user_id }}">{{ acc.get_api_status_display }}</td>
|
<td id="api-status-{{ acc.api_user_id }}">{{ acc.get_api_status_display }}</td>
|
||||||
<td id="api-time-{{ acc.api_user_id }}">{{ acc.api_last_updated|naturaltimediff }}</td>
|
<td id="api-time-{{ acc.api_user_id }}">{{ acc.api_last_updated|naturaltimediff }}</td>
|
||||||
<td>{% ifswitch api-disableprocessing %}{% else %}<a href="{% url eve_api.views.eveapi_refresh acc.api_user_id %}" onclick="javascript:refresh_apikey({{ acc.api_user_id }}); return false;">Refresh</a>,
|
<td>{% ifswitch api-disableprocessing %}{% else %}<a href="{% url eve_api.views.eveapi_refresh acc.api_user_id %}" onclick="javascript:refresh_apikey({{ acc.api_user_id }}); return false;">Refresh</a>,
|
||||||
@@ -177,14 +179,27 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script type="text/javascript">
|
||||||
$(function () {
|
|
||||||
$('.tabs').tabs()
|
|
||||||
})
|
|
||||||
|
|
||||||
$(function() {
|
access_popover = function(e) {
|
||||||
$("table#eveapikeys").tablesorter({ sortList: [[0,0]] });
|
e.preventDefault();
|
||||||
});
|
var el = $(this);
|
||||||
|
var id = $(this).attr('id');
|
||||||
|
$.ajax({
|
||||||
|
type: 'GET',
|
||||||
|
url: '/eve/eveapi/access/' + id + '/',
|
||||||
|
dataType: 'html',
|
||||||
|
success: function(data) {
|
||||||
|
el.attr('data-content', data);
|
||||||
|
el.popover('show');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.tabs').tabs();
|
||||||
|
$("table#eveapikeys").tablesorter({ sortList: [[0,0]] });
|
||||||
|
$('.accesspopup').popover({html: 'true', trigger: 'manual'});
|
||||||
|
$('.accesspopup').hover(access_popover, function () { $(this).popover('hide') });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
//background-image: -o-linear-gradient(top, #333333, #5F6757);
|
//background-image: -o-linear-gradient(top, #333333, #5F6757);
|
||||||
//background-image: linear-gradient(top, #333333, #5F6757);
|
//background-image: linear-gradient(top, #333333, #5F6757);
|
||||||
}
|
}
|
||||||
div.content {
|
.container div.content {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
margin: 0 -20px;
|
margin: 0 -20px;
|
||||||
|
|||||||
Reference in New Issue
Block a user