def page_logic(json, **argd): try: email = argd["email"] password = argd["password"] except KeyError: return [ "error", { "message": "Need both email & password as parameters", "record": {}, "problemfield": "", } ] R = Registrations.read_database() for r in R: if r["email"] == email: break else: return [ "error", { "message": "Sorry, could not log you in - please check your email & password", "record": {}, "problemfield": "", } ] if r["password"] != md5.md5(argd["password"]).hexdigest(): return [ "error", { "message": "Sorry, could not log you in - please check your email & password.", "record": {}, "problemfield": "", } ] if r["confirmed"]: cookie = CookieJar.getCookie(r["regid"]) return [ "loggedin", { "message": "Login successful", "user": r["screenname"], "sessioncookie": cookie, } ] else: return [ "error", { "message": "Sorry, you need to confirm your identity before you can login!", "record": {}, "problemfield": "", } ]
def page_logic(json, **argd): try: email = argd["email"] password = argd["password"] except KeyError: return [ "error", { "message" : "Need both email & password as parameters", "record" : {}, "problemfield" : "", } ] R = Registrations.read_database() for r in R: if r["email"] == email: break else: return [ "error", { "message": "Sorry, could not log you in - please check your email & password", "record" : {}, "problemfield" : "", } ] if r["password"] != md5.md5(argd["password"]).hexdigest(): return [ "error", { "message": "Sorry, could not log you in - please check your email & password.", "record" : {}, "problemfield" : "", } ] if r["confirmed"]: cookie = CookieJar.getCookie(r["regid"]) return [ "loggedin", { "message": "Login successful", "user" : r["screenname"], "sessioncookie" : cookie, } ] else: return [ "error", { "message": "Sorry, you need to confirm your identity before you can login!", "record" : {}, "problemfield" : "", } ]
def loggedIn(env): if loggedout: return False cookies = env.get("cookies", None) if not cookies: return False sessioncookie_raw = cookies.get("sessioncookie", None) if not sessioncookie_raw: return False sessioncookie = sessioncookie_raw.value try: userid = CookieJar.getUser(sessioncookie) except CookieJar.NoSuchUser: return False user = Registrations.get_record(userid) if user["confirmed"]: return userid else: return False
raise e return [ "error", { "message" : Reason, "record" : R, "problemfield" : field, } ] # end of action=new ------------------------------------------------------------------------ if argd.get("action", "") == "dump": env = argd.get("__environ__") cookie = env["bbc.cookies"].get("sessioncookie",None) if cookie: try: userid = CookieJar.getUser(cookie) except CookieJar.NoSuchUser: return [ "error", { "message" : "Can't find your registration associated with your cookie"+repr(cookie), "record" : {}, "problemfield" : "regid", "setcookies" : {"sessioncookie" : ";path=/"}, } ] try: R = Registrations.get_record(userid) except IOError: # probably means the db has been deleted/zapped CookieJar.wipePairing(cookie, userid) return [ "error", { "message" : "Can't find your registration associated with your cookie - maybe it was deleted?",
def page_logic(json, **argd): env = argd.get("__environ__") userid = None record = None if argd.get("action", "") == "": return [ "__default__", { "message" : "Sorry, this is not meant to be called directly", "record" : {}, "problemfield" : "regid", } ] if argd.get("action", "") == "upload": cookie = env["bbc.cookies"].get("sessioncookie",None) if cookie: try: userid = CookieJar.getUser(cookie) except CookieJar.NoSuchUser: sys.stderr.write("line 41\n") return [ "error", { "message" : "Can't identify you, so not accepting your submission, sorry - try logging out and in again"+repr(cookie), "record" : {}, "problemfield" : "regid", "setcookies" : {"sessioncookie" : ";path=/"}, } ] else: sys.stderr.write("line 51\n") return [ "error", { "message" : "Can't identify you, so not accepting your submission, sorry - try logging in or registering!", "record" : {}, "problemfield" : "regid", "setcookies" : {"sessioncookie" : ";path=/"}, } ] # We now have a valid userid. # OK, where's the uploaded data? video_file = argd.get("upload.filename.__filename", None) original_name = argd.get("upload.filename.__originalfilename", None) if (video_file == None) or (original_name == None): return [ "error", { "message" : "You need to upload a file for this method", "record" : argd, "problemfield" : "upload.filename", } ] # try: # import Video # Video.open(video_file) # except IOError: # return [ "error", # { "message" : "Sorry, but that doesn't seem to be an video", # "record" : {}, # "problemfield" : "upload.filename", # } # ] # Data we have right now: # # We have a valid userid # video_file contains a valid filename # upload.filename.__originalfilename # We know it's not moderated. # - Moderation is being handled by a file moving from a to b to c # - we really ought to have the video filename without the directory name trimmed = video_file[video_file.rfind("/")+1:] unique = trimmed[:trimmed.rfind(".")] record = { "uploaded_file": video_file, "unique_name": unique, "userid" : userid, "original_filename" : original_name, "trimmed_filename" : trimmed, } # try: # shutil.copytree("/srv/www/sites/bicker.kamaelia.org/template/videos", # "/srv/www/sites/bicker.kamaelia.org/docs/videos/user/%(unique_name)s" % record ) # except OSError: # pass record = new_video(**record) return [ "video_uploadok", { "message": "Upload Successful", "user" : "", } ]
def page_logic(json, **argd): env = argd.get("__environ__") userid = None record = None if argd.get("action", "") == "": return [ "__default__", { "message": "Sorry, this is not meant to be called directly", "record": {}, "problemfield": "regid", } ] if argd.get("action", "") == "upload": cookie = env["bbc.cookies"].get("sessioncookie", None) if cookie: try: userid = CookieJar.getUser(cookie) except CookieJar.NoSuchUser: sys.stderr.write("line 41\n") return [ "error", { "message": "Can't identify you, so not accepting your submission, sorry - try logging out and in again" + repr(cookie), "record": {}, "problemfield": "regid", "setcookies": { "sessioncookie": ";path=/" }, } ] else: sys.stderr.write("line 51\n") return [ "error", { "message": "Can't identify you, so not accepting your submission, sorry - try logging in or registering!", "record": {}, "problemfield": "regid", "setcookies": { "sessioncookie": ";path=/" }, } ] # We now have a valid userid. # OK, where's the uploaded data? image_file = argd.get("upload.filename.__filename", None) original_name = argd.get("upload.filename.__originalfilename", None) if (image_file == None) or (original_name == None): return [ "error", { "message": "You need to upload a file for this method", "record": argd, "problemfield": "upload.filename", } ] try: import Image Image.open(image_file) except IOError: return [ "error", { "message": "Sorry, but that doesn't seem to be an image", "record": {}, "problemfield": "upload.filename", } ] # Data we have right now: # # We have a valid userid # image_file contains a valid filename # upload.filename.__originalfilename # We know it's not moderated. # - Moderation is being handled by a file moving from a to b to c # - we really ought to have the image filename without the directory name trimmed = image_file[image_file.rfind("/") + 1:] unique = trimmed[:trimmed.rfind(".")] record = { "uploaded_file": image_file, "unique_name": unique, "userid": userid, "original_filename": original_name, "trimmed_filename": trimmed, } try: shutil.copytree( "/srv/www/sites/bicker.kamaelia.org/template/images", "/srv/www/sites/bicker.kamaelia.org/docs/images/user/%(unique_name)s" % record) except OSError: pass record = new_image(**record) return ["uploadok", { "message": "Upload Successful", "user": "", }]