def start(self, ip, port, callback): """ Begin listening for client connections at the given address. @param ip The IP address to listen on. @param port The port to listen on. Should be 6660-6669 or 7000. @param callback The function to call when a thread receives a message """ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True) self._hostname = ip sock.bind((ip, port)) while True: # Listen with no queued connections - will block sock.listen(0) # A connection has been acquired - get its info (conn, (ip, _)) = sock.accept() # The user will manage its own connection info usr = User(conn, ip) # Users are autonomous, but store them as a key to keep track of # the channels they belong to self._users[usr] = [] # Let the user start listening on its own thread Thread(target = usr.listen, args = (callback,)).start()
def run(self, server, protocol, command): login = command['account_name'] password = command['password'] public_key = command['public_key'] hashed_password = get_hash(login, password) session = sessionmaker(bind=self.db_engine)() db_user = session.query(SQLUser).filter_by(login=login).first() if db_user: if db_user.password != hashed_password: protocol.send_packet(ResponsePacket(402, command['id'])) session.close() return else: db_user = SQLUser(login=login, password=hashed_password, public_key=public_key) session.add(db_user) session.commit() user = User() user.gid = db_user.gid user.login = db_user.login user.public_key = db_user.public_key user.protocol = protocol protocol.user = user server.logged_users.update({user.login: user}) protocol.send_packet(ResponsePacket(202, command['id']))
def init_app(self, email: str, password: str): db: dataset.Database = self.get_db() system_table = db.get_table("system") if None == system_table.find_one(key="app_00"): user: User = User() user._email = email user._name = re.sub(r"@.*$", "", email) user._password = password self.update_user(user) system_table.insert({"key": "app_00", "value": True}) return True else: return False
import os from server.database import DatabaseManager from server.database import db from server.user import User databaseName = "database_test" os.remove(os.path.abspath('./' + databaseName + ".db")) db = DatabaseManager(databaseName) user1 = User() user1.SetName("Erik Palencik") user1.SetEmail("*****@*****.**") user1.SetPassword( "1234567" ) #If you see this code i dont use this password anywhere, so dont even try db.SerializeClass(user1) rows = db.GetAllUsers().fetchall() print("Writting all users:") for row in rows: print(row)