def submitArt(): if request.method == 'GET': if g.loggedInUser: return render_template("submit.html") else: abort(401) else: if not g.loggedInUser: abort(401) messages = [] # Image if request.form["artType"] == "image": image = request.files['upload'] if not util.allowedFile(image.filename, config.imageExtensions): flash(config.fileTypeError + "The allowed filetypes are " + util.printList(config.imageExtensions) + ". ") elif image.content_length >= config.maxImageSize: flash(config.fileSizeError + "Your image must be at most " + config.maxImageSizeText + ". ") elif not ("title" in request.form and "description" in request.form) : abort(500) elif not request.form["title"]: flash("Your title must not be left blank. ") else: fileType = util.fileType(request.files['upload'].filename) key = db.nextKey("art") db.db.art.insert({ "_id" : key , "title" : request.form["title"] , "description" : request.form["description"] , "codeDesc" : usercode.parse(request.form["description"]) , "author" : g.loggedInUser["username"] , "authorID" : g.loggedInUser["_id"] , "keywords" : filter (lambda keyword: not keyword in ignoredKeywords.commonWords, map(lambda keyword: keyword.lower() , request.form["title"].split() ) ) , "mature" : False , "folder" : "complete" , "favorites" : [] , "favAmount" : 0 , "views" : 0 , "date" : datetime.datetime.today() , "filetype" : fileType , "type" : "image" }) fileLocation = os.path.join(config.artDir, str(key) + "." + fileType) image.save(fileLocation) storage.push(fileLocation, fileLocation) autocrop(key) return redirect(url_for('crop',art=key)) # Audio # Literature # Craft # Cullinary # Performance return redirect(url_for('submitArt'))
def settings(): if request.method == 'GET': if g.loggedInUser: return render_template("settings.html") else: abort(401) elif request.method == 'POST': if g.loggedInUser: # User Icon icon = request.files['iconUpload'] if icon and util.allowedFile(icon.filename,config.iconExtensions): try: os.remove(os.path.join(app.config["iconsDir"], g.loggedInUser['lowername'] + "." + g.loggedInUser["icon"])) except: if config.logging: logging.warning("Error: Couldn't remove user \"" + g.loggedInUser['username']+ "\"'s old icon while attempting to upload a new icon. ") fileName = g.loggedInUser['lowername'] + "." + util.fileType(icon.filename) fileLocation = os.path.join(app.config["iconsDir"], fileName) db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": {"icon": util.fileType(fileName) }}) icon.save(fileLocation) image = Image.open(fileLocation) resized = image.resize(config.iconSize, Image.ANTIALIAS) try: resized.save(fileLocation, quality=100) except: if config.logging: logging.warning("Error: Couldn't save user \"" + g.loggedInUser['username'] + "\"'s new icon while attempting to upload a new icon. ") # Password if request.form["changePassCurrent"] and request.form["changePassNew1"] and request.form["changePassNew2"]: if system.cryptography.encryptPassword(request.form["changePassCurrent"], True) == g.loggedInUser['password']: if request.form["changePassNew1"] == request.form["changePassNew2"]: hashed = system.cryptography.encryptPassword(request.form['changePassNew1'], True) db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": {"password": hashed}}) session['password']=hashed # Gender if request.form["changeGender"] != g.loggedInUser["gender"]: db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": {"gender": request.form["changeGender"] }}) # Profile if request.form["changeProfile"] != g.loggedInUser["profile"]: db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": {"profile": request.form["changeProfile"], "codeProfile": usercode.parse(request.form["changeProfile"]) } }) # Color Theme if request.form["changeColorTheme"] != g.loggedInUser["theme"]: db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": {"theme": request.form["changeColorTheme"]} }) return "1" else: abort(401)
def settings(): if request.method == 'GET': if g.loggedInUser: if config.betaKey: betaKeys = db.db.betaPass.find({"owner" : g.loggedInUser["username"] }) else: betaKeys = None return render_template("settings.html", betaKeys = betaKeys) else: abort(401) elif request.method == 'POST': if g.loggedInUser: # User Messages messages = [] # User Icon icon = request.files['iconUpload'] if icon: if not icon.content_length <= config.maxIconSize: flash(config.fileSizeError + "Your icon must be at most " + config.maxIconSizeText + ". ") else: if not util.allowedFile(icon.filename,config.iconExtensions): flash(config.fileTypeError + "The allowed extensions are " + util.printList(config.iconExtensions) + ". ") else: try: os.remove(os.path.join(config.iconsDir, g.loggedInUser['lowername'] + "." + g.loggedInUser["icon"])) except: if config.logging: logging.warning("Couldn't remove user \"" + g.loggedInUser['username']+ "\"'s old icon while attempting to upload a new icon. ") fileName = g.loggedInUser['lowername'] fileType = util.fileType(icon.filename) if fileType.lower() == "jpg": fileType = "jpeg" # Change filetype for PIL (mimetype,i) = mimetypes.guess_type(icon.filename) fileLocation = os.path.join(config.iconsDir, fileName) db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": {"icon": fileType } } ) icon.save(fileLocation) image = Image.open(fileLocation) resized = image.resize(config.iconSize, Image.ANTIALIAS) resized.save(fileLocation, fileType, quality=100) storage.push(fileLocation, fileLocation, mimetype = mimetype ) messages.append("User Icon") # Password if request.form["changePassCurrent"] and request.form["changePassNew1"] and request.form["changePassNew2"]: if system.cryptography.encryptPassword(request.form["changePassCurrent"], True) != g.loggedInUser['password']: flash("The new password you gave didn't match the one in the database! ):") elif request.form["changePassNew1"] != request.form["changePassNew2"]: flash("The new passwords you gave don't match! Try retyping them carefully. ") else: hashed = system.cryptography.encryptPassword(request.form['changePassNew1'], True) db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": {"password": hashed}}) session['password']=hashed messages.append("Password") # Gender if request.form["changeGender"] != g.loggedInUser["gender"]: db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": {"gender": request.form["changeGender"] }}) messages.append("Gender") # Location if request.form["changeLatitude"] != str(g.loggedInUser["latitude"]) or request.form["changeLongitude"] != str(g.loggedInUser["longitude"]): try: latFloat = float(request.form["changeLatitude"]) lonFloat = float(request.form["changeLongitude"]) db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": {"latitude": latFloat, "longitude": lonFloat } } ) messages.append("Location") except ValueError: flash("The locations you gave were invalid latitude and longitude coordinates! ): ") # Profile if request.form["changeProfile"] != g.loggedInUser["profile"]: db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": {"profile": request.form["changeProfile"], "codeProfile": usercode.parse(request.form["changeProfile"]) } }) messages.append("Profile") # Color Theme if request.form["changeColorTheme"] != g.loggedInUser["theme"]: db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": {"theme": request.form["changeColorTheme"]} }) messages.append("Color Theme") # Layout l1 = util.urlDecode(request.form["changeLayout"]) l2 = util.urlDecode(request.form["changeLayoutOrder"]) for key in l2: l2[key] = int(l2[key]) # Converts orderings to integers layout = util.concDictValues(l1,l2) if not util.compareDicts(layout, g.loggedInUser["layout"]): if util.compareDictKeys(layout, g.loggedInUser["layout"]): layoutToPush = {} for key in layout: layoutToPush["layout." + key] = layout[key] db.db.users.update({"lowername": g.loggedInUser['lowername']}, {"$set": layoutToPush }) messages.append("Layout") return render_template("settingsSuccess.html",messages=messages,len=len) else: abort(401)