示例#1
0
 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})
示例#2
0
 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})
示例#3
0
 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]))
示例#4
0
 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]))
示例#5
0
 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
示例#6
0
 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()
示例#7
0
 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
示例#8
0
 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
示例#9
0
 def __init__(self):
     self.env = Environment(loader=PackageLoader('blenheim', 'template'),
                            trim_blocks=True,
                            lstrip_blocks=True)
     self.config = Config()
示例#10
0
 async def resolve_domains(self, info: ResolveInfo):
     if info.context.get('current_user'):
         return create_domain_list(Config())
示例#11
0
 async def resolve_ipv6(self, info: ResolveInfo):
     if info.context.get('current_user'):
         return Config()['settings']['ipv6']
示例#12
0
 async def resolve_default_subdomains(self, info: ResolveInfo):
     if info.context.get('current_user'):
         return Config()['settings']['default_subdomains']
示例#13
0
 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)
示例#14
0
 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)