Add user importing from 3 - servers to be added

This commit is contained in:
xithical 2022-03-18 21:55:39 -05:00
parent 7c822b715a
commit 4c14b58a2a
2 changed files with 42 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import logging
from app.classes.shared.console import console from app.classes.shared.console import console
from app.classes.shared.helpers import helper from app.classes.shared.helpers import helper
from app.classes.shared.import3 import import3
from app.classes.web.websocket_helper import websocket_helper from app.classes.web.websocket_helper import websocket_helper
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -58,6 +59,10 @@ class MainPrompt(cmd.Cmd):
else: else:
print(f'Name: {thread.name} Identifier: {thread.ident}') print(f'Name: {thread.name} Identifier: {thread.ident}')
@staticmethod
def do_import3():
import3.start_import()
def universal_exit(self): def universal_exit(self):
logger.info("Stopping all server daemons / threads") logger.info("Stopping all server daemons / threads")
console.info("Stopping all server daemons / threads - This may take a few seconds") console.info("Stopping all server daemons / threads - This may take a few seconds")
@ -75,3 +80,7 @@ class MainPrompt(cmd.Cmd):
@staticmethod @staticmethod
def help_migrations(): def help_migrations():
console.help("Only for advanced users. Use with caution") console.help("Only for advanced users. Use with caution")
@staticmethod
def help_import3():
console.help("Import users and servers from Crafty 3")

View File

@ -0,0 +1,33 @@
import json
import os
import console
import logging
logger = logging.getLogger(__name__)
from app.classes.controllers.users_controller import users_helper
from app.classes.shared.main_controller import Controller
class import3:
def start_import(self):
folder = os.path.normpath(input("Please input the path to the migrations folder in your installation of Crafty 3: "))
if not os.path.exists(folder):
console.log("Crafty cannot find the path you entered. Does Crafty's user have permission to access it?")
console.log("Please run the import3 command again and enter a valid path.")
else:
with open (os.path.join(folder, "users.json")) as f:
user_json = json.load(f.read())
with open (os.path.join(folder, "mc_settings.json")) as f:
servers_json = json.load(f.read())
self.import_users(user_json)
self.import_servers(servers_json)
@staticmethod
def import_users(json_data):
for user in json_data:
users_helper.add_rawpass_user(user.username, user.password)
console.log(f"Imported user {user.username} from Crafty 3")
logger.info(f"Imported user {user.username} from Crafty 3")
@staticmethod
def import_servers(json_data):
return