mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Initial work on user control panel for tokens
This commit is contained in:
parent
6be465fe9b
commit
d58a8ebba0
@ -11,6 +11,7 @@
|
|||||||
<ul class="nav nav-pills nav-stacked">
|
<ul class="nav nav-pills nav-stacked">
|
||||||
<li{% ifequal active_tab "profile" %} class="active"{% endifequal %}><a href="{% url 'users:profile' %}">Profile</a></li>
|
<li{% ifequal active_tab "profile" %} class="active"{% endifequal %}><a href="{% url 'users:profile' %}">Profile</a></li>
|
||||||
<li{% ifequal active_tab "change_password" %} class="active"{% endifequal %}><a href="{% url 'users:change_password' %}">Change Password</a></li>
|
<li{% ifequal active_tab "change_password" %} class="active"{% endifequal %}><a href="{% url 'users:change_password' %}">Change Password</a></li>
|
||||||
|
<li{% ifequal active_tab "api_tokens" %} class="active"{% endifequal %}><a href="{% url 'users:api_tokens' %}">API Tokens</a></li>
|
||||||
<li{% ifequal active_tab "userkey" %} class="active"{% endifequal %}><a href="{% url 'users:userkey' %}">User Key</a></li>
|
<li{% ifequal active_tab "userkey" %} class="active"{% endifequal %}><a href="{% url 'users:userkey' %}">User Key</a></li>
|
||||||
<li{% ifequal active_tab "recent_activity" %} class="active"{% endifequal %}><a href="{% url 'users:recent_activity' %}">Recent Activity</a></li>
|
<li{% ifequal active_tab "recent_activity" %} class="active"{% endifequal %}><a href="{% url 'users:recent_activity' %}">Recent Activity</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
44
netbox/templates/users/api_tokens.html
Normal file
44
netbox/templates/users/api_tokens.html
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{% extends 'users/_user.html' %}
|
||||||
|
{% load helpers %}
|
||||||
|
|
||||||
|
{% block title %}API Tokens{% endblock %}
|
||||||
|
|
||||||
|
{% block usercontent %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
{% for token in tokens %}
|
||||||
|
<div class="panel panel-{% if token.is_expired %}danger{% else %}default{% endif %}">
|
||||||
|
<div class="panel-heading">
|
||||||
|
{% if token.is_expired %}
|
||||||
|
<div class="pull-right">
|
||||||
|
<span class="label label-danger">Expired</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<i class="fa fa-key"></i> {{ token.key }}
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-4">
|
||||||
|
Created: {{ token.created|date }}
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
Expires: {{ token.expires|default:"Never" }}
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
Write operations:
|
||||||
|
{% if token.write_enabled %}
|
||||||
|
<span class="label label-success">Enabled</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="label label-danger">Disabled</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% if token.description %}
|
||||||
|
<br /><span>{{ token.description }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@ -8,6 +8,7 @@ urlpatterns = [
|
|||||||
# User profiles
|
# User profiles
|
||||||
url(r'^profile/$', views.profile, name='profile'),
|
url(r'^profile/$', views.profile, name='profile'),
|
||||||
url(r'^profile/password/$', views.change_password, name='change_password'),
|
url(r'^profile/password/$', views.change_password, name='change_password'),
|
||||||
|
url(r'^profile/api-tokens/$', views.TokenList.as_view(), name='api_tokens'),
|
||||||
url(r'^profile/user-key/$', views.userkey, name='userkey'),
|
url(r'^profile/user-key/$', views.userkey, name='userkey'),
|
||||||
url(r'^profile/user-key/edit/$', views.userkey_edit, name='userkey_edit'),
|
url(r'^profile/user-key/edit/$', views.userkey_edit, name='userkey_edit'),
|
||||||
url(r'^profile/recent-activity/$', views.recent_activity, name='recent_activity'),
|
url(r'^profile/recent-activity/$', views.recent_activity, name='recent_activity'),
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth import login as auth_login, logout as auth_logout, update_session_auth_hash
|
from django.contrib.auth import login as auth_login, logout as auth_logout, update_session_auth_hash
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
from django.utils.http import is_safe_url
|
from django.utils.http import is_safe_url
|
||||||
|
from django.views.generic import View
|
||||||
|
|
||||||
from secrets.forms import UserKeyForm
|
from secrets.forms import UserKeyForm
|
||||||
from secrets.models import UserKey
|
from secrets.models import UserKey
|
||||||
|
|
||||||
from .forms import LoginForm, PasswordChangeForm
|
from .forms import LoginForm, PasswordChangeForm
|
||||||
|
from .models import Token
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -128,3 +130,19 @@ def recent_activity(request):
|
|||||||
'recent_activity': request.user.actions.all()[:50],
|
'recent_activity': request.user.actions.all()[:50],
|
||||||
'active_tab': 'recent_activity',
|
'active_tab': 'recent_activity',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# API tokens
|
||||||
|
#
|
||||||
|
|
||||||
|
class TokenList(LoginRequiredMixin, View):
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
|
||||||
|
tokens = Token.objects.filter(user=request.user)
|
||||||
|
|
||||||
|
return render(request, 'users/api_tokens.html', {
|
||||||
|
'tokens': tokens,
|
||||||
|
'active_tab': 'api_tokens',
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user