Add client creation. Remove user from client model.
This commit is contained in:
parent
2b55e8dd8e
commit
36f8f7939b
|
@ -18,22 +18,10 @@ class Client(models.Model):
|
|||
]
|
||||
|
||||
name = models.CharField(max_length=100, default='')
|
||||
user = models.ForeignKey(User)
|
||||
client_id = models.CharField(max_length=255, unique=True)
|
||||
client_secret = models.CharField(max_length=255, unique=True)
|
||||
client_type = models.CharField(max_length=20, choices=CLIENT_TYPE_CHOICES)
|
||||
response_type = models.CharField(max_length=30, choices=RESPONSE_TYPE_CHOICES)
|
||||
|
||||
# TODO: Need to be implemented.
|
||||
# The list of scopes the client may request access to.
|
||||
_scope = models.TextField(default='')
|
||||
def scope():
|
||||
def fget(self):
|
||||
return self._scope.split()
|
||||
def fset(self, value):
|
||||
self._scope = ' '.join(value)
|
||||
return locals()
|
||||
scope = property(**scope())
|
||||
|
||||
_redirect_uris = models.TextField(default='')
|
||||
def redirect_uris():
|
||||
|
|
50
openid_provider/templates/openid_provider/client_create.html
Normal file
50
openid_provider/templates/openid_provider/client_create.html
Normal file
|
@ -0,0 +1,50 @@
|
|||
{% extends "openid_provider/base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-md-offset-3">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Create new client</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{% if error %}
|
||||
<div class="alert alert-danger" role="alert"><strong>Something was wrong.</strong> Try again please.</div>
|
||||
{% endif %}
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input name="name" type="text" class="form-control" placeholder="Some Client">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Client Type</label>
|
||||
<select name="client_type" class="form-control">
|
||||
<option value="confidential">Confidential</option>
|
||||
<option value="public">Public</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Response Type</label>
|
||||
<select name="response_type" class="form-control">
|
||||
<option value="code">code (Authorization Code Flow)</option>
|
||||
<option value="id_token">id_token (Implicit Flow)</option>
|
||||
<option value="id_token token">id_token token (Implicit Flow)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>Redirect URIs</label>
|
||||
<textarea name="redirect_uris" class="form-control" rows="3" placeholder="Complete URL's. Separated with new lines."></textarea>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-success btn-block" value="OK" />
|
||||
<br><a href="{% url 'openid_provider:client_list' %}"><span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span> Go Back</a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -33,16 +33,12 @@
|
|||
<th scope="row">Redirect URIs</th>
|
||||
<td>{{ object.redirect_uris|join:', ' }} </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Scopes</th>
|
||||
<td>{{ object.scope|join:', ' }} </td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="btn-group btn-group btn-group-justified" role="group">
|
||||
<a href="{% url 'openid_provider:client_list' %}" class="btn btn-primary"><span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span> Go Back</a>
|
||||
<a class="btn btn-danger">Delete</a>
|
||||
<a class="btn btn-success">Edit</a>
|
||||
</div>
|
||||
<br><a href="{% url 'openid_provider:client_list' %}"><span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span> Go Back</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<strong>Total</strong>
|
||||
</li>
|
||||
</ul>
|
||||
<a href="#" class="btn btn-success btn-block">New Client</a>
|
||||
<a href="{% url 'openid_provider:client_create' %}" class="btn btn-success btn-block">New Client</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -15,5 +15,6 @@ urlpatterns = patterns('',
|
|||
|
||||
url(r'^clients/$', clients.ClientListView.as_view(), name='client_list'),
|
||||
url(r'^clients/(?P<pk>[\d]+)/$', clients.ClientDetailView.as_view(), name='client_detail'),
|
||||
url(r'^clients/create/$', clients.client_create, name='client_create'),
|
||||
|
||||
)
|
|
@ -1,8 +1,13 @@
|
|||
from django.shortcuts import redirect
|
||||
from django.shortcuts import render
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.generic.detail import DetailView
|
||||
from django.views.generic.edit import CreateView
|
||||
from django.views.generic.list import ListView
|
||||
from openid_provider.lib.utils.decorators import staff_required
|
||||
from openid_provider.models import Client
|
||||
from random import random
|
||||
import uuid
|
||||
|
||||
|
||||
class ClientListView(ListView):
|
||||
|
@ -15,4 +20,40 @@ class ClientListView(ListView):
|
|||
|
||||
class ClientDetailView(DetailView):
|
||||
|
||||
model = Client
|
||||
model = Client
|
||||
|
||||
@method_decorator(staff_required)
|
||||
def dispatch(self, *args, **kwargs):
|
||||
return super(ClientListView, self).dispatch(*args, **kwargs)
|
||||
|
||||
@staff_required
|
||||
def client_create(request):
|
||||
|
||||
error = False
|
||||
|
||||
if request.method == 'POST':
|
||||
|
||||
try:
|
||||
client = Client()
|
||||
|
||||
client.name = request.POST.get('name')
|
||||
client.client_type = request.POST.get('client_type')
|
||||
client.response_type = request.POST.get('response_type')
|
||||
client.redirect_uris = request.POST.get('redirect_uris')
|
||||
|
||||
client.client_id = str(random()).split('.')[1][:8]
|
||||
client.client_secret = uuid.uuid4().hex
|
||||
|
||||
client.save()
|
||||
|
||||
return redirect('openid_provider:client_list')
|
||||
|
||||
except Exception as e:
|
||||
print e
|
||||
error = True
|
||||
|
||||
data = {
|
||||
'error': error,
|
||||
}
|
||||
|
||||
return render(request, 'openid_provider/client_create.html', data)
|
Loading…
Reference in a new issue