diff --git a/eve_api/api_puller/accounts.py b/eve_api/api_puller/accounts.py index 4fb19fa..383199b 100755 --- a/eve_api/api_puller/accounts.py +++ b/eve_api/api_puller/accounts.py @@ -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: diff --git a/media/css/tables.css b/media/css/tables.css new file mode 100644 index 0000000..20a50a6 --- /dev/null +++ b/media/css/tables.css @@ -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 +} + diff --git a/settings.py b/settings.py index f3859e9..bfb2b9c 100644 --- a/settings.py +++ b/settings.py @@ -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 diff --git a/sso/forms.py b/sso/forms.py new file mode 100644 index 0000000..00fe0f0 --- /dev/null +++ b/sso/forms.py @@ -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'] + diff --git a/sso/models.py b/sso/models.py index b54c941..3c8bc88 100644 --- a/sso/models.py +++ b/sso/models.py @@ -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) diff --git a/sso/urls.py b/sso/urls.py index a718d78..6350117 100644 --- a/sso/urls.py +++ b/sso/urls.py @@ -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\d+)/$', views.eveapi_del), + (r'^profile/add/service', views.service_add), + (r'^profile/del/service/$', views.eveapi_del), + (r'^profile/del/service/(?P\d+)/$', views.service_del), ) diff --git a/sso/views.py b/sso/views.py index b664896..335d9e8 100644 --- a/sso/views.py +++ b/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')) diff --git a/templates/base.html b/templates/base.html index e69de29..3ba60d4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -0,0 +1,15 @@ + + + + dredd.it - {% block title %}{% endblock %} + + + + {% block content %}{% endblock %} + + diff --git a/templates/profile.html b/templates/profile.html index e69de29..1f5ab8a 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -0,0 +1,52 @@ +{% extends "base.html" %} + +{% block title %}Your Profile{% endblock %} + +{% block content %} + +

Your Profile

+ + + +

Service Accounts

+{% if srvaccounts %} + + +{% for acc in srvaccounts %} + + + + + + +{% endfor %} +
ServiceUsernamePasswordActiveActions
{{ acc.service }}{{ acc.username }}******{{ acc.active }}Delete
+{% endif %} + +{% if profile.corp_user %} +Add Service +{% endif %} + +
+ +

Eve API Keys

+{% if eveaccounts %} + + +{% for acc in eveaccounts %} + + + + + + +{% endfor %} +
User IDAPI KeyDescriptionActiveActions
{{ acc.api_user_id }}{{ acc.api_key }}{{ acc.description }}{{ acc.api_status }}Delete
+{% endif %} + +Add a Eve API key + +{% endblock %} diff --git a/templates/sso/eveapi.html b/templates/sso/eveapi.html new file mode 100644 index 0000000..014e268 --- /dev/null +++ b/templates/sso/eveapi.html @@ -0,0 +1,4 @@ +
+{{ form.as_p }} + +
diff --git a/templates/sso/serviceaccount.html b/templates/sso/serviceaccount.html new file mode 100644 index 0000000..db5710f --- /dev/null +++ b/templates/sso/serviceaccount.html @@ -0,0 +1,4 @@ +
+{{ form.as_p }} + +
diff --git a/urls.py b/urls.py index 21896bb..d186ecb 100644 --- a/urls.py +++ b/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.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), + )