diff --git a/authentication/models.py b/authentication/models.py index a6c983ef..29bbbeec 100755 --- a/authentication/models.py +++ b/authentication/models.py @@ -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) diff --git a/services/managers/discord_manager.py b/services/managers/discord_manager.py index 9f5ccaf3..d8102e24 100644 --- a/services/managers/discord_manager.py +++ b/services/managers/discord_manager.py @@ -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 "", "" diff --git a/services/views.py b/services/views.py index b612d6ce..100f05b5 100755 --- a/services/views.py +++ b/services/views.py @@ -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) diff --git a/stock/templates/registered/services.html b/stock/templates/registered/services.html index 0a2d4d86..85837823 100755 --- a/stock/templates/registered/services.html +++ b/stock/templates/registered/services.html @@ -114,6 +114,31 @@ {% endif %} + {% if ENABLE_BLUE_DISCORD %} +
Discord | +{{ authinfo.discord_username }} | +{{ authinfo.discord_password }} | +https://discordapp.com | ++ {% ifequal authinfo.discord_username "" %} + + + + {% else %} + + + + + + + {% endifequal %} + | +
Service | diff --git a/util/common_task.py b/util/common_task.py index 5c613447..dc7bf364 100755 --- a/util/common_task.py +++ b/util/common_task.py @@ -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):
---|