From bf5a5b4befa5e7b9e9aa7fe128f34b5a0a3333d9 Mon Sep 17 00:00:00 2001 From: Raynaldo Rivera Date: Sat, 4 Oct 2014 21:20:26 -0700 Subject: [PATCH] Added basic openfire support --- README.md | 8 ++++--- allianceauth/settings.py | 8 +++++-- allianceauth/urls.py | 1 + portal/views.py | 15 +++++++++++++ templates/public/applications.html | 1 + test.py | 17 --------------- util/jabber_manager.py | 34 ++++++++++++++++++++++++++++++ 7 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 util/jabber_manager.py diff --git a/README.md b/README.md index 78f9a05e..437cd178 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ allianceauth Note: THIS WAS RUSHED! IT DOES NOT FOLLOW GOOD CODING STANDARDS Note2: Most importantly though it works.... +Note3: Jabber uses inband registration. In prosody whitelist the auth server Requirments: django 1.7 @@ -10,12 +11,13 @@ Requirments: python-mysqld django-evolution python-passlib + python-openfire bcrypt Services Interaction: - Mysql Forums - Mumble - Prosody (jabber) + Phpbb3 (Forums) + Mumble (Voice) + Openfire (Jabber) diff --git a/allianceauth/settings.py b/allianceauth/settings.py index 5a793f6f..0f993c4b 100644 --- a/allianceauth/settings.py +++ b/allianceauth/settings.py @@ -141,5 +141,9 @@ STATICFILES_DIRS = ( STATIC_URL = '/static/' # ALLIANCE INFO -ALLIANCE_ID = 99001336 -ALLIANCE_NAME = 'The 99 Percent' +ALLIANCE_ID = 0 +ALLIANCE_NAME = 'Some alliance here' + +# Jabber Prosody Info +OPENFIRE_ADDRESS = "http://domain.com:9090/" +OPENFIRE_SECRET_KEY = "somekey" diff --git a/allianceauth/urls.py b/allianceauth/urls.py index a2b28b9b..4abeaa75 100644 --- a/allianceauth/urls.py +++ b/allianceauth/urls.py @@ -13,6 +13,7 @@ urlpatterns = patterns('', url(r'^maincharacterchange/(\d+)/$', 'portal.views.main_character_change', name='main_character_change'), url(r'^applications/', 'portal.views.applications_view', name = 'applications'), url(r'^activateforum/$', 'portal.views.activate_forum', name = 'activateforum'), + url(r'^activatejabber/$', 'portal.views.activate_jabber', name = 'activatejabber'), url(r'^loginuser/','authentication.views.login_user', name='loginuser'), url(r'^logoutuser/','authentication.views.logout_user', name='logoutuser'), url(r'^register/', 'registration.views.register', name='register'), diff --git a/portal/views.py b/portal/views.py index b9680ffd..66716fbe 100644 --- a/portal/views.py +++ b/portal/views.py @@ -7,6 +7,7 @@ from forms import UpdateKeyForm from evespecific.managers import EveCharacterManager from authentication.models import AllianceUserManager from util.phpbb3_manager import Phpbb3Manager +from util.jabber_manager import JabberManager # Create your views here. @login_required @@ -62,3 +63,17 @@ def activate_forum(request): return HttpResponseRedirect("/") +@login_required +def activate_jabber(request): + userManager = AllianceUserManager() + jabberManager = JabberManager() + if userManager.check_if_user_exist(request.user.id): + characterManager = EveCharacterManager() + character = characterManager.get_character_by_id(request.user.main_char_id) + + jabberManager.add_user(character.character_name,"test") + + return HttpResponseRedirect("/applications/") + + return HttpResponseRedirect("/") + diff --git a/templates/public/applications.html b/templates/public/applications.html index 41330482..9bd9d07f 100644 --- a/templates/public/applications.html +++ b/templates/public/applications.html @@ -11,6 +11,7 @@

Really dumb right now

Click button to add user to services

+ {% endblock content %} diff --git a/test.py b/test.py index cbc7fd15..e69de29b 100644 --- a/test.py +++ b/test.py @@ -1,17 +0,0 @@ -import evelink.api # Raw API access -import evelink.char # Wrapped API access for the /char/ API path -import evelink.eve # Wrapped API access for the /eve/ API path - -api_id = '3730269' -api_key = 'BkoREwPBo4QQOGGZXcuOfXMMfSDuTttmoqtQSjiaCoYECqrPozBp4bKjYZ2XmOHL' -# Create user -api = evelink.api.API(api_key=(api_id, api_key)) -account = evelink.account.Account(api=api) -chars = account.characters() -for char in chars.result: - print char['alliance']['id'] - print char['alliance']['name'] - print char['corp']['id'] - print char['corp']['name'] - print char['id'] - print char['name'] diff --git a/util/jabber_manager.py b/util/jabber_manager.py new file mode 100644 index 00000000..b8cfa150 --- /dev/null +++ b/util/jabber_manager.py @@ -0,0 +1,34 @@ +from django.conf import settings +from django.db import connections, transaction +from openfire import UserService + +class JabberManager(): + + def __init__(self): + pass + + def add_user(self, username, password): + api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY) + print str(username) + print str(password) + api.add_user(self.__santatize_username(username), str(password)) + + def delete_user(self, username): + api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY) + api.delete_user(username, password) + + def lock_user(self, username): + api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY) + api.lock_user(username, password) + + def unlock_user(self, username): + api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY) + api.unlock_user(username, password) + + def update_user_pass(self, username, password): + api = UserService(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY) + api.update_user(username, password) + + def __santatize_username(self, username): + sanatized = username.replace(" ","_") + return sanatized.lower() \ No newline at end of file