def handle(self): try: while True: auth_info = self.request.recv(1024).decode() auth_type, user, pwd = auth_info.split(':') auth_user = Auth(user, pwd) if auth_type == 'register': status_code = auth_user.register() self.request.sendall(status_code.encode()) elif auth_type == 'login': user_dict = auth_user.login() if user_dict: self.request.sendall(b'200') self.user_current_path = user_dict['home_path'] self.user_home_path = user_dict['home_path'] self.user_limit_size = user_dict['limit_size'] while True: command = self.request.recv(1024).decode() if not command: continue command_str = command.split()[0] if hasattr(self, command_str): func = getattr(self, command_str) func(command) else: self.request.sendall(b'400') except ConnectionResetError as e: print('Error:', e)
def handle(self): while True: try: user_info = self.request.recv(1024).decode() if not user_info: continue Logger.info('[%s:%s] 连接成功.' % self.client_address) auth_type = user_info.split(':')[-1] auth = Auth(user_info) if auth_type == 'register': auth_code = auth.register() self.request.sendall(auth_code.encode()) # if auth_code != '201': # continue elif auth_type == 'login': auth_code, user_dict = auth.login() self.user_home_path = user_dict['home_path'] self.user_current_path = user_dict['home_path'] self.limit_size = user_dict['limit_size'] self.request.sendall(auth_code.encode()) print('auth_code:', auth_code) if auth_code != '200': continue while True: command = self.request.recv(1024).decode() print(command) if not command: continue command_str = command.split()[0] if hasattr(self, command_str): func = getattr(self, command_str) func(command) # cmd = self.request.recv(1024).decode() # cmd = input('>>>') except ConnectionResetError as e: print('Error:', e) Logger.info('[%s:%s] 断开连接.' % self.client_address) break
def handle(self): try: while True: auth_info = self.request.recv(1024).decode() # auth_type, user, pwd, email n = auth_info.count(':') if n == 2: auth_type, user, pwd = auth_info.split(':') auth_user = Auth(user, pwd) else: auth_type, user, pwd, email = auth_info.split(':') auth_user = Auth(user, pwd, email) if auth_type == 'register': status_code = auth_user.register() self.request.sendall(status_code.encode()) elif auth_type == 'login': user_dict = auth_user.login() if user_dict: self.request.sendall(b'200') self.user_name = user_dict[0] self.user_current_path = user_dict[2] self.user_home_path = user_dict[2] self.user_limit_size = int(user_dict[3]) while True: opt = self.request.recv(1024).decode() if opt == '1': self.chat() elif opt == '2': email = self.getmail(self.user_name) self.request.sendall(email.encode()) elif opt == '3': email = self.getmail(self.user_name) print(self.user_name) print(email) self.request.sendall(email.encode()) elif opt == '4': receiver = self.request.recv(1024).decode() file = self.request.recv(1024).decode() self.recvfile(receiver, file) elif opt == '5': self.user_current_path = Shared_PATH self.user_home_path = Shared_PATH self.user_limit_size = LIMIT_SIZE while True: command = self.request.recv(1024).decode() print(command) command_str = command.split()[0] if hasattr(self, command_str): func = getattr(self, command_str) func(command) elif opt == '6': while True: command = self.request.recv(1024).decode() print(command) command_str = command.split()[0] if hasattr(self, command_str): func = getattr(self, command_str) func(command) else: pass else: self.request.sendall(b'400') except ConnectionResetError as e: print('Error:', e)