def mutate(self, info, id: str): if info.context.get('current_user'): config = Config() setting = config['settings'][setting_id] setting.append(id) config.save() return Settings(**{setting_id: setting})
def mutate(self, info, id: str, index: int): if info.context.get('current_user'): config = Config() setting = config['settings'][setting_id] setting[index] = id config.save() return Settings(**{setting_id: setting})
def mutate(self, info, id: str, index: int): if info.context.get('current_user'): config = Config() del config['domains'][id][index][setting_id] config.save() return Domain(id=id, subdomains=create_subdomain_list( config['domains'][id]))
def mutate(self, info, id: str, name: str): if info.context.get('current_user'): config = Config() config['domains'][id].append({'subdomain': name}) config.save() return Domain(id=id, subdomains=create_subdomain_list( config['domains'][id]))
async def resolve_change_password(self, info: ResolveInfo, password: str): current_user = info.context.get('current_user') if current_user: config = Config() config[USERS][current_user['name']]['password'] = ( await Authentication.hash_password(password)) config.save() return True return False
async def expire_tokens(): config = Config() to_delete = [] for key, value in config[TOKENS].items(): elapsed = datetime.now() - datetime.fromisoformat(value['created']) if elapsed.seconds > 60 * 60: to_delete.append(key) for key in to_delete: del config[TOKENS][key] config.save()
async def resolve_login(self, info: ResolveInfo, details: UserInput): await Authentication.expire_tokens() config = Config() user = config[USERS].get(str(details.name)) if (user and user.get('password') == await Authentication.hash_password(details.password)): token = token_urlsafe() config[TOKENS][token] = { 'user': details.name, 'created': datetime.now().isoformat() } config.save() return token
async def resolve_token(self, info: ResolveInfo, token: str): await Authentication.expire_tokens() config = Config() token_data = config[TOKENS].get(token) if token_data: user = config[USERS][token_data['user']] info.context['current_user'] = user info.context['current_token'] = token return token
def __init__(self): self.env = Environment(loader=PackageLoader('blenheim', 'template'), trim_blocks=True, lstrip_blocks=True) self.config = Config()
async def resolve_domains(self, info: ResolveInfo): if info.context.get('current_user'): return create_domain_list(Config())
async def resolve_ipv6(self, info: ResolveInfo): if info.context.get('current_user'): return Config()['settings']['ipv6']
async def resolve_default_subdomains(self, info: ResolveInfo): if info.context.get('current_user'): return Config()['settings']['default_subdomains']
def mutate(self, info, id: str): if info.context.get('current_user'): config = Config() del config['domains'][id] config.save() return create_domain_list(config)
def mutate(self, info, id: str, new_name: str): if info.context.get('current_user'): config = Config() config['domains'][new_name] = config['domains'].pop(id) config.save() return create_domain_list(config)