Skip to content

Commit

Permalink
correcting file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Carter committed Jan 5, 2018
1 parent 9fb3049 commit b6bb1bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lasanfound.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class About(Handler):
def get(self):
self.render("about.html")

#currently a bracket error with the newitem when things are valid except for the captcha verification.
class NewItem(Handler):
def get(self):
logging.info("******** New Item GET ******")
Expand All @@ -86,21 +87,21 @@ def post(self):
picture = self.request.get("file")
img_type = imghdr.what(None, picture)
img_type = str(img_type)
logging.info(img_type)
supportedtypes = ['png', 'jpeg', 'gif', 'tiff', 'bmp']
con = httplib.HTTPSConnection("www.google.com")
con.request("POST", "/recaptcha/api/siteverify", urllib.urlencode({"secret": "6LdVQTQUAAAAAEla2hBTZfXSiBOiaGUjYPVcbzIg", "response": self.request.get("g-recaptcha-response"), "remoteip": self.request.remote_addr}), {"Content-Type": "application/x-www-form-urlencoded"})
response = con.getresponse()
data = response.read()
success = json.loads(data)['success']
if success:
if title=="":
logging.info("error, submitted blank title")
titleError="*Please Add a Title*"
self.render("newitem.html", titleError=titleError, descData=desc, locData=location, upload_url=upload_url)
logging.info("captcha was completed successfully")
if not title:
logging.info("no title")
elif (img_type not in supportedtypes) and (img_type != "None"):
logging.info("error, invalid file type: "+img_type)
logging.info("valid file upload (or no file)")
fileError="*Not Supported Filetype*<br><br>Supported Types: " + ", ".join(supportedtypes)
self.render("newitem.html", fileError=fileError, descData=desc, locData=location, upload_url=upload_url, titleData=title)
self.render("newitem.html", fileError=fileError, descData=desc, locData=location, titleData=title)
else:
logging.info("no errors, posting item")
if img_type!="None":
Expand All @@ -111,7 +112,9 @@ def post(self):
time.sleep(0.1)
self.redirect('/')
else:
self.render("newitem.html", descData=data, locData=location, upload_url=upload_url, )
logging.info("CAPTCHA false")
self.render("newitem.html", descData=data, locData=location, titleData=title)


class PermItem(Handler):
def get(self, item_id):
Expand Down
Binary file modified lasanfound.pyc
Binary file not shown.

0 comments on commit b6bb1bb

Please sign in to comment.