Commit ced1a876 authored by Stauros Kroustouris's avatar Stauros Kroustouris

Ui to generate auth token via the profile page

parent d22a3836
...@@ -51,17 +51,20 @@ Here are some examples: ...@@ -51,17 +51,20 @@ Here are some examples:
#### GET items #### GET items
- List all the rules your user has created (admin users can see all the rules) - List all the rules your user has created (admin users can see all the rules)
curl -X GET https://fod.example.com/api/routes/ -H 'Authorization: Token <Your users token>'
curl -X GET https://fod.example.com/api/routes/ -H 'Authorization: Token <Your users token>'
- Retrieve a specific rule: - Retrieve a specific rule:
curl -X GET https:/fod.example.com/api/routes/<rule_id>/ -H 'Authorization: Token <Your users token>'
curl -X GET https:/fod.example.com/api/routes/<rule_id>/ -H 'Authorization: Token <Your users token>'
- In order to create or modify a rule you have to use POST/PUT methods. - In order to create or modify a rule you have to use POST/PUT methods.
#### POST/PUT items #### POST/PUT rules
In order to update or create rules you can follow this example:
##### Foreign Keys ##### Foreign Keys
In order to create/modify a rule you have to connect the rule with: In order to create/modify a rule you have to connect the rule with some foreign keys:
###### Ports, Fragmentypes, protocols, thenactions ###### Ports, Fragmentypes, protocols, thenactions
When creating a rule, one can specify: When creating a rule, one can specify:
......
...@@ -21,17 +21,27 @@ from django.conf import settings ...@@ -21,17 +21,27 @@ from django.conf import settings
from django.core.mail import send_mail from django.core.mail import send_mail
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.shortcuts import render from django.shortcuts import render, HttpResponse
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.decorators.cache import never_cache from django.views.decorators.cache import never_cache
from rest_framework.authtoken.models import Token
from accounts.models import UserProfile from accounts.models import UserProfile
from peers.models import Peer from peers.models import Peer
from flowspec.forms import UserProfileForm from flowspec.forms import UserProfileForm
from registration.models import RegistrationProfile from registration.models import RegistrationProfile
def generate_token(request):
user = request.user
try:
token = user.auth_token
except Token.DoesNotExist:
token = Token.objects.create(user=request.user)
return HttpResponse(token)
@never_cache @never_cache
def activate(request, activation_key): def activate(request, activation_key):
account = None account = None
......
$(document).ready(function() {
$('a#generate_token').one('click', function (ev) {
ev.preventDefault();
var url = $(this).prop('href');
var result = $(this).parent()
result.text('loading...');
$.ajax({
url: url,
success: function (data) {
result.text(data);
},
})
.fail(function() {
result.text('An error has occured...');
});
});
});
{% extends "base.html" %} {% extends "base.html" %}
{% load i18n %} {% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "My profile" %}{% endblock %} {% block title %}{% trans "My profile" %}{% endblock %}
{% block contentplaceholder %} {% block contentplaceholder %}
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">{% trans "My profile" %}</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<div class="row"> <div class="row">
<div class="col-md-8"> <div class="col-lg-12">
<div class="panel panel-primary"> <h1 class="page-header">{% trans "My profile" %}</h1>
<div class="panel-heading"> </div>
<i class="fa fa-bolt"></i> {% trans "My Networks" %} <!-- /.col-lg-12 -->
</div> </div>
<!-- /.panel-heading -->
<div class="panel-body">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>{% trans "Organization" %}</th><th>{% trans "Networks" %}</th>
</tr>
</thead>
{% for peer in peers %}
<tr>
<td>{{peer}} </td>
<td>
{% for network in peer.networks.all %}
{{network}}<br>
{% empty %}
<span style="color:red">{% blocktrans %}Ooops! Seems you have no networks associated with your peer. Contact Helpdesk to resolve this issue.{% endblocktrans %}</span>
{% endfor %}
</td></tr>
{% endfor %}
</table>
</div>
</div>
</div>
<div class="col-md-4"> <div class="row">
<div class="panel panel-default"> <div class="col-md-8">
<div class="panel-heading"> <div class="panel panel-primary">
<i class="fa fa-tags"></i> Shortcuts <div class="panel-heading">
</div> <i class="fa fa-bolt"></i> {% trans "My Networks" %}
<!-- /.panel-heading --> </div>
<div class="panel-body"> <!-- /.panel-heading -->
<div class="panel-body">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>{% trans "Organization" %}</th><th>{% trans "Networks" %}</th>
</tr>
</thead>
{% for peer in peers %}
<tr>
<td>{{peer}} </td>
<td>
{% for network in peer.networks.all %}
{{network}}<br>
{% empty %}
<span style="color:red">{% blocktrans %}Ooops! Seems you have no networks associated with your peer. Contact Helpdesk to resolve this issue.{% endblocktrans %}</span>
{% endfor %}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-tags"></i> Shortcuts
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<a class="btn btn-sm btn-outline btn-success" id="routebutton" href="{% url add-route %}"><i class="fa fa-plus-circle"></i> {% trans "Add Rule" %}</a> <a class="btn btn-sm btn-outline btn-success" id="routebutton" href="{% url add-route %}"><i class="fa fa-plus-circle"></i> {% trans "Add Rule" %}</a>
<a class="btn btn-sm btn-outline btn-primary" href="{% url group-routes %}"><i class="fa fa-shield fa-fw"></i> {% trans "My Rules" %}</a> <a class="btn btn-sm btn-outline btn-primary" href="{% url group-routes %}"><i class="fa fa-shield fa-fw"></i> {% trans "My Rules" %}</a>
<a class="btn btn-sm btn-outline btn-info" href="{% url dashboard %}"><i class="fa fa-dashboard"></i> {% trans "Dashboard" %}</a> <a class="btn btn-sm btn-outline btn-info" href="{% url dashboard %}"><i class="fa fa-dashboard"></i> {% trans "Dashboard" %}</a>
</div> </div>
<!-- /.panel-body --> <!-- /.panel-body -->
</div> </div>
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-user"></i> {% trans "My Profile" %}
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<dl class="dl-horizontal">
<dt>{% trans "Username" %}:</dt><dd>{{user.username}}</dd>
<dt>{% trans "First name" %}:</dt><dd>{{user.first_name}}</dd>
<dt>{% trans "Last name" %}:</dt><dd>{{user.last_name}}</dd>
<dt>{% trans "Email" %}:</dt><dd>{{user.email}}</dd>
</dl>
</div>
</div>
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-user"></i> {% trans "My Profile" %}
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<dl class="dl-horizontal">
<dt>{% trans "Username" %}:</dt>
<dd>{{user.username}}</dd>
<dt>{% trans "First name" %}:</dt><dd>{{user.first_name}}</dd>
<dt>{% trans "Last name" %}:</dt><dd>{{user.last_name}}</dd>
<dt>{% trans "Email" %}:</dt><dd>{{user.email}}</dd>
<dt>{% trans "Api Token" %}:</dt>
<dd>
{% if user.auth_token %}
{{ user.auth_token }}
{% else %}
<a id="generate_token" href="{% url user-profile-token %}">{% trans "Generate One" %}</a>
{% endif %}
</dd>
</dl>
</div>
</div>
</div>
</div>
{% endblock %} {% endblock %}
{% block pagejs %}
<script type="text/javascript" src="{% static 'js/accounts.js' %}"></script>
{% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment