mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-14 06:50:15 +02:00
Included Discord in disable_services from common_task.
Changed how user accounts in discord are handled: endpoint accepts password and email. Accounts are created with a password(random) and their user email. Need to activate account through link in email.
This commit is contained in:
parent
90522a5053
commit
c009420536
@ -14,7 +14,7 @@ class AuthServicesInfo(models.Model):
|
||||
teamspeak3_uid = models.CharField(max_length=254, default="")
|
||||
teamspeak3_perm_key = models.CharField(max_length=254, default="")
|
||||
discord_username = models.CharField(max_length=254, default="")
|
||||
discord_uid = models.CharField(max_length=254, default="")
|
||||
discord_password = models.CharField(max_length=254, default="")
|
||||
main_char_id = models.CharField(max_length=64, default="")
|
||||
is_blue = models.BooleanField(default=False)
|
||||
user = models.ForeignKey(User)
|
||||
|
@ -2,6 +2,7 @@ import requests
|
||||
import json
|
||||
from django.conf import settings
|
||||
import re
|
||||
import os
|
||||
|
||||
DISCORD_URL = "https://discordapp.com/api"
|
||||
|
||||
@ -153,12 +154,14 @@ class DiscordAPIManager:
|
||||
r.raise_for_status()
|
||||
|
||||
@staticmethod
|
||||
def register_user(server_id, username, invite_code):
|
||||
def register_user(server_id, username, invite_code, password, email):
|
||||
custom_headers = {'content-type': 'application/json'}
|
||||
data = {
|
||||
'fingerprint': None,
|
||||
'username': username,
|
||||
'invite': invite_code,
|
||||
'passowrd': password,
|
||||
'email': email,
|
||||
}
|
||||
path = DISCORD_URL + "/auth/register"
|
||||
r = requests.post(path, headers=custom_headers, data=json.dumps(data))
|
||||
@ -213,14 +216,19 @@ class DiscordManager:
|
||||
return clean
|
||||
|
||||
@staticmethod
|
||||
def add_user(username):
|
||||
def __generate_random_pass():
|
||||
return os.urandom(8).encode('hex')
|
||||
|
||||
@staticmethod
|
||||
def add_user(username, email):
|
||||
try:
|
||||
username_clean = DiscordManager.__sanatize_username(username)
|
||||
invite_code = DiscordAPIManager.create_invite(settings.DISCORD_SERVER_ID)['code']
|
||||
DiscordAPIManager.register_user(settings.DISCORD_SERVER_ID, username_clean, invite_code)
|
||||
password = DiscordManager.__generate_random_pass()
|
||||
DiscordAPIManager.register_user(server_id=settings.DISCORD_SERVER_ID, username=username_clean, invite=invite_code, password=password, email=email)
|
||||
user_id = DiscordAPIManager.get_user_id(settings.DISCORD_SERVER_ID, username_clean)
|
||||
DiscordAPIManager.delete_invite(invite_code)
|
||||
return username_clean, user_id
|
||||
return username_clean, password
|
||||
except:
|
||||
return "", ""
|
||||
|
||||
|
@ -325,7 +325,7 @@ context_instance=RequestContext(request))
|
||||
def activate_discord(request):
|
||||
authinfo = AuthServicesInfoManager.get_auth_service_info(request.user)
|
||||
character = EveManager.get_character_by_id(authinfo.main_char_id)
|
||||
info = DiscordManager.add_user(character.character_name)
|
||||
info = DiscordManager.add_user(character.character_name, request.user.email)
|
||||
# If our username is blank means we already had a user
|
||||
if info[0] is not "":
|
||||
AuthServicesInfoManager.update_user_discord_info(info[0], info[1], request.user)
|
||||
@ -352,7 +352,7 @@ def reset_discord(request):
|
||||
if result:
|
||||
# ensures succesful deletion
|
||||
AuthServicesInfoManager.update_user_discord_info("", "", request.user)
|
||||
new_result = DiscordManager.add_user(authinfo.discord_username)
|
||||
new_result = DiscordManager.add_user(authinfo.discord_username, request.user.email)
|
||||
if new_result:
|
||||
# ensures succesful creation
|
||||
AuthServicesInfoManager.update_user_discord_info(new_result[0], new_result[1], request.user)
|
||||
|
@ -114,6 +114,31 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if ENABLE_BLUE_DISCORD %}
|
||||
<tr>
|
||||
<td class="text-center">Discord</td>
|
||||
<td class="text-center">{{ authinfo.discord_username }}</td>
|
||||
<td class="text-center">{{ authinfo.discord_password }}</td>
|
||||
<td class="text-center"><a href="https://discordapp.com/channels/{{ DISCORD_SERVER_ID }}/{{ DISCORD_SERVER_ID}}">https://discordapp.com</a></td>
|
||||
<td class="text-center">
|
||||
{% ifequal authinfo.discord_username "" %}
|
||||
<a href="{% url 'auth_activate_discord' %}">
|
||||
<button type="button" class="btn btn-warning"><span
|
||||
class="glyphicon glyphicon-ok"></span></button>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="{% url 'auth_reset_discord' %}">
|
||||
<button type="button" class="btn btn-primary"><span
|
||||
class="glyphicon glyphicon-refresh"></span></button>
|
||||
</a>
|
||||
<a href="{% url 'auth_deactivate_discord' %}">
|
||||
<button type="button" class="btn btn-danger"><span
|
||||
class="glyphicon glyphicon-remove"></span></button>
|
||||
</a>
|
||||
{% endifequal %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if ENABLE_BLUE_TEAMSPEAK3 %}
|
||||
<tr>
|
||||
<th class="text-center">Service</th>
|
||||
@ -152,38 +177,6 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if ENABLE_BLUE_DISCORD %}
|
||||
<tr>
|
||||
<th class="text-center">Service</th>
|
||||
<th class="text-center">Username</th>
|
||||
<th class="text-center">User ID</th>
|
||||
<th class="text-center">Domain</th>
|
||||
<th class="text-center">Action</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-center">Discord</td>
|
||||
<td class="text-center">{{ authinfo.discord_username }}</td>
|
||||
<td class="text-center">{{ authinfo.discord_uid }}</td>
|
||||
<td class="text-center"><a href="https://discordapp.com/channels/{{ DISCORD_SERVER_ID }}/{{ DISCORD_SERVER_ID}}">https://discordapp.com</a></td>
|
||||
<td class="text-center">
|
||||
{% ifequal authinfo.discord_username "" %}
|
||||
<a href="{% url 'auth_activate_discord' %}">
|
||||
<button type="button" class="btn btn-warning"><span
|
||||
class="glyphicon glyphicon-ok"></span></button>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="{% url 'auth_reset_discord' %}">
|
||||
<button type="button" class="btn btn-primary"><span
|
||||
class="glyphicon glyphicon-refresh"></span></button>
|
||||
</a>
|
||||
<a href="{% url 'auth_deactivate_discord' %}">
|
||||
<button type="button" class="btn btn-danger"><span
|
||||
class="glyphicon glyphicon-remove"></span></button>
|
||||
</a>
|
||||
{% endifequal %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
</table>
|
||||
{% elif perms.auth.member %}
|
||||
<table class="table table-bordered">
|
||||
@ -292,6 +285,31 @@
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if ENABLE_AUTH_DISCORD %}
|
||||
<tr>
|
||||
<td class="text-center">Discord</td>
|
||||
<td class="text-center">{{ authinfo.discord_username }}</td>
|
||||
<td class="text-center">{{ authinfo.discord_password }}</td>
|
||||
<td class="text-center"><a href="https://discordapp.com/channels/{{ DISCORD_SERVER_ID }}/{{ DISCORD_SERVER_ID}}">https://discordapp.com</a></td>
|
||||
<td class="text-center">
|
||||
{% ifequal authinfo.discord_username "" %}
|
||||
<a href="{% url 'auth_activate_discord' %}">
|
||||
<button type="button" class="btn btn-warning"><span
|
||||
class="glyphicon glyphicon-ok"></span></button>
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="{% url 'auth_reset_discord' %}">
|
||||
<button type="button" class="btn btn-primary"><span
|
||||
class="glyphicon glyphicon-refresh"></span></button>
|
||||
</a>
|
||||
<a href="{% url 'auth_deactivate_discord' %}">
|
||||
<button type="button" class="btn btn-danger"><span
|
||||
class="glyphicon glyphicon-remove"></span></button>
|
||||
</a>
|
||||
{% endifequal %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if ENABLE_AUTH_TEAMSPEAK3 %}
|
||||
<tr>
|
||||
<th class="text-center">Service</th>
|
||||
|
@ -7,6 +7,7 @@ from services.managers.phpbb3_manager import Phpbb3Manager
|
||||
from services.managers.mumble_manager import MumbleManager
|
||||
from services.managers.ipboard_manager import IPBoardManager
|
||||
from services.managers.teamspeak3_manager import Teamspeak3Manager
|
||||
from services.managers.discord_manager import DiscordManager
|
||||
|
||||
|
||||
def add_user_to_group(user, groupname):
|
||||
@ -41,6 +42,9 @@ def deactivate_services(user):
|
||||
if authinfo.teamspeak3_uid and authinfo.teamspeak3_uid != "":
|
||||
Teamspeak3Manager.delete_user(authinfo.teamspeak3_uid)
|
||||
AuthServicesInfoManager.update_user_teamspeak3_info("", "", user)
|
||||
if authinfo.discord_username and authinfo.discord_username != "":
|
||||
DiscordManager.delete_user(authinfo.discord_username)
|
||||
AuthServicesInfoManager.update_user_discord_info("", "", user)
|
||||
|
||||
|
||||
def generate_corp_group_name(corpname):
|
||||
|
Loading…
x
Reference in New Issue
Block a user