This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try to change usernames automatically (#290)
Just needed to see how to pinpoint the case when a user is opting-in for the first time.
- Loading branch information
1 parent
fc54d00
commit 7b03954
Showing
4 changed files
with
56 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,16 @@ | ||
import os | ||
|
||
from aspen import Response | ||
from gittip import db | ||
from gittip.networks import change_participant_id | ||
from psycopg2 import IntegrityError | ||
|
||
ALLOWED_ASCII = set("0123456789" | ||
"abcdefghijklmnopqrstuvwxyz" | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
".,-_;:@ ") | ||
|
||
FILENAMES = os.listdir(website.www_root) | ||
|
||
# ========================================================================== ^L | ||
|
||
if user.ANON: | ||
raise Response(404) | ||
|
||
new_participant_id = request.body['participant_id'] | ||
|
||
|
||
# Lightly sanitize input. | ||
# ======================= | ||
# We want to be pretty loose with usernames. Unicode is allowed. So are spaces. | ||
# Control characters aren't. We also limit to 32 characters in length. | ||
|
||
for i, c in enumerate(new_participant_id): | ||
if i == 32: | ||
raise Response(413) # Request Entity Too Large (more or less) | ||
elif ord(c) < 128 and c not in ALLOWED_ASCII: | ||
raise Response(400) # Yeah, no. | ||
elif c not in ALLOWED_ASCII: | ||
raise Response(400) # XXX Burned by an Aspen bug. :`-( | ||
# https://github.com/whit537/aspen/issues/102 | ||
|
||
if new_participant_id in FILENAMES: | ||
raise Response(400) | ||
|
||
|
||
# Persist | ||
# ======= | ||
|
||
try: | ||
if new_participant_id != user.id: | ||
rec = db.fetchone( "UPDATE participants SET id=%s WHERE id=%s " \ | ||
"RETURNING id", (new_participant_id, user.id)) | ||
assert rec is not None # sanity check | ||
assert new_participant_id == rec['id'] # sanity check | ||
change_participant_id(website, user.id, new_participant_id) | ||
response.body = {"participant_id": new_participant_id} | ||
except IntegrityError: | ||
response.code = 409 # Conflict | ||
raise Response(409) # Conflict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters