Ejemplo n.º 1
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})
Ejemplo n.º 2
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})
Ejemplo n.º 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]))
Ejemplo n.º 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]))
Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 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
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)