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:
#### GET items
- List all the rules your user has created (admin users can see all the rules)
curl -X GET -H 'Authorization: Token <Your users token>'
- Retrieve a specific rule:
curl -X GET https:/<rule_id>/ -H 'Authorization: Token <Your users token>'
- 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
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
When creating a rule, one can specify:
......@@ -21,17 +21,27 @@ from django.conf import settings
from django.core.mail import send_mail
from django.contrib.sites.models import Site
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.utils.translation import ugettext_lazy as _
from django.views.decorators.cache import never_cache
from rest_framework.authtoken.models import Token
from accounts.models import UserProfile
from peers.models import Peer
from flowspec.forms import UserProfileForm
from registration.models import RegistrationProfile
def generate_token(request):
user = request.user
token = user.auth_token
except Token.DoesNotExist:
token = Token.objects.create(user=request.user)
return HttpResponse(token)
def activate(request, activation_key):
account = None
$(document).ready(function() {
$('a#generate_token').one('click', function (ev) {
var url = $(this).prop('href');
var result = $(this).parent()
url: url,
success: function (data) {
.fail(function() {
result.text('An error has occured...');
{% extends "base.html" %}
{% load i18n %}
{% load staticfiles %}
{% block title %}{% trans "My profile" %}{% endblock %}
{% block contentplaceholder %}
<div class="row">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">{% trans "My profile" %}</h1>
<!-- /.col-lg-12 -->
<div class="row">
<div class="col-md-8">
......@@ -33,20 +34,20 @@
{% 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 %}
{% endfor %}
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-tags"></i> Shortcuts
<!-- /.panel-heading -->
<div class="panel-body">
<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-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>
......@@ -61,20 +62,26 @@
<!-- /.panel-heading -->
<div class="panel-body">
<dl class="dl-horizontal">
<dt>{% trans "Username" %}:</dt><dd>{{user.username}}</dd>
<dt>{% trans "Username" %}:</dt>
<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>{{}}</dd>
<dt>{% trans "Api Token" %}:</dt>
{% if user.auth_token %}
{{ user.auth_token }}
{% else %}
<a id="generate_token" href="{% url user-profile-token %}">{% trans "Generate One" %}</a>
{% endif %}
{% 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