[Noisebridge-discuss] Fwd: API now lets you create new doorcodes
Danny O'Brien
danny at spesh.com
Mon Nov 5 19:52:34 UTC 2012
---------- Forwarded message ----------
From: Danny O'Brien <danny at spesh.com>
Date: Mon, Nov 5, 2012 at 11:52 AM
Subject: Re: [Noisebridge-discuss] API now lets you create new doorcodes
To: Andrew Byrne <andrew at pachakutech.com>
On Mon, Nov 5, 2012 at 8:30 AM, Andrew Byrne <andrew at pachakutech.com> wrote:
> What field, if any, can we use for short reminders about the people to whom
> we give numbers?
> best.
> -AnB
>
Oh good idea. That should be pretty easy to add to the code at
https://github.com/noisebridge/noise-api/blob/master/api.py
A suggestion is below (new/changed lines marked with + )... I'd have
to think a bit about whitelisting the text, because it's actually
currently just adding to a
textfile. If you strip it so that it's just alphanumeric+spaces
allowed (and a reasonable length), it should be ok i think.
I'll get around to doing this eventually, but you might want to have a go at it.
d.
def add_door_code(oldcode, newcode = 0, note = ""):
oldcode = str(int(oldcode))
if oldcode not in load_door_codes():
raise DoorCodeException(403, "Your current doorcode doesn't
work, so you cannot create a new doorcode.")
if newcode == 0:
newcode = random.randint(10000, 10000000)
newcode = str(int(newcode))
if len(newcode) < 6:
raise DoorCodeException(403, "Preferred new doorcode is too short.")
if len(newcode) > 50:
raise DoorCodeException(403, "Preferred new doorcode is too long.")
+ note = FILTER_THROUGH_WHITELIST_OF_CHARACTERS(request.forms.note)
+ if len(note) > 50:
+ raise DoorCodeException(403, "Note is too long.")
with open(door_codes_path, "a") as f:
fcntl.flock(f, fcntl.LOCK_EX)
+ f.write('%s # from %s, (%s) added %s\n' % (newcode, oldcode,
note, datetime.now()))
fcntl.flock(f, fcntl.LOCK_UN)
return newcode
@api_app.post('/gate/key/<oldcode:int>')
def gate_key_create(oldcode=None):
if 'create' in request.forms and request.forms.create:
if 'preferred' in request.forms and request.forms.preferred:
preferred_code = int(request.forms.preferred)
else:
preferred_code = 0
+ if 'note' in request.forms and request.forms.note:
+ newcode = add_door_code(oldcode, preferred_code, note)
redirect('/gate/key/%s' % (newcode))
return {}
>
> On Mon, Nov 5, 2012 at 2:12 PM, Danny O'Brien <danny at spesh.com> wrote:
>>
>> This needs a nice web page on pony to work for everyone, but for now,
>> those who know how to hack on an API (and already have a doorcode) can
>> finally create new ones like this:
>>
>> https://www.noisebridge.net/wiki/API#POST_.2Fgate.2Fkey.2F.5Bdoorcode.5D
>>
>> Suppose you have a doorcode 8499146, and you'd like to give a friend a
>> new doorcode. She asks if she can have the number '7895473'. Go to
>> your local friendly command line (while in the space), and type:
>>
>> % curl -v -X POST -d create=True -d preferred=7895473
>> http://api.noisebridge.net/gate/key/8499146
>>
>> Voila!
>>
>> It will probably all be broken. Bugs (and preferably fixes) gladly
>> accepted at:
>> https://github.com/noisebridge/noise-api/issues
>>
>> for now.
>>
>> d.
>> _______________________________________________
>> Noisebridge-discuss mailing list
>> Noisebridge-discuss at lists.noisebridge.net
>> https://www.noisebridge.net/mailman/listinfo/noisebridge-discuss
>
>
>
>
> --
> -- --
> -- -- -- --
> -- -- -- -- -- --
> @AndruByrne
> CEO, Pachakutech
> www.pachakutech.com/intro.html
>
More information about the Noisebridge-discuss
mailing list