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)
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)
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)
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)
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)
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)
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('用户名不存在')
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'])
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)
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()
def get(self): return Msg.success('hello word')
def post(self): return Msg.success('logout success')
def get(self): return Msg.success('success')