Exemplo n.º 1
0
 def post(self):
     arg = self.parse.parse_args()
     folder = DiskFolder.get_by_id(**arg)
     if folder:
         folder.delete()
         return Msg.success('ok')
     else:
         return Msg.failed_dict(1002)
Exemplo n.º 2
0
 def post(self):
     arg = self.parse.parse_args()
     file = DiskFile.query_one(id=arg['id'], user_id=g.user.id)
     if file:
         file.update(id=arg['id'], is_trash=1)
         return Msg.success('ok')
     else:
         return Msg.failed_dict(1002)
Exemplo n.º 3
0
 def post(self):
     arg = self.parse.parse_args()
     folder = DiskFolder.get_by_id(arg['id'])
     if folder:
         print(arg)
         folder.update(**arg)
         return Msg.success('ok')
     else:
         return Msg.failed_dict(1002)
Exemplo n.º 4
0
 def post(self):
     arg = config_parse.parse_args()
     config = FConfig.query_one(server_name=arg['server_name'])
     if config:
         arg['update_time'] = datetime.now()
         config.update(**arg)
         arg['update_time'] = str(config.update_time)
         arg['create_time'] = str(config.create_time)
         return Msg.success('ok', config=arg)
     else:
         FConfig.create(**arg)
         return Msg.success('ok', config=arg)
Exemplo n.º 5
0
 def post(self):
     user_id = g.user.id
     arg = self.folder_parse.parse_args()
     arg['user_id'] = user_id
     print(arg)
     folder = DiskFolder.create(**arg)
     return Msg.success('ok', id=folder.id)
Exemplo n.º 6
0
    def decorated_view(*args, **kwargs):

        roles = g.user.roles
        if roles == ADMIN:
            return func(*args, **kwargs)
        elif roles == GROUP:
            return func(*args, **kwargs)
        else:
            return Msg.failed_dict(2001)
Exemplo n.º 7
0
    def post(self):
        arg = login_parse.parse_args()

        user = User.query.filter_by(username=arg.get('username')).first()
        if user:
            if user.check_password(arg.get('password')):
                next = request.args.get('next')
                # next_is_valid should check if the user has valid
                # identity_changed.send(current_app._get_current_object(), identity=Identity(user.id))
                # permission to access the `next` url
                if not next_is_valid(next):
                    return {'message': 'next url valid failed'}, 400
                return Msg.success('登录成功',
                                   assess_key=user.generate_auth_token())
            else:
                return Msg.login_password_error('用户名和密码不匹配')
        else:
            return Msg.login_username_error('用户名不存在')
Exemplo n.º 8
0
 def post(self):
     arg = self.folder_parse.parse_args()
     ad_config = FConfig.query_one(server_name=SERVER_NAME)
     backup_base_path = ad_config.backup_base_path
     path = os.path.join(backup_base_path, arg['file_name'])
     file = arg['file_data']
     file.save(path)
     arg['path'] = path
     arg.pop('file_data')
     Backup.create(**arg)
     return Msg.success('ok', filename=arg['file_name'])
Exemplo n.º 9
0
    def post(self):
        user_id = g.user.id
        arg = self.folder_parse.parse_args()
        arg['user_id'] = user_id
        file = arg['file_data']
        arg.pop('file_data')
        file_data = file.read()
        file_size = len(file_data) / 1024
        check_size = True if g.user.max_size > (g.user.use_size + file_size) else False
        if check_size:
            arg['file_size'] = file_size
            arg['show_name'] = file.filename
            file_obj = DiskFile(**arg)
            filename = file_obj.file_name
            save_path = os.path.join(UPLOAD_PATH, g.user.use_folder)
            path = os.path.join(save_path, filename)
            file.save(path)
            file_obj.save()
            arg['path'] = path
            back_up_task.apply_async(args=[arg, ], countdown=60*5)

            return Msg.success('ok')
        else:
            return Msg.failed_dict(1001)
Exemplo n.º 10
0
    def decorated_view(*args, **kwargs):
        # first, try to login using the api_key url arg
        api_key = request.args.get('assess_key')
        if api_key:
            user = User.verify_auth_token(api_key)
            if user:
                g.user = user
                return func(*args, **kwargs)

        api_key = request.form.get('assess_key')
        if api_key:
            user = User.verify_auth_token(api_key)
            if user:
                g.user = user
                return func(*args, **kwargs)

        if request.json:
            api_key = request.json.get('assess_key')
            if api_key:
                user = User.verify_auth_token(api_key)
                if user:
                    g.user = user
                    return func(*args, **kwargs)
        # next, try to login using Basic Auth
        api_key = request.headers.get('Authorization')
        if api_key:
            api_key = api_key.replace('Basic ', '', 1)
            try:
                api_key = base64.b64decode(api_key)
            except TypeError:
                pass
            user = User.verify_auth_token(api_key)
            if user:
                g.user = user
                return func(*args, **kwargs)

        # finally, return None if both methods did not login the user
        return Msg.authorized_failed()
Exemplo n.º 11
0
 def get(self):
     return Msg.success('hello word')
Exemplo n.º 12
0
 def post(self):
     return Msg.success('logout success')
Exemplo n.º 13
0
 def get(self):
     return Msg.success('success')