Beispiel #1
0
 def handle(self):
     while True:
         # login_auth
         headers_login_auth = self.recv_data_packet_server()
         if headers_login_auth['operation'] == '0':
             # 退出
             break
         elif headers_login_auth['operation'] == '1':
             # 登录
             account = headers_login_auth['account']
             password = headers_login_auth['password']
             ret_login = User.login_auth(account,
                                         password)  # ret_login true false
             if ret_login:
                 self.send_state_code_server(1)
                 break
             else:
                 self.send_state_code_server(0)
         elif headers_login_auth['operation'] == '2':
             # 注册
             account = headers_login_auth['account']
             password = headers_login_auth['password']
             ret_register = User.register(
                 account, password)  # ret_register  true false
             if ret_register:
                 self.send_state_code_server(1)
                 break
             else:
                 self.send_state_code_server(0)
     if headers_login_auth['operation'] != '0':
         # 当用户认证成功进入此模块
         user = User(headers_login_auth['account'])
         while True:
             # operation_choice
             headers_operation = self.recv_data_packet_server()
             if headers_operation['operation'] == '0':
                 # exit
                 break
             elif headers_operation['operation'] == '1':
                 # enter_upper_contents,进入上层目录
                 ret_data = user.enter_upper_contents()
                 self.send_data_server(ret_data)
             elif headers_operation['operation'] == '2':
                 # enter_lower_contents,进入下层目录
                 lower_contents_name = headers_operation[
                     'lower_contents_name']
                 ret_data = user.enter_lower_contents(lower_contents_name)
                 self.send_data_server(ret_data)
             elif headers_operation['operation'] == '3':
                 # create_folder,创建新文件夹
                 new_folder_name = headers_operation['new_folder_name']
                 ret_state = user.create_folder(new_folder_name)
                 ret_state = 1 if ret_state else 0
                 self.send_state_code_server(ret_state)
             elif headers_operation['operation'] == '4':
                 # clear_empty_file,清空空文件和空文件夹
                 ret_data = user.clear_empty_file()
                 self.send_data_server(ret_data)
             elif headers_operation['operation'] == '5':
                 # show_file,展示当前文件夹内的文件信息
                 ret_data = user.show_file()
                 self.send_data_server(ret_data)
             elif headers_operation['operation'] == '6':
                 # uploading_files,上传文件
                 self.recv_data_file_server(headers_operation, user)
             elif headers_operation['operation'] == '7':
                 # download_files,下载文件,未实现
                 pass
     self.request.close()