def post(self, **kw): data = Bunch(kw) try: data.key = int(data.key) if data.key <= KEY_RESET_FLOOR: return 'json:', dict(success=False, message=_("The key given (%d) must be above minimum reset floor value of %d. Please reset your EVE API Key." % (data.key, KEY_RESET_FLOOR)), field='key') except ValueError: return 'json:', dict(success=False, message=_("Key ID must be a number."), field='key') record = EVECredential(data.key, data.code, owner=user.id) try: record.save() #Necessary to guarantee that the pull finished before returning. record.pull() characters = [] for character in record.characters: characters.append(dict(identifier = character.identifier, name = character.name)) if request.is_xhr: return 'json:', dict( success = True, message = _("Successfully added EVE API key."), identifier = str(record.id), key = record.key, code = record.code, characters = characters, violation = record.violation ) except ValidationError: if request.is_xhr: return 'json:', dict( success = False, message = _("Validation error: one or more fields are incorrect or missing."), ) except NotUniqueError: return 'json:', dict( success = False, message = _("This key has already been added by another account."), ) raise HTTPFound(location='/key/')
def post(self, **kw): data = Bunch(kw) try: data.key = int(data.key) if data.key <= int(config["core.minimum_key_id"]): return ( "json:", dict( success=False, message=_( "The key given (%d) must be above minimum reset floor value of %d. " "Please reset your EVE API Key." % (data.key, int(config["core.minimum_key_id"])) ), field="key", ), ) except ValueError: return "json:", dict(success=False, message=_("Key ID must be a number."), field="key") record = EVECredential(data.key, data.code, owner=user.id) try: record.save() # Necessary to guarantee that the pull finished before returning. record.pull() characters = [] for character in record.characters: characters.append(dict(identifier=character.identifier, name=character.name)) if request.is_xhr: return ( "json:", dict( success=True, message=_("Successfully added EVE API key."), identifier=str(record.id), key=record.key, code=record.code, characters=characters, violation=record.violation, ), ) except ValidationError: if request.is_xhr: return ( "json:", dict(success=False, message=_("Validation error: one or more fields are incorrect or missing.")), ) except NotUniqueError: if EVECredential.objects(key=data.key): # Mark both of these accounts as duplicates to each other. acc = User.objects(username=user.username).first() other = EVECredential.objects(key=data.key).first().owner User.add_duplicate(acc, other) return ( "json:", dict(success=False, message=_("This key has already been added to this or another account.")), ) raise HTTPFound(location="/key/")
def post(self, **kw): data = Bunch(kw) try: data.key = int(data.key) if data.key <= int(config['core.minimum_key_id']): return 'json:', dict( success=False, message=_( "The key given (%d) must be above minimum reset floor value of %d. " "Please reset your EVE API Key." % (data.key, int(config['core.minimum_key_id']))), field='key') except ValueError: return 'json:', dict(success=False, message=_("Key ID must be a number."), field='key') record = EVECredential(data.key, data.code, owner=user.id) try: record.save() #Necessary to guarantee that the pull finished before returning. record.pull() characters = [] for character in record.characters: characters.append( dict(identifier=character.identifier, name=character.name)) if request.is_xhr: return 'json:', dict( success=True, message=_("Successfully added EVE API key."), identifier=str(record.id), key=record.key, code=record.code, characters=characters, violation=record.violation) except ValidationError: if request.is_xhr: return 'json:', dict( success=False, message= _("Validation error: one or more fields are incorrect or missing." ), ) except NotUniqueError: if EVECredential.objects(key=data.key): # Mark both of these accounts as duplicates to each other. acc = User.objects(username=user.username).first() other = EVECredential.objects(key=data.key).first().owner User.add_duplicate(acc, other) return 'json:', dict( success=False, message= _("This key has already been added to this or another account." ), ) raise HTTPFound(location='/key/')