mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 06:42:16 +00:00
Views now working, basic construction complete
This commit is contained in:
@@ -12,6 +12,7 @@ if __name__ == "__main__":
|
||||
|
||||
from django.conf import settings
|
||||
from eve_proxy.models import CachedDocument
|
||||
from eve_api.app_defines import *
|
||||
from eve_api.api_exceptions import APIAuthException, APINoUserIDException
|
||||
from eve_api.models import EVEAccount, EVEPlayerCharacter, EVEPlayerCorporation
|
||||
|
||||
@@ -39,6 +40,7 @@ def import_eve_account(api_key, user_id):
|
||||
account.api_key = api_key
|
||||
account.api_user_id = user_id
|
||||
account.api_last_updated = datetime.now()
|
||||
account.api_status = API_STATUS_OK
|
||||
account.save()
|
||||
|
||||
for node in characters_node_children:
|
||||
|
||||
79
media/css/tables.css
Normal file
79
media/css/tables.css
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
http://icant.co.uk/csstablegallery/index.php?css=71
|
||||
|
||||
Data Tables and Cascading Style Sheets Gallery
|
||||
Title: Casablanca
|
||||
Author: RODrigo CASTilho Galvão Ferreira - RODCAST
|
||||
URL: http://www.rodcast.com.br
|
||||
Update: 04/04/2008 10:51 AM
|
||||
*/
|
||||
|
||||
table {
|
||||
color: #7F7F7F;
|
||||
font: 0.8em/1.6em "Trebuchet MS",Verdana,sans-serif;
|
||||
border-collapse: collapse
|
||||
}
|
||||
|
||||
table,caption {
|
||||
margin: 0 auto;
|
||||
border-right: 1px solid #CCC;
|
||||
border-left: 1px solid #CCC
|
||||
}
|
||||
|
||||
caption,th,td {
|
||||
border-left: 0;
|
||||
padding: 10px
|
||||
}
|
||||
|
||||
caption,thead th,tfoot th,tfoot td {
|
||||
background-color: #E63C1E;
|
||||
color: #FFF;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase
|
||||
}
|
||||
|
||||
thead th {
|
||||
background-color: #C30;
|
||||
color: #FFB3A6;
|
||||
text-align: center
|
||||
}
|
||||
|
||||
tbody th {
|
||||
padding: 20px 10px
|
||||
}
|
||||
|
||||
tbody tr.odd {
|
||||
background-color: #F7F7F7;
|
||||
color: #666
|
||||
}
|
||||
|
||||
tbody a {
|
||||
padding: 1px 2px;
|
||||
color: #333;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dotted #E63C1E
|
||||
}
|
||||
|
||||
tbody a:active,tbody a:hover,tbody a:focus,tbody a:visited {
|
||||
color: #666
|
||||
}
|
||||
|
||||
tbody tr:hover {
|
||||
background-color: #EEE;
|
||||
color: #333
|
||||
}
|
||||
|
||||
tbody tr:hover a {
|
||||
background-color: #FFF
|
||||
}
|
||||
|
||||
tbody td+td+td+td a {
|
||||
color: #C30;
|
||||
font-weight: bold;
|
||||
border-bottom: 0
|
||||
}
|
||||
|
||||
tbody td+td+td+td a:active,tbody td+td+td+td a:hover,tbody td+td+td+td a:focus,tbody td+td+td+td a:visited {
|
||||
color: #E63C1E
|
||||
}
|
||||
|
||||
@@ -46,12 +46,12 @@ USE_I18N = True
|
||||
|
||||
# Absolute path to the directory that holds media.
|
||||
# Example: "/home/media/media.lawrence.com/"
|
||||
MEDIA_ROOT = ''
|
||||
MEDIA_ROOT = '/home/nikdoof/dev/corpsso/media'
|
||||
|
||||
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
||||
# trailing slash if there is a path component (optional in other cases).
|
||||
# Examples: "http://media.lawrence.com", "http://example.com/media/"
|
||||
MEDIA_URL = ''
|
||||
MEDIA_URL = '/media/'
|
||||
|
||||
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
|
||||
# trailing slash.
|
||||
@@ -94,6 +94,10 @@ INSTALLED_APPS = (
|
||||
|
||||
AUTH_PROFILE_MODULE = 'sso.SSOUser'
|
||||
|
||||
### EVE Corp Info
|
||||
|
||||
EVE_CORP_ID = 1018389948
|
||||
|
||||
### Jabber Service Settings
|
||||
|
||||
# Vhost to add users to
|
||||
|
||||
14
sso/forms.py
Normal file
14
sso/forms.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django import forms
|
||||
|
||||
from sso.models import ServiceAccount
|
||||
|
||||
class EveAPIForm(forms.Form):
|
||||
user_id = forms.CharField(max_length=10)
|
||||
api_key = forms.CharField(max_length=100)
|
||||
description = forms.CharField(max_length=100)
|
||||
|
||||
class ServiceAccountForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = ServiceAccount
|
||||
exclude = ['user', 'active']
|
||||
|
||||
@@ -45,7 +45,8 @@ class Service(models.Model):
|
||||
api = models.CharField(max_length=200)
|
||||
|
||||
def __str__(self):
|
||||
return "%s: %s" % (self.name, self.api)
|
||||
#return "%s: %s" % (self.name, self.api)
|
||||
return self.name
|
||||
|
||||
class ServiceAccount(models.Model):
|
||||
user = models.ForeignKey(User, blank=False)
|
||||
|
||||
@@ -3,5 +3,11 @@ from django.conf.urls.defaults import *
|
||||
from sso import views
|
||||
|
||||
urlpatterns = patterns('',
|
||||
(r'^profile/', views.profile),
|
||||
(r'^profile/$', views.profile),
|
||||
(r'^profile/add/eveapi', views.eveapi_add),
|
||||
(r'^profile/del/eveapi/$', views.eveapi_del),
|
||||
(r'^profile/del/eveapi/(?P<userid>\d+)/$', views.eveapi_del),
|
||||
(r'^profile/add/service', views.service_add),
|
||||
(r'^profile/del/service/$', views.eveapi_del),
|
||||
(r'^profile/del/service/(?P<serviceid>\d+)/$', views.service_del),
|
||||
)
|
||||
|
||||
92
sso/views.py
92
sso/views.py
@@ -1,9 +1,17 @@
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from eve_api.api_exceptions import APIAuthException, APINoUserIDException
|
||||
from eve_api.api_puller.accounts import import_eve_account
|
||||
from eve_api.models.api_player import EVEAccount
|
||||
|
||||
from sso.models import ServiceAccount, SSOUser
|
||||
from sso.forms import EveAPIForm, ServiceAccountForm
|
||||
|
||||
import settings
|
||||
|
||||
def index(request):
|
||||
pass
|
||||
@@ -19,23 +27,97 @@ def profile(request):
|
||||
profile.save()
|
||||
|
||||
try:
|
||||
srvaccounts = ServiceAccount.objects.get(user=request.user)
|
||||
srvaccounts = ServiceAccount.objects.filter(user=request.user).all()
|
||||
except ServiceAccount.DoesNotExist:
|
||||
srvaccounts = None
|
||||
|
||||
try:
|
||||
eveaccounts = EVEAccount.objects.get(user=request.user)
|
||||
eveaccounts = EVEAccount.objects.filter(user=request.user).all()
|
||||
except EVEAccount.DoesNotExist:
|
||||
eveaccounts = None
|
||||
|
||||
return render_to_response('profile.html', locals())
|
||||
|
||||
@login_required
|
||||
def eveapi_add(request):
|
||||
if request.method == 'POST':
|
||||
form = EveAPIForm(request.POST)
|
||||
if form.is_valid():
|
||||
try:
|
||||
acc = import_eve_account(form.cleaned_data['api_key'], form.cleaned_data['user_id'])
|
||||
except APIAuthException:
|
||||
return HttpResponseRedirect(reverse('sso.views.profile'))
|
||||
|
||||
acc.user = request.user
|
||||
acc.description = form.cleaned_data['description']
|
||||
acc.save()
|
||||
|
||||
for eacc in EVEAccount.objects.filter(user=request.user):
|
||||
if acc.api_status == 1 and acc.in_corp(settings.EVE_CORP_ID):
|
||||
profile = request.user.get_profile()
|
||||
profile.corp_user = True
|
||||
profile.save()
|
||||
break
|
||||
|
||||
return HttpResponseRedirect(reverse('sso.views.profile')) # Redirect after POST
|
||||
else:
|
||||
form = EveAPIForm() # An unbound form
|
||||
|
||||
return render_to_response('sso/eveapi.html', {
|
||||
'form': form,
|
||||
})
|
||||
|
||||
@login_required
|
||||
def eveapi_del(request, userid=0):
|
||||
|
||||
if userid > 0 :
|
||||
|
||||
try:
|
||||
acc = EVEAccount.objects.get(id=userid)
|
||||
except EVEAccount.DoesNotExist:
|
||||
return HttpResponseRedirect(reverse('sso.views.profile'))
|
||||
|
||||
if acc.user == request.user:
|
||||
acc.delete()
|
||||
|
||||
return HttpResponseRedirect(reverse('sso.views.profile'))
|
||||
|
||||
@login_required
|
||||
def service_add(request):
|
||||
pass
|
||||
if request.method == 'POST':
|
||||
form = ServiceAccountForm(request.POST)
|
||||
if form.is_valid():
|
||||
|
||||
acc = ServiceAccount()
|
||||
|
||||
def service_del(request):
|
||||
pass
|
||||
acc.user = request.user
|
||||
acc.service = form.cleaned_data['service']
|
||||
acc.username = form.cleaned_data['username']
|
||||
acc.password = form.cleaned_data['password']
|
||||
|
||||
acc.save()
|
||||
|
||||
return HttpResponseRedirect(reverse('sso.views.profile')) # Redirect after POST
|
||||
else:
|
||||
form = ServiceAccountForm() # An unbound form
|
||||
|
||||
return render_to_response('sso/serviceaccount.html', {
|
||||
'form': form,
|
||||
})
|
||||
|
||||
@login_required
|
||||
def service_del(request, serviceid=0):
|
||||
if serviceid > 0 :
|
||||
|
||||
try:
|
||||
acc = ServiceAccount.objects.get(id=serviceid)
|
||||
except ServiceAccount.DoesNotExist:
|
||||
return HttpResponseRedirect(reverse('sso.views.profile'))
|
||||
|
||||
if acc.user == request.user:
|
||||
acc.delete()
|
||||
|
||||
return HttpResponseRedirect(reverse('sso.views.profile'))
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>dredd.it - {% block title %}{% endblock %}</title>
|
||||
<style type="text/css">
|
||||
BODY, TH, TD, P {
|
||||
font-size: 0.9em;
|
||||
font-family: Verdana;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Your Profile{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>Your Profile</h1>
|
||||
|
||||
<ul>
|
||||
<li><b>Username:</b> {{ user.username }}</li>
|
||||
<li><b>Corp Access?</b> {{ profile.corp_user }}</li>
|
||||
</ul>
|
||||
|
||||
<h2>Service Accounts</h2>
|
||||
{% if srvaccounts %}
|
||||
<table border=1>
|
||||
<tr><th>Service</th><th>Username</th><th>Password</th><th>Active</th><th>Actions</th></tr>
|
||||
{% for acc in srvaccounts %}
|
||||
<tr><td>{{ acc.service }}</td>
|
||||
<td>{{ acc.username }}</td>
|
||||
<td>******</td>
|
||||
<td>{{ acc.active }}</td>
|
||||
<td><a href="/profile/del/service/{{ acc.id }}/">Delete</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
{% if profile.corp_user %}
|
||||
<a href="/profile/add/service">Add Service</a>
|
||||
{% endif %}
|
||||
|
||||
<br/>
|
||||
|
||||
<h2>Eve API Keys</h2>
|
||||
{% if eveaccounts %}
|
||||
<table border=1>
|
||||
<tr><th>User ID</th><th>API Key</th><th>Description</th><th>Active</th><th>Actions</th></tr>
|
||||
{% for acc in eveaccounts %}
|
||||
<tr><td>{{ acc.api_user_id }}</td>
|
||||
<td>{{ acc.api_key }}</td>
|
||||
<td>{{ acc.description }}</td>
|
||||
<td>{{ acc.api_status }}</td>
|
||||
<td><a href="/profile/del/eveapi/{{ acc.api_user_id }}/">Delete</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
<a href="/profile/add/eveapi">Add a Eve API key</a>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
4
templates/sso/eveapi.html
Normal file
4
templates/sso/eveapi.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<form action="/profile/add/eveapi" method="post">
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
4
templates/sso/serviceaccount.html
Normal file
4
templates/sso/serviceaccount.html
Normal file
@@ -0,0 +1,4 @@
|
||||
<form action="/profile/add/service" method="post">
|
||||
{{ form.as_p }}
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
6
urls.py
6
urls.py
@@ -1,5 +1,6 @@
|
||||
from django.conf.urls.defaults import *
|
||||
from django.contrib import admin
|
||||
import settings
|
||||
|
||||
admin.autodiscover()
|
||||
|
||||
@@ -12,3 +13,8 @@ urlpatterns = patterns('',
|
||||
('', include('registration.backends.default.urls')),
|
||||
('', include('sso.urls')),
|
||||
)
|
||||
|
||||
if not settings.DEBUG:
|
||||
urlpatterns += patterns('',
|
||||
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user