FAT uses ESI tokens to get character location/ship

Closes #564
This commit is contained in:
Adarnof 2016-12-11 22:10:05 -05:00
parent a630b5b397
commit b4b739ee61
5 changed files with 106 additions and 226 deletions

View File

@ -13,6 +13,8 @@ from eveonline.managers import EveManager
from fleetactivitytracking.forms import FatlinkForm from fleetactivitytracking.forms import FatlinkForm
from fleetactivitytracking.models import Fatlink, Fat from fleetactivitytracking.models import Fatlink, Fat
from esi.decorators import token_required
from slugify import slugify from slugify import slugify
from collections import OrderedDict from collections import OrderedDict
@ -177,51 +179,54 @@ def fatlink_monthly_personal_statistics_view(request, year, month, char_id=None)
@login_required @login_required
def click_fatlink_view(request, hash, fatname): @token_required(scopes=['esi-location.read_location.v1', 'esi-location.read_ship_type.v1', 'esi-universe.read_structures.v1'])
# Take IG-header data and register the fatlink if not existing already. def click_fatlink_view(request, token, hash, fatname):
# use obj, created = Fat.objects.get_or_create() try:
# onload="CCPEVE.requestTrust('http://www.mywebsite.com')" fatlink = Fatlink.objects.filter(hash=hash)[0]
if 'HTTP_EVE_TRUSTED' in request.META and request.META['HTTP_EVE_TRUSTED'] == "Yes": if (timezone.now() - fatlink.fatdatetime) < datetime.timedelta(seconds=(fatlink.duration * 60)):
# Retrieve the latest fatlink using the hash.
try:
fatlink = Fatlink.objects.filter(hash=hash)[0]
if (timezone.now() - fatlink.fatdatetime) < datetime.timedelta(seconds=(fatlink.duration * 60)): character = EveManager.get_character_by_id(token.character_id)
character = EveManager.get_character_by_id(request.META['HTTP_EVE_CHARID']) if character:
# get data
if character: c = token.get_esi_client()
fat = Fat() location = c.Location.get_characters_character_id_location(character_id=token.character_id).result()
fat.system = request.META['HTTP_EVE_SOLARSYSTEMNAME'] ship = c.Location.get_characters_character_id_ship(character_id=token.character_id).result()
if 'HTTP_EVE_STATIONNAME' in request.META: location['solar_system_name'] = c.Universe.get_universe_systems_system_id(system_id=location['solar_system_id']).result()['solar_system_name']
fat.station = request.META['HTTP_EVE_STATIONNAME'] if location['structure_id']:
else: location['station_name'] = c.Universe.get_universe_structures_structure_id(structure_id=location['structure_id']).result()['name']
fat.station = "No Station" elif location['station_id']:
fat.shiptype = request.META['HTTP_EVE_SHIPTYPENAME'] location['station_name'] = c.Universe.get_universe_stations_station_id(station_id=location['station_id']).result()['station_name']
fat.fatlink = fatlink
fat.character = character
fat.user = character.user
try:
fat.full_clean()
fat.save()
context = {'trusted': True, 'registered': True}
except ValidationError as e:
messages = []
for errorname, message in e.message_dict.items():
messages.append(message[0].decode())
context = {'trusted': True, 'errormessages': messages}
else: else:
context = {'character_id': request.META['HTTP_EVE_CHARID'], location['station_name'] = "No Station"
'character_name': request.META['HTTP_EVE_CHARNAME']} ship['ship_type_name'] = c.Universe.get_universe_types_type_id(type_id=ship['ship_type_id']).result()['type_name']
return render(request, 'public/characternotexisting.html', context=context)
fat = Fat()
fat.system = location['solar_system_name']
fat.station = location['station_name']
fat.shiptype = ship['ship_type_name']
fat.fatlink = fatlink
fat.character = character
fat.user = character.user
try:
fat.full_clean()
fat.save()
context = {'registered': True}
except ValidationError as e:
messages = []
for errorname, message in e.message_dict.items():
messages.append(message[0].decode())
context = {'errormessages': messages}
else: else:
context = {'trusted': True, 'expired': True} context = {'character_id': token.character_id,
except ObjectDoesNotExist: 'character_name': token.character_name}
context = {'trusted': True} return render(request, 'registered/characternotexisting.html', context=context)
else: else:
context = {'trusted': False, 'fatname': fatname} context = {'expired': True}
return render(request, 'public/clickfatlinkview.html', context=context) except (ObjectDoesNotExist, KeyError):
context = {}
return render(request, 'registered/clickfatlinkview.html', context=context)
@login_required @login_required

View File

@ -1,90 +0,0 @@
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Fleet participation</title>
<!-- Bootstrap Core CSS -->
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
<!-- Custom Fonts -->
<link href="{% static 'css/font-awesome.min.css' %}" rel="stylesheet" type="text/css">
<link href="{% static 'css/sb-admin-2.css' %}" rel="stylesheet">
{% block extra_css %}{% endblock extra_css %}
<style>
.grayiconecolor {
color: #505050;
}
</style>
</head>
<body onload=CCPEVE.requestTrust('{{ DOMAIN }}')>
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="navbar-header ">
<a class="navbar-brand " href="/dashboard/">
<div class="fa fa-cog fa-spin"></div>
{% if IS_CORP %}
{{ CORP_NAME }}
{% else %}
{{ ALLIANCE_NAME }}
{% endif %}
</a>
</div>
<!-- /.navbar-header -->
<ul class="nav navbar-top-links navbar-right">
{% if user.is_authenticated %}
<li><a href="{% url 'auth_logout_user' %}">Logout</a></li>
{% else %}
<li><a href="{% url 'auth_login_user' %}">Login</a></li>
{% endif %}
</ul>
<!-- /.navbar-static-side -->
</nav>
</div>
<div class="col-lg-12">
<h1 class="page-header text-center">Character not found!</h1>
<div class="col-lg-12 container" id="example">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">{{ character_name }}</div>
<div class="panel-body">
<div class="col-lg-2 col-sm-2">
<img class="ra-avatar img-responsive" src="https://image.eveonline.com/Character/{{ character_id }}_128.jpg">
</div>
<div class="col-lg-10 col-sm-2">
<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.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/jquery.datetimepicker.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
</body>
</html>

View File

@ -1,96 +0,0 @@
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Fleet participation</title>
<!-- Bootstrap Core CSS -->
<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet">
<!-- Custom Fonts -->
<link href="{% static 'css/font-awesome.min.css' %}" rel="stylesheet" type="text/css">
<link href="{% static 'css/sb-admin-2.css' %}" rel="stylesheet">
{% block extra_css %}{% endblock extra_css %}
<style>
.grayiconecolor {
color: #505050;
}
</style>
</head>
<body onload=CCPEVE.requestTrust('{{ DOMAIN }}')>
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="navbar-header ">
<a class="navbar-brand " href="/dashboard/">
<div class="fa fa-cog fa-spin"></div>
{% if IS_CORP %}
{{ CORP_NAME }}
{% else %}
{{ ALLIANCE_NAME }}
{% endif %}
</a>
</div>
<!-- /.navbar-header -->
<ul class="nav navbar-top-links navbar-right">
{% if user.is_authenticated %}
<li><a href="{% url 'auth_logout_user' %}">Logout</a></li>
{% else %}
<li><a href="{% url 'auth_login_user' %}">Login</a></li>
{% endif %}
</ul>
<!-- /.navbar-static-side -->
</nav>
</div>
<div class="col-lg-12">
{% if registered %}<h1 class="page-header text-center">Fleet registered!</h1> {% elif expired%}<h1 class="page-header text-center">This link has expired.</h1> {% elif errormessages%}<h1 class="page-header text-center">Something horrible happened. Shoot your FC!</h1>{% else %}<h1 class="page-header text-center">Invalid link.</h1>{% endif %}
<div class="col-lg-12 container" id="example">
{% for message in errormessages %}
<div class="alert alert-danger" role="alert">{{ message }}</div>
{% endfor %}
{% if trusted %}
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">Fleet stats</div>
<div class="panel-body">
<div class="col-lg-2 col-sm-2">
<img class="ra-avatar img-responsive" src="https://image.eveonline.com/{% if IS_CORP %}Corporation/{{ CORPORATION_ID }}{% else %}Alliance/{{ ALLIANCE_ID }}{% endif %}_128.png">
</div>
<div class="col-lg-7 col-sm-2">
</div>
</div>
</div>
</div>
</div>
{% else %}
<div class="alert alert-danger" role="alert">This page requires trust to operate.</div>
{% endif %}
</div>
</div>
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/jquery.datetimepicker.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
</body>
</html>

View File

@ -0,0 +1,25 @@
{% extends 'public/base.html' %}
{% block title %}Fleet Participation{% endblock %}
{% block page_title %}Fleet Participation{% endblock %}
<div class="col-lg-12">
<h1 class="page-header text-center">Character not found!</h1>
<div class="col-lg-12 container" id="example">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">{{ character_name }}</div>
<div class="panel-body">
<div class="col-lg-2 col-sm-2">
<img class="ra-avatar img-responsive" src="https://image.eveonline.com/Character/{{ character_id }}_128.jpg">
</div>
<div class="col-lg-10 col-sm-2">
<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.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,36 @@
{% extends 'public/base.html' %}
{% block title %}Fleet participation{% endblock %}
{% block page_title %}Fleet Participation{% endblock %}
{% block content %}
<div class="col-lg-12">
{% if registered %}
<h1 class="page-header text-center">Fleet registered!</h1>
{% elif expired%}
<h1 class="page-header text-center">This link has expired.</h1>
{% elif errormessages%}
<h1 class="page-header text-center">Something horrible happened. Shoot your FC!</h1>
{% else %}
<h1 class="page-header text-center">Invalid link.</h1>
{% endif %}
<div class="col-lg-12 container" id="example">
{% for message in errormessages %}
<div class="alert alert-danger" role="alert">{{ message }}</div>
{% endfor %}
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">Fleet Stats</div>
<div class="panel-body">
<div class="col-lg-2 col-sm-2">
<img class="ra-avatar img-responsive" src="https://image.eveonline.com/{% if IS_CORP %}Corporation/{{ CORPORATION_ID }}{% else %}Alliance/{{ ALLIANCE_ID }}{% endif %}_128.png">
</div>
<div class="col-lg-7 col-sm-2">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}