@@ -282,6 +282,22 @@ class AuthManager: | |||||
self._update_prop_cache(module, prop, value) | self._update_prop_cache(module, prop, value) | ||||
return True | return True | ||||
def get_token(self): | |||||
"""Return a valid token for the current character, or None. | |||||
Assuming this is called in a restricted route (following a True result | |||||
from is_authenticated), this function makes no API calls and should | |||||
always succeed. If it is called in other circumstances, it may fail and | |||||
return None. | |||||
""" | |||||
cid = self.get_character_id() | |||||
if not cid: | |||||
return None | |||||
if not hasattr(g, "_cached_token"): | |||||
g._cached_token = self._get_token(cid) | |||||
return g._cached_token | |||||
def is_authenticated(self): | def is_authenticated(self): | ||||
"""Return whether the user has permission to access this site. | """Return whether the user has permission to access this site. | ||||
@@ -308,6 +324,7 @@ class AuthManager: | |||||
self._debug("Access granted for char id=%d session id=%d", cid, | self._debug("Access granted for char id=%d session id=%d", cid, | ||||
session["id"]) | session["id"]) | ||||
g.db.touch_session(session["id"]) | g.db.touch_session(session["id"]) | ||||
g._cached_token = token | |||||
return True | return True | ||||
def make_login_link(self): | def make_login_link(self): | ||||
@@ -1,8 +1,42 @@ | |||||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||
# ... | |||||
from collections import namedtuple | |||||
from flask import g | |||||
from flask_mako import render_template | |||||
from ._provided import blueprint | |||||
SCOPES = {"esi-corporations.read_corporation_membership.v1"} | SCOPES = {"esi-corporations.read_corporation_membership.v1"} | ||||
_Member = namedtuple("_Member", ["id", "name"]) | |||||
def get_members(): | |||||
"""Return a list of the members of the user's corporation. | |||||
Members are returned as 2-namedtuples of (id, name). An empty list is | |||||
returned if there was some error with tokens. | |||||
""" | |||||
token = g.auth.get_token() | |||||
if not token: | |||||
return [] | |||||
corp_id = g.config.get("corp.id") | |||||
resp = g.eve.esi(token).v2.corporations(corp_id).members.get() | |||||
cids = ",".join(str(item["character_id"]) for item in resp) | |||||
resp = g.eve.esi(token).v1.characters.names.get(character_ids=cids) | |||||
return [_Member(item["character_id"], item["character_name"]) | |||||
for item in resp] | |||||
def home(): | |||||
"""Render and return the main members page.""" | |||||
return render_template("members/members.mako", members=get_members()) | |||||
def navitem(): | def navitem(): | ||||
return "Members" | |||||
"""Render and return the navigation item for this module.""" | |||||
return render_template("members/navitem.mako").decode("utf8") | |||||
@blueprint.rroute("/members") | |||||
def members(): | |||||
"""Render and return the main members page.""" | |||||
return home() |
@@ -1,7 +1,7 @@ | |||||
<%inherit file="../_default.mako"/> | <%inherit file="../_default.mako"/> | ||||
%if current: | |||||
% if current: | |||||
<h2><span class="understate">Campaign:</span> ${current} <!-- select ... --></h2> | <h2><span class="understate">Campaign:</span> ${current} <!-- select ... --></h2> | ||||
<p>Hello! ...</p> | <p>Hello! ...</p> | ||||
%else: | |||||
% else: | |||||
<p>No campaigns currently.</p> | <p>No campaigns currently.</p> | ||||
%endif | |||||
% endif |
@@ -0,0 +1,11 @@ | |||||
<%inherit file="../_default.mako"/> | |||||
<h2>Members</h2> | |||||
<!-- ... handle case where members is empty - means something went wrong --> | |||||
<ul> | |||||
% for member in members: | |||||
<li> | |||||
<img title="${member.name}" alt="${member.name}'s Portrait" src="${g.eve.image.character(member.id, 256)}"/> | |||||
${member.name} | |||||
</li> | |||||
% endfor | |||||
</ul> |
@@ -0,0 +1 @@ | |||||
<a href="${url_for('members.members')}">Members</a> |