Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ohmg/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ def profile_url(self):

@cached_property
def api_keys(self):
return [i for i in APIKey.objects.filter(account=self).values_list("value", flat=True)]
return [
i
for i in APIKey.objects.filter(account=self).values_list(
"value", "active", "request_count"
)
]

def update_sesh_counts(self):
self.load_ct = Map.objects.filter(loaded_by=self).count()
Expand Down
3 changes: 2 additions & 1 deletion ohmg/accounts/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.urls import include, path

from .views import OHMGSignupView, ProfilesView, ProfileView
from .views import APIKeysView, OHMGSignupView, ProfilesView, ProfileView

urlpatterns = [
## overwrite the default allauth signup view here
path("account/signup/", OHMGSignupView.as_view(), name="account_signup"),
path("account/api-keys/", APIKeysView.as_view(), name="api_keys"),
path("account/", include("allauth.urls")),
path("profile/<str:username>/", ProfileView.as_view(), name="profile_detail"),
path("profiles/", ProfilesView.as_view(), name="profiles"),
Expand Down
15 changes: 15 additions & 0 deletions ohmg/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,18 @@ def form_valid(self, form):
if not verify_prosopo_token(token):
raise ValidationError("Invalid token", code="invalid")
return super(self.__class__, self).form_valid(form)


class APIKeysView(View):
def get(self, request):
ohmg_context = generate_ohmg_context(request)
return render(
request,
"accounts/api-keys.html",
context={
"CONTEXT": ohmg_context,
"PROFILES_PROPS": {
"CONTEXT": ohmg_context,
},
},
)
22 changes: 20 additions & 2 deletions ohmg/frontend/static/css/site_base.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,26 @@ img {
}

table {
border-spacing: 0;
width: 100%;
min-width: 100%;
border: 1px solid #ddd;
}

table caption {
color: #333;
text-align: center;
}

th,
td {
padding: 4px;
}

tr:nth-child(even) {
background-color: #f6f6f6;
}

tr:nth-child(odd) {
background-color: #ffffff;
}

pre {
Expand Down
7 changes: 5 additions & 2 deletions ohmg/frontend/templates/_navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@
</div>
<div class="navbar-end">
{% if user.is_authenticated %}
<div class="navbar-item has-dropdown is-hoverable">
<div class="navbar-item has-dropdow is-hoverable">
<button class="navbar-link is-arrowless" style="cursor:default" >
<span>{{ user.username }}</span>
<i class="ph-bold ph-caret-down"></i>
</button>
<div class="navbar-dropdown navbar-menu">
<div class="navbar-dropdown is-right navbar-menu">
<a class="navbar-item" href="/profile/{{ user.username }}" title="Go to my profile">My profile</a>
<a class="navbar-item" href="/account/" title="Go to my account">My account</a>
{% if user.is_staff %}
<a class="navbar-item" href="/admin/" title="Go admin backend">Admin backend</a>
{% endif %}
<a class="navbar-item" href="/account/logout" title="Sign out">Sign out</a>
</div>
</div>
Expand Down
38 changes: 38 additions & 0 deletions ohmg/frontend/templates/accounts/api-keys.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends "account/base_manage.html" %}
{% load allauth i18n %}
{% block content %}
<div class="alert alert-danger">Our API is still in beta mode and should not be considered stable.</div>
<div class="content">
<h2>
{% trans "API access" %}
</h2>
<p>To request a new key, email: <a href="mailto:hello@oldinsurancemaps.net">hello@oldinsurancemaps.net</a>.</p>
<p>Include the key in an <code>X-API-Key</code> header of each request. See the API docs for endpoints:</p>
<ul>
<li><a href="/api/beta2/docs">beta2 (unstable)</a></li>
</ul>
<p>Please wait at least 2 seconds between requests, for example when working through paginated response lists.</p>
<p>Currently, GeoTIFF downloads do not require an API key (they come straight from S3 compatible storage buckets)
and are not limited. Be aware this may change in the future.</p>
</div>
{% if CONTEXT.user.api_keys|length > 0 %}
<table>
<thead>
<tr>
<th>Key</th>
<th>Active?</th>
<th>Usage</th>
</tr>
</thead>
<tbody>
{% for key in CONTEXT.user.api_keys %}
<tr>
<th><code>{{key.0}}</code></th>
<th>{% if key.1 %}<span style="color:green">✓</span>{% else %}<span style="color:red">x</span>{% endif %}</th>
<th>{{key.2}}</th>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{% endblock %}
15 changes: 9 additions & 6 deletions ohmg/frontend/templates/allauth/layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@
{% url 'account_email' as email_url_ %}
{% if email_url_ %}
<li class="{% if request.path == email_url_ %}is-active{% endif %}">
<a href="{{ email_url_ }}">{% trans "Change Email" %}</a>
<a href="{{ email_url_ }}">{% trans "Change email" %}</a>
</li>
{% endif %}
{% url 'account_change_password' as change_password_url_ %}
{% if change_password_url_ %}
<li class="{% if '/account/password/' in request.path %}is-active{% endif %}">
<a href="{{ change_password_url_ }}">{% trans "Change Password" %}</a>
<a href="{{ change_password_url_ }}">{% trans "Change password" %}</a>
</li>
{% endif %}
<li class="{% if '/avatar/' in request.path %}is-active{% endif %}">
<a href="{% url 'avatar_change' %}">{% trans "Change Avatar" %}</a>
<a href="{% url 'avatar_change' %}">{% trans "Change avatar" %}</a>
</li>
{% url 'socialaccount_connections' as connections_url_ %}
{% if connections_url_ %}
<li class="{% if request.path == connections_url_ %}is-active{% endif %}">
<a href="{{ connections_url_ }}">{% trans "Account Connections" %}</a>
<a href="{{ connections_url_ }}">{% trans "Account connections" %}</a>
</li>
{% endif %}
{% url 'mfa_index' as mfa_url_ %}
{% if mfa_url_ %}
<li class="{% if request.path == mfa_url_ %}is-active{% endif %}">
<a href="{{ mfa_url_ }}">{% trans "Two-Factor Authentication" %}</a>
<a href="{{ mfa_url_ }}">{% trans "Two-factor authentication" %}</a>
</li>
{% endif %}
{% url 'usersessions_list' as usersessions_list_url_ %}
Expand All @@ -46,9 +46,12 @@
{% url 'account_logout' as logout_url_ %}
{% if logout_url_ %}
<li class="{% if request.path == logout_url_ %}is-active{% endif %}">
<a href="{{ logout_url_ }}">{% trans "Sign Out" %}</a>
<a href="{{ logout_url_ }}">{% trans "Sign out" %}</a>
</li>
{% endif %}
<li class="{% if request.path == '/account/api-keys/' %}is-active{% endif %}">
<a href="/account/api-keys">{% trans "API access" %}</a>
</li>
{% else %}
{% url 'account_login' as login_url_ %}
{% if login_url_ %}
Expand Down
Loading