mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 12:30:15 +02:00
Very messy forum account creation
This commit is contained in:
parent
de253f60e3
commit
cd8befe506
@ -9,9 +9,11 @@ Requirments:
|
|||||||
python-mysql-connector
|
python-mysql-connector
|
||||||
python-mysqld
|
python-mysqld
|
||||||
django-evolution
|
django-evolution
|
||||||
|
python-passlib
|
||||||
|
bcrypt
|
||||||
|
|
||||||
Services Interaction:
|
Services Interaction:
|
||||||
Vanilla forums
|
Mysql Forums
|
||||||
Mumble
|
Mumble
|
||||||
Prosody (jabber)
|
Prosody (jabber)
|
||||||
|
|
||||||
|
@ -83,6 +83,15 @@ DATABASES = {
|
|||||||
'PASSWORD': 'allianceauth',
|
'PASSWORD': 'allianceauth',
|
||||||
'HOST': '127.0.0.1',
|
'HOST': '127.0.0.1',
|
||||||
'PORT': '3306',
|
'PORT': '3306',
|
||||||
|
},
|
||||||
|
|
||||||
|
'phpbb3': {
|
||||||
|
'ENGINE': 'django.db.backends.mysql',
|
||||||
|
'NAME': 'alliance_forum',
|
||||||
|
'USER': 'allianceauth',
|
||||||
|
'PASSWORD': 'allianceauth',
|
||||||
|
'HOST': '127.0.0.1',
|
||||||
|
'PORT': '3306',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ urlpatterns = patterns('',
|
|||||||
url(r'^characters/', 'portal.views.characters_view', name='characters'),
|
url(r'^characters/', 'portal.views.characters_view', name='characters'),
|
||||||
url(r'^apikeymanagment/', 'portal.views.apikeymanagment_view', name='apimanagment'),
|
url(r'^apikeymanagment/', 'portal.views.apikeymanagment_view', name='apimanagment'),
|
||||||
url(r'^maincharacterchange/(\d+)/$', 'portal.views.main_character_change', name='main_character_change'),
|
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'^loginuser/','authentication.views.login_user', name='loginuser'),
|
||||||
url(r'^logoutuser/','authentication.views.logout_user', name='logoutuser'),
|
url(r'^logoutuser/','authentication.views.logout_user', name='logoutuser'),
|
||||||
url(r'^register/', 'registration.views.register', name='register'),
|
url(r'^register/', 'registration.views.register', name='register'),
|
||||||
|
@ -59,6 +59,9 @@ class AllianceUserManager(BaseUserManager):
|
|||||||
user = AllianceUser.objects.get(id=user_id)
|
user = AllianceUser.objects.get(id=user_id)
|
||||||
user.main_char_id = character_id
|
user.main_char_id = character_id
|
||||||
user.save(update_fields=['main_char_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
|
# The icv user
|
||||||
class AllianceUser(AbstractBaseUser):
|
class AllianceUser(AbstractBaseUser):
|
||||||
|
@ -27,11 +27,15 @@ class EveCharacterManager():
|
|||||||
def get_characters_by_owner_id(self, owner_id):
|
def get_characters_by_owner_id(self, owner_id):
|
||||||
return EveCharacter.objects.all().filter(allianceuser_owner=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):
|
def check_if_character_owned_by_user(self, char_id, user_id):
|
||||||
character = EveCharacter.objects.get(character_id = char_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:
|
if character.allianceuser_owner.id == user_id:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ from forms import UpdateKeyForm
|
|||||||
|
|
||||||
from evespecific.managers import EveCharacterManager
|
from evespecific.managers import EveCharacterManager
|
||||||
from authentication.models import AllianceUserManager
|
from authentication.models import AllianceUserManager
|
||||||
|
from util.phpbb3_manager import Phpbb3Manager
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
@login_required
|
@login_required
|
||||||
def index(request):
|
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})
|
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))
|
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("/")
|
||||||
|
|
||||||
|
16
templates/public/applications.html
Normal file
16
templates/public/applications.html
Normal file
@ -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 %}
|
||||||
|
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
|
||||||
|
<h3> Really dumb right now</h3>
|
||||||
|
<p> Click button to add user to services</p>
|
||||||
|
<a href="/activateforum/"><button type="button" class="btn btn-default">Activate Forum</button></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock content %}
|
@ -52,7 +52,7 @@
|
|||||||
<li><a href="/">Overview</a></li>
|
<li><a href="/">Overview</a></li>
|
||||||
<li><a href="/characters">Characters</a></li>
|
<li><a href="/characters">Characters</a></li>
|
||||||
<li><a href="/apikeymanagment">Api Keys</a></li>
|
<li><a href="/apikeymanagment">Api Keys</a></li>
|
||||||
<li><a href="#">Applications</a></li>
|
<li><a href="/applications">Applications</a></li>
|
||||||
<li><a href="#">Help</a></li>
|
<li><a href="#">Help</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
61
util/phpbb3_manager.py
Normal file
61
util/phpbb3_manager.py
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user