Replace API Key page with Dashboard profile

Closes #582
This commit is contained in:
Adarnof 2016-12-29 17:13:07 -05:00
commit 33e481fb12
8 changed files with 141 additions and 142 deletions

View File

@ -177,7 +177,7 @@ urlpatterns += i18n_patterns(
django.contrib.auth.views.password_reset_confirm, name='password_reset_confirm'), django.contrib.auth.views.password_reset_confirm, name='password_reset_confirm'),
# Portal Urls # Portal Urls
url(_(r'^dashboard/$'), authentication.views.dashboard_view, name='auth_dashboard'), url(_(r'^dashboard/$'), eveonline.views.dashboard_view, name='auth_dashboard'),
url(_(r'^help/$'), authentication.views.help_view, name='auth_help'), url(_(r'^help/$'), authentication.views.help_view, name='auth_help'),
# Eveonline Urls # Eveonline Urls

View File

@ -88,19 +88,12 @@ def index_view(request):
return render(request, 'public/index.html') return render(request, 'public/index.html')
@login_required
def dashboard_view(request):
logger.debug("dashboard_view called by user %s" % request.user)
render_items = {'characters': EveManager.get_characters_by_owner_id(request.user.id),
'authinfo': AuthServicesInfo.objects.get_or_create(user=request.user)[0]}
return render(request, 'registered/dashboard.html', context=render_items)
@login_required @login_required
def help_view(request): def help_view(request):
logger.debug("help_view called by user %s" % request.user) logger.debug("help_view called by user %s" % request.user)
return render(request, 'registered/help.html') return render(request, 'registered/help.html')
@token_required(new=True) @token_required(new=True)
def sso_login(request, tokens=[]): def sso_login(request, tokens=[]):
token = tokens[0] token = tokens[0]
@ -109,7 +102,7 @@ def sso_login(request, tokens=[]):
if char.user: if char.user:
if char.user.is_active: if char.user.is_active:
login(request, char.user) login(request, char.user)
return redirect(dashboard_view) return redirect('auth_dashboard')
else: else:
messages.error(request, 'Your account has been disabled.') messages.error(request, 'Your account has been disabled.')
else: else:

View File

@ -227,6 +227,10 @@ class EveManager:
return None return None
@staticmethod
def get_characters_by_api_id(api_id):
return EveCharacter.objects.filter(api_id=api_id)
@staticmethod @staticmethod
def get_charater_alliance_id_by_id(char_id): def get_charater_alliance_id_by_id(char_id):
if EveCharacter.objects.filter(character_id=char_id).exists(): if EveCharacter.objects.filter(character_id=char_id).exists():

View File

@ -55,7 +55,7 @@ def add_api_key(request):
auth = AuthServicesInfo.objects.get_or_create(user=request.user)[0] auth = AuthServicesInfo.objects.get_or_create(user=request.user)[0]
if not auth.main_char_id: if not auth.main_char_id:
return redirect('auth_characters') return redirect('auth_characters')
return redirect("/api_key_management/") return redirect("auth_dashboard")
else: else:
logger.debug('Requesting SSO validation of API %s by user %s' % (api_key.api_id, request.user)) logger.debug('Requesting SSO validation of API %s by user %s' % (api_key.api_id, request.user))
return render(request, 'registered/apisso.html', context={'api':api_key}) return render(request, 'registered/apisso.html', context={'api':api_key})
@ -76,11 +76,11 @@ def api_sso_validate(request, tokens, api_id):
if api.user and api.user != request.user: if api.user and api.user != request.user:
logger.warning('User %s attempting to take ownership of api %s from %s' % (request.user, api_id, api.user)) logger.warning('User %s attempting to take ownership of api %s from %s' % (request.user, api_id, api.user))
messages.warning(request, 'API %s already claimed by user %s' % (api_id, api.user)) messages.warning(request, 'API %s already claimed by user %s' % (api_id, api.user))
return redirect('auth_api_key_management') return redirect('auth_dashboard')
elif api.sso_verified: elif api.sso_verified:
logger.debug('API %s has already been verified.' % api_id) logger.debug('API %s has already been verified.' % api_id)
messages.info(request, 'API %s has already been verified' % api_id) messages.info(request, 'API %s has already been verified' % api_id)
return redirect('auth_api_key_management') return redirect('auth_dashboard')
token = tokens[0] token = tokens[0]
logger.debug('API %s has not been verified. Checking if token for %s matches.' % (api_id, token.character_name)) logger.debug('API %s has not been verified. Checking if token for %s matches.' % (api_id, token.character_name))
characters = EveApiManager.get_characters_from_api(api.api_id, api.api_key).result characters = EveApiManager.get_characters_from_api(api.api_id, api.api_key).result
@ -93,7 +93,7 @@ def api_sso_validate(request, tokens, api_id):
auth, c = AuthServicesInfo.objects.get_or_create(user=request.user) auth, c = AuthServicesInfo.objects.get_or_create(user=request.user)
if not auth.main_char_id: if not auth.main_char_id:
return redirect('auth_characters') return redirect('auth_characters')
return redirect('auth_api_key_management') return redirect('auth_dashboard')
else: else:
messages.warning(request, '%s not found on API %s. Please SSO as a character on the API.' % (token.character_name, api.api_id)) messages.warning(request, '%s not found on API %s. Please SSO as a character on the API.' % (token.character_name, api.api_id))
return render(request, 'registered/apisso.html', context={'api':api}) return render(request, 'registered/apisso.html', context={'api':api})
@ -101,13 +101,33 @@ def api_sso_validate(request, tokens, api_id):
@login_required @login_required
def api_key_management_view(request): def api_key_management_view(request):
logger.debug("api_key_management_view called by user %s" % request.user) logger.debug("DEPRECIATED api_key_management_view called by user %s" % request.user)
context = { # Legacy redirect in case some links still ghost here
'apikeypairs': EveManager.get_api_key_pairs(request.user.id), return redirect('auth_dashboard')
'api_sso_validation': settings.API_SSO_VALIDATION or False
}
return render(request, 'registered/apikeymanagment.html', context=context)
@login_required
def dashboard_view(request):
logger.debug("dashboard_view called by user %s" % request.user)
auth_info = AuthServicesInfo.objects.get_or_create(user=request.user)[0]
apikeypairs = EveManager.get_api_key_pairs(request.user.id)
sso_validation = settings.API_SSO_VALIDATION or False
api_chars = []
if apikeypairs:
for api in apikeypairs:
api_chars.append({
'id': api.api_id,
'sso_verified': api.sso_verified if sso_validation else True,
'characters': EveManager.get_characters_by_api_id(api.api_id),
})
context = {
'main': EveManager.get_character_by_id(auth_info.main_char_id),
'apis': api_chars,
'api_sso_validation': settings.API_SSO_VALIDATION or False,
}
return render(request, 'registered/dashboard.html', context=context)
@login_required @login_required
@ -118,13 +138,11 @@ def api_key_removal(request, api_id):
EveManager.delete_characters_by_api_id(api_id, request.user.id) EveManager.delete_characters_by_api_id(api_id, request.user.id)
messages.success(request, 'Deleted API key %s' % api_id) messages.success(request, 'Deleted API key %s' % api_id)
logger.info("Succesfully processed api delete request by user %s for api %s" % (request.user, api_id)) logger.info("Succesfully processed api delete request by user %s for api %s" % (request.user, api_id))
if EveCharacter.objects.filter(character_id=authinfo.main_char_id).exists(): if not EveCharacter.objects.filter(character_id=authinfo.main_char_id).exists():
return redirect("auth_api_key_management")
else:
authinfo.main_char_id = None authinfo.main_char_id = None
authinfo.save() authinfo.save()
set_state(request.user) set_state(request.user)
return redirect("auth_characters") return redirect("auth_dashboard")
@login_required @login_required
@ -142,7 +160,7 @@ def main_character_change(request, char_id):
AuthServicesInfoManager.update_main_char_id(char_id, request.user) AuthServicesInfoManager.update_main_char_id(char_id, request.user)
messages.success(request, 'Changed main character ID to %s' % char_id) messages.success(request, 'Changed main character ID to %s' % char_id)
set_state(request.user) set_state(request.user)
return redirect("auth_characters") return redirect("auth_dashboard")
messages.error(request, 'Failed to change main character - selected character is not owned by your account.') messages.error(request, 'Failed to change main character - selected character is not owned by your account.')
return redirect("auth_characters") return redirect("auth_characters")
@ -162,4 +180,4 @@ def user_refresh_api(request, api_id):
else: else:
messages.warning(request, 'Unable to locate API key %s' % api_id) messages.warning(request, 'Unable to locate API key %s' % api_id)
logger.warn("User %s unable to refresh api id %s - api key not found" % (request.user, api_id)) logger.warn("User %s unable to refresh api id %s - api key not found" % (request.user, api_id))
return redirect("auth_api_key_management") return redirect("auth_dashboard")

View File

@ -110,12 +110,6 @@
</a> </a>
</li> </li>
<li>
<a class="{% navactive request 'auth_api_key_management auth_add_api_key' %}" href="{% url 'auth_api_key_management' %}">
<i class="fa fa-key fa-fw grayiconecolor"></i>{% trans " Api Keys" %}
</a>
</li>
<li> <li>
<a class="{% navactive request 'auth_characters' %}" href="{% url 'auth_characters' %}"> <a class="{% navactive request 'auth_characters' %}" href="{% url 'auth_characters' %}">
<i class="fa fa-users fa-fw grayiconecolor"></i>{% trans " Characters" %} <i class="fa fa-users fa-fw grayiconecolor"></i>{% trans " Characters" %}

View File

@ -71,7 +71,7 @@
</div> </div>
<div class="col-lg-10 col-sm-2"> <div class="col-lg-10 col-sm-2">
<div class="alert alert-danger" role="alert">Character not registered!</div> <div class="alert alert-danger" role="alert">Character not registered!</div>
This character is not part of any registered API-key. You must go to <a href=" {% url 'auth_api_key_management' %}">API key management</a> and add an API with the character on before being able to click fleet attendance links. This character is not part of any registered API-key. You must go to <a href=" {% url 'auth_dashboard' %}">API key management</a> and add an API with the character on before being able to click fleet attendance links.
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,64 +0,0 @@
{% extends "public/base.html" %}
{% load bootstrap %}
{% load staticfiles %}
{% load i18n %}
{% block title %}Alliance Auth{% endblock %}
{% block page_title %}{% trans "API Key Management" %}{% endblock page_title %}
{% block extra_css %}{% endblock extra_css %}
{% block content %}
<div class="col-lg-6 col-lg-offset-3">
<div class="row">
<h1 class="page-header text-center">{% trans "API Key Management" %}
<div class="text-right">
<a href="{% url 'auth_add_api_key' %}" class="btn btn-success">{% trans "Add Key" %}</a>
</div>
</h1>
{% if apikeypairs %}
<table class="table">
<tr>
<th class="text-center">{% trans "API ID" %}</th>
{% if api_sso_validation %}
<th class="text-center">{% trans "SSO Verified" %}</th>
{% endif %}
<th class="text-center">{% trans "Action" %}</th>
</tr>
{% for pair in apikeypairs %}
<tr>
<td class="text-center">{{ pair.api_id }}</td>
{% if api_sso_validation %}
<th class="text-center" style="font-size: 2em;">
{% if pair.sso_verified %}
<span class="glyphicon glyphicon-ok text-success" title="API key verified"></span>
{% else %}
<span class="glyphicon glyphicon-remove text-danger" title="API key not verified">
</span>
{% endif %}
</th>
{% endif %}
<td class="text-center">
<a href="{% url 'auth_user_refresh_api' pair.api_id %}" class="btn btn-success">
<span class="glyphicon glyphicon-refresh"></span>
</a>
<a href="{% url 'auth_api_key_removal' pair.api_id %}" class="btn btn-danger">
<span class="glyphicon glyphicon-remove"></span>
</a>
{% if api_sso_validation and not pair.sso_verified %}
<a href="{% url 'auth_api_sso' pair.api_id %}" class="btn btn-info"
title="EVE SSO verify this key">
<i class="fa fa-shield" aria-hidden="true"></i>
</a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
<div class="alert alert-danger" role="alert">{% trans "No api keys found" %}</div>
{% endif %}
</div>
</div>
{% endblock content %}

View File

@ -1,52 +1,62 @@
{% extends "public/base.html" %} {% extends "public/base.html" %}
{% load staticfiles %}
{% load i18n %} {% load i18n %}
{% block title %}Alliance Auth{% endblock %}
{% block page_title %}{% trans "Dashboard" %}{% endblock page_title %} {% block title %}{% trans "Dashboard" %}{% endblock %}
{% block content %} {% block content %}
<div class="col-lg-12"> <div class="col-lg-12">
<h1 class="page-header text-center">{% trans "Dashboard" %}</h1> <h1 class="page-header text-center">{% trans "Dashboard" %}</h1>
{% if STATE == MEMBER_STATE or user.is_superuser%} <div class="col-lg-12 container">
<div class="col-lg-12 container" id="example">
<div class="row"> <div class="row">
<div class="col-lg-6"> <div class="col-lg-6 text-center">
{% for character in characters %} <div class="panel panel-primary">
{% ifequal character.character_id authinfo.main_char_id %} <div class="panel-heading">{% trans "Main Character" %}</div>
<div class="panel panel-default">
<div class="panel-heading">{% trans "Main character" %}</div>
<div class="panel-body"> <div class="panel-body">
<div class="col-lg-5 col-sm-2"> {% if main %}
<img class="ra-avatar img-responsive" src="https://image.eveonline.com/Character/{{ character.character_id }}_128.jpg"> <div class="col-lg-4 col-sm-2">
<table class="table">
<tr><td class="text-center"><img class="ra-avatar" src="https://image.eveonline.com/Character/{{ main.character_id }}_128.jpg"></td></tr>
<tr><td class="text-center">{{ main.character_name }}</td></tr>
</table>
</div> </div>
<div class="col-lg-4 col-sm-2">
<div class="col-lg-7 col-sm-2"> <table class="table">
<h4 class="">{{ character.character_name }}</h4> <tr><td class="text-center"><img class="ra-avatar" src="http://image.eveonline.com/Corporation/{{ main.corporation_id }}_128.png"></td></tr>
<tr><td class="text-center">{{ main.corporation_name }}</td></tr>
<p>{{ character.corporation_name }}</p> </table>
</div>
<p>{{ character.alliance_name }}</p> <div class="col-lg-4 col-sm-2">
{% if main.alliance_id != '0' %}
<table class="table">
<tr><td class="text-center"><img class="ra-avatar" src="https://image.eveonline.com/Alliance/{{ main.alliance_id }}_128.png"></td></tr>
<tr><td class="text-center">{{ main.alliance_name }}</td><tr>
</table>
{% endif %}
</div>
{% else %}
<div class="alert alert-danger" role="alert">Missing main character model.</div>
{% endif %}
<div class="clearfix"></div>
<div class="col-sm-6">
<a href="{% url 'auth_add_api_key' %}" class="btn btn-block btn-success" label="Add API Key">Add API Key</a>
</div>
<div class="col-sm-6">
<a href="{% url 'auth_characters' %}" class="btn btn-block btn-info" label="Change Main Character">Change Main</a>
</div> </div>
</div> </div>
</div> </div>
{% endifequal %}
{% endfor %}
</div> </div>
<div class="col-lg-6 text-center">
<div class="panel panel-success">
<div class="col-lg-6">
<div class="panel panel-default">
<div class="panel-heading">{% trans "Groups" %}</div> <div class="panel-heading">{% trans "Groups" %}</div>
<div class="panel-body"> <div class="panel-body">
<div style="height: 128px;overflow:-moz-scrollbars-vertical;overflow-y:auto;"> <div style="height: 236px;overflow:-moz-scrollbars-vertical;overflow-y:auto;">
<table class="table table-striped"> <table class="table table-striped">
{% for group in user.groups.all %} {% for group in user.groups.all %}
<tr> <tr>
<td> <td>
<p class="">{{ group.name }}</p> <p>{{ group.name }}</p>
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
@ -55,15 +65,59 @@
</div> </div>
</div> </div>
</div> </div>
<div class="clearfix"></div>
{% if apis %}
{% for api in apis %}
<div class="panel panel-{{ api.sso_verified|yesno:"success,warning,default" }}">
<div class="panel-heading" style="display:flex;">
<div style="width: 25%;" title="{% if not api.sso_verified and api_sso_validation %}{% trans "API Key requires EVE SSO verification" %}{% else %}{% trans "API Key is valid" %}{% endif %}">
{% trans "API ID" %} {{ api.id }} <span class="glyphicon glyphicon-{{ api.sso_verified|yesno:"ok-sign,warning-sign,question-sign" }}"></span>
</div> </div>
</div> <div class="text-right" style="width: 75%;">
{% else %} <a href="{% url 'auth_user_refresh_api' api.id %}" class="btn btn-primary" title="Update"><span class="glyphicon glyphicon-refresh"></span></a>
{% if IS_CORP %} <a href="{% url 'auth_api_key_removal' api.id %}" class="btn btn-danger" title="Delete"><span class="glyphicon glyphicon-remove"></span></a>
<div class="alert alert-danger" role="alert">{% trans "Not a part of the corporation." %}</div> {% if api_sso_validation and not api.sso_verified %}
{% else %} <a href="{% url 'auth_api_sso' api.id %}" class="btn btn-info"
<div class="alert alert-danger" role="alert">{% trans "Not a part of the alliance." %}</div> title="EVE SSO verify this key">
{% endif %} <span class="fa fa-shield"></span>
</a>
{% endif %} {% endif %}
</div> </div>
{% endblock content %} </div>
<table class="table">
<tr>
<th class="text-center"></th>
<th class="text-center">{% trans "Name" %}</th>
<th class="text-center">{% trans "Corp" %}</th>
<th class="text-center">{% trans "Alliance" %}</th>
</tr>
{% for char in api.characters %}
<tr>
<td class="text-center">
<img class="ra-avatar img-responsive" src="https://image.eveonline.com/Character/{{ char.character_id }}_32.jpg">
</td>
<td class="text-center">{{ char.character_name }}</td>
<td class="text-center">{{ char.corporation_name }}</td>
<td class="text-center">{{ char.alliance_name }}</td>
</tr>
{% endfor %}
{% if api.corp %}
<tr>
<td class="text-center">
<img class="ra-avatar img-responsive" src="https://image.eveonline.com/Corporation/{{ api.corporation_id }}_32.png">
</td>
<td class="text-center"></td>
<td class="text-center">{{ api.corporation_name }}</td>
<td class="text-center">{{ api.alliance_name }}</td>
</tr>
{% endif %}
</table>
</div>
{% endfor %}
{% else %}
<div class="alert alert-danger" role="alert">{% trans "No API keys found" %}</div>
{% endif %}
</div>
</div>
</div>
{% endblock %}