Ejemplo n.º 1
0
 def post(self) -> Response:
     ''' POST response for multiple users
         :returns JSON object
         POST /user/bulk_insert/
     '''
     array = csv_to_json(
         '/Users/cansuulker/PycharmProjects/GJGApi/resources/sample_user_data.csv',
         '/Users/cansuulker/PycharmProjects/GJGApi/resources/sample_user_data.json'
     )
     user_instances = [users(**data) for data in array]
     users.objects.insert(user_instances, load_bulk=False)
     output = users.objects.count()
     return jsonify({'Sample user data loaded': output})
Ejemplo n.º 2
0
 def post(self) -> Response:
     ''' POST response for creating a user
         :returns JSON object
         POST /user/create/
     '''
     data = request.get_json(force=True)
     post_user = users(**data)
     num_users = users.objects.count()
     post_user.rank = num_users + 1
     post_user.points = 0
     post_user.save()
     output = {
         'user_id': str(post_user.id),
         'display_name': str(post_user.display_name),
         'points': post_user.points,
         'rank': post_user.rank
     }
     return jsonify({'result': output})
Ejemplo n.º 3
0
 def handle(self):
     '''
     handle方法
     :return: 无
     '''
     import os
     self.__loger = mylib.mylog(conf.LOGS, isstream = True) # 定义日志对象
     self.__current_user = user('guest', '', conf.DEFAULT_QUOTA) # 定义默认用户
     self.__users = users() # 获取users对象
     self.__home_path =  os.path.abspath(os.path.join(conf.HOME_PATH,self.__current_user.get_username())).replace('\\', '/') # 获取家目录
     self.__current_path = self.__home_path # 定义当前目录
     self.__code_list = conf.CODE_LIST # 定义错误里诶表
     self.__loger.info('Client %s:%s is connect the server' %self.client_address)
     while  True:
         try:
             data = mylib.b2s(self.request.recv(1024)) # 获取客户端命令
         except socket.error as e:
             self.__loger.info('Has lost client %s:%s' %self.client_address)
             break
         if not data:
             self.__loger.info('Has lost client %s:%s' %self.client_address)
             break     #如果收不到客户端数据了(代表客户端断开了),就断开
         self.instruction_allowcation(data) #客户端发过来的数据统一交给功能分发器处理
Ejemplo n.º 4
0
    def handle(self):
        #print(self)
        # 定义当前用户,用来保存当前用户信息
        self.__current_user = {
        "username" : "guest",
        "home" : "home/tmp/",
        "max_size" : conf.TMP_SPACE_SIZE
        }
        # 定义用户对象
        self.__userobj = users.users()

        # self.__users = self.__userobj.get_users()
        # print(self.__users)
        conn = self.request
        # 用户连接后后显示的信息
        conn.sendall(bytes('欢迎使用ftp','utf8'))
        # 获取当前目录
        self.__current_path = self.__current_user['home']

        flag = True
        while flag:
            try:
                # 获取用户命令
                client_cmd = mylib.b2s(conn.recv(100))
                if client_cmd == '': break
                # 将用户命令进行分割,客户端传过来的命令需要使用|分割命令本身和命令相关参数
                client_cmd = client_cmd.split("|")
                # 获取命令
                if client_cmd[0] == 'quit': # 如果是quit,退出当前循环,释放连接
                    flag = False
                    continue
                if hasattr(self, client_cmd[0]): # 根据命令执行相应的方法
                    func = getattr(self, client_cmd[0])
                    func(client_cmd)
            except Exception:
                break
        conn.close()
Ejemplo n.º 5
0
    def handle(self):
        #print(self)
        # 定义当前用户,用来保存当前用户信息
        self.__current_user = {
            "username": "******",
            "home": "home/tmp/",
            "max_size": conf.TMP_SPACE_SIZE
        }
        # 定义用户对象
        self.__userobj = users.users()

        # self.__users = self.__userobj.get_users()
        # print(self.__users)
        conn = self.request
        # 用户连接后后显示的信息
        conn.sendall(bytes('欢迎使用65ftp', 'utf8'))
        # 获取当前目录
        self.__current_path = self.__current_user['home']

        flag = True
        while flag:
            try:
                # 获取用户命令
                client_cmd = mylib.b2s(conn.recv(100))
                if client_cmd == '': break
                # 将用户命令进行分割,客户端传过来的命令需要使用|分割命令本身和命令相关参数
                client_cmd = client_cmd.split("|")
                # 获取命令
                if client_cmd[0] == 'quit':  # 如果是quit,退出当前循环,释放连接
                    flag = False
                    continue
                if hasattr(self, client_cmd[0]):  # 根据命令执行相应的方法
                    func = getattr(self, client_cmd[0])
                    func(client_cmd)
            except Exception:
                break
        conn.close()