diff --git a/README.md b/README.md index bad3c8cc..78f9a05e 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,11 @@ Requirments: python-mysql-connector python-mysqld django-evolution + python-passlib + bcrypt Services Interaction: - Vanilla forums + Mysql Forums Mumble Prosody (jabber) diff --git a/allianceauth/settings.py b/allianceauth/settings.py index 2807bfe0..5a793f6f 100644 --- a/allianceauth/settings.py +++ b/allianceauth/settings.py @@ -83,6 +83,15 @@ DATABASES = { 'PASSWORD': 'allianceauth', 'HOST': '127.0.0.1', 'PORT': '3306', + }, + + 'phpbb3': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'alliance_forum', + 'USER': 'allianceauth', + 'PASSWORD': 'allianceauth', + 'HOST': '127.0.0.1', + 'PORT': '3306', } } diff --git a/allianceauth/urls.py b/allianceauth/urls.py index 20324af0..a2b28b9b 100644 --- a/allianceauth/urls.py +++ b/allianceauth/urls.py @@ -11,6 +11,8 @@ urlpatterns = patterns('', url(r'^characters/', 'portal.views.characters_view', name='characters'), url(r'^apikeymanagment/', 'portal.views.apikeymanagment_view', name='apimanagment'), 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'^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/authentication/models.py b/authentication/models.py index 3a3d2904..2f395499 100644 --- a/authentication/models.py +++ b/authentication/models.py @@ -59,6 +59,9 @@ class AllianceUserManager(BaseUserManager): user = AllianceUser.objects.get(id=user_id) user.main_char_id = character_id user.save(update_fields=['main_char_id']) + + def check_if_user_exist(self, user_id): + return AllianceUser.objects.filter(id=user_id).exists() # The icv user class AllianceUser(AbstractBaseUser): diff --git a/evespecific/managers.py b/evespecific/managers.py index 2e45930c..ace198a6 100644 --- a/evespecific/managers.py +++ b/evespecific/managers.py @@ -27,11 +27,15 @@ class EveCharacterManager(): def get_characters_by_owner_id(self, owner_id): return EveCharacter.objects.all().filter(allianceuser_owner=owner_id) + def get_character_by_id(self, char_id): + if EveCharacter.objects.filter(character_id = char_id).exists(): + return EveCharacter.objects.get(character_id=char_id) + + return None + def check_if_character_owned_by_user(self, char_id, user_id): character = EveCharacter.objects.get(character_id = char_id) - print char_id - print user_id - print character.allianceuser_owner + if character.allianceuser_owner.id == user_id: return True diff --git a/portal/views.py b/portal/views.py index f2a4802d..b9680ffd 100644 --- a/portal/views.py +++ b/portal/views.py @@ -6,6 +6,8 @@ from forms import UpdateKeyForm from evespecific.managers import EveCharacterManager from authentication.models import AllianceUserManager +from util.phpbb3_manager import Phpbb3Manager + # Create your views here. @login_required def index(request): @@ -39,3 +41,24 @@ def apikeymanagment_view(request): form = UpdateKeyForm(initial={'api_id':request.user.api_id,'api_key':request.user.api_key}) return render_to_response('public/apikeymanagment.html', {'form':form}, context_instance=RequestContext(request)) + +@login_required +def applications_view(request): + return render_to_response('public/applications.html', None, context_instance=RequestContext(request)) + +@login_required +def activate_forum(request): + userManager = AllianceUserManager() + forumManager = Phpbb3Manager() + + if userManager.check_if_user_exist(request.user.id): + # Valid now we get the main characters + characterManager = EveCharacterManager() + character = characterManager.get_character_by_id(request.user.main_char_id) + + if forumManager.check_user(character.character_name) == False: + forumManager.add_user(character.character_name, "test", request.user.email, ['REGISTERED']) + return HttpResponseRedirect("/applications/") + + return HttpResponseRedirect("/") + diff --git a/templates/public/applications.html b/templates/public/applications.html new file mode 100644 index 00000000..41330482 --- /dev/null +++ b/templates/public/applications.html @@ -0,0 +1,16 @@ +{% extends "public/base.html" %} +{% load staticfiles %} + +{% block title %}Alliance Auth{% endblock %} + +{% block page_title %}Something something here{% endblock page_title %} +{% block extra_css %}{% endblock extra_css %} + +{% block content %} +
+

Really dumb right now

+

Click button to add user to services

+ +
+ +{% endblock content %} diff --git a/templates/public/base.html b/templates/public/base.html index a3404c3d..26363fa5 100644 --- a/templates/public/base.html +++ b/templates/public/base.html @@ -52,7 +52,7 @@
  • Overview
  • Characters
  • Api Keys
  • -
  • Applications
  • +
  • Applications
  • Help
  • diff --git a/util/phpbb3_manager.py b/util/phpbb3_manager.py new file mode 100644 index 00000000..ec7cc654 --- /dev/null +++ b/util/phpbb3_manager.py @@ -0,0 +1,61 @@ +import hashlib +import random +from passlib.apps import phpbb3_context +from django.conf import settings +from django.db import connections, transaction + +class Phpbb3Manager(): + + SQL_ADD_USER = r"INSERT INTO phpbb_users (username, username_clean, user_password, user_email, group_id , user_permissions, user_sig, user_occ, user_interests) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)" + SQL_DIS_USER = r"DELETE FROM phpbb_user_groups where user_id = (SELECT user_id FROM phpbb_users WHERE username = %s)" + SQL_CHECK_USER = r"SELECT user_id from phpbb_users WHERE username = %s" + + SQL_ADD_USER_GROUP = r"INSERT INTO phpbb_user_group (group_id, user_id, user_pending) VALUES (%s, %s, %s)" + SQL_GET_GROUP = r"SELECT group_id from phpbb_groups WHERE group_name = %s" + SQL_ADD_GROUP = r"INSERT INTO phpbb_groups (group_name) VALUES (%s)" + + def __init__(self): + pass + + def _gen_salt(self): + return "%x" % random.randint(0, 2147483647) + + def _gen_hash(self, password): + return phpbb3_context.encrypt(password) + + def add_user(self, username, password, email, groups): + + cursor = connections['phpbb3'].cursor() + + """ Add a user """ + username_clean = username.lower() + pwhash = self._gen_hash(password) + cursor.execute(self.SQL_ADD_USER, [username, username_clean, pwhash, email, 2, "", "","", ""]) + self.update_groups(username,groups) + return { 'username': username, 'password': password } + + def update_groups(self, username, groups): + cursor = connections['phpbb3'].cursor() + + cursor.execute(self.SQL_CHECK_USER, [username]) + row = cursor.fetchone() + userid = row[0] + for group in groups: + cursor.execute(self.SQL_GET_GROUP, [group]) + row = cursor.fetchone() + print row + if not row: + cursor.execute(self.SQL_ADD_GROUP, [group]) + cursor.execute(self.SQL_GET_GROUP, [group]) + row = cursor.fetchone() + + cursor.execute(self.SQL_ADD_USER_GROUP, [row[0], userid,0]) + + def check_user(self, username): + cursor = connections['phpbb3'].cursor() + """ Check if the username exists """ + cursor.execute(self.SQL_CHECK_USER, [username]) + row = cursor.fetchone() + if row: + return True + return False \ No newline at end of file