def createUser(name, icon, agency, subtext): #test user creation... # basically a User constructor using a given set of values # to save me some typing use = User() name = name.replace(' ', '_') use.setProfileInfo(name, icon, agency, subtext) return use
def createUser(name, icon, agency, subtext): use = User() use.setProfileInfo(name, icon, agency, subtext) return use
def setLoginCookie(): uid = request.forms.get("userid") pw = request.forms.get("password") rem = request.forms.get("remember_me") if client is not None: db = client.users hash_pass = SHA256.new(pw).digest() # hash user input password hash_pass_uni = hash_pass.decode("latin-1") # convert to unicode salt = db.test_user.find_one({"user": uid}, {"salt": 1, "_id": 0}) # pull user salt salt_uni = salt["salt"] # pull single salt unicode element password = db.test_user.find_one({"user": uid}, {"password": 1, "_id": 0}) # pull user password password_uni = password["password"] # pull single password unicode element if str(db.test_user.find_one({"user": uid})) == "None": return "User not Found" else: if password_uni == salt_uni + hash_pass_uni: # matches input password to db password _user = USERS.getUserByName(uid) # TODO: replace this with db lookup loginToken = ( uid + "loginToken" + "".join(random.choice(string.ascii_letters + string.digits) for _ in range(5)) ) def createUser(name, icon, agency, subtext): use = User() use.setProfileInfo(name, icon, agency, subtext) return use mongo_user = db.test_user.find_one({"user": uid}, {"user": 1, "_id": 0})[ "user" ] # pull out mongodb query and display only the value of the approriate key, i.e. pymongo returns a <type 'dict'> mongo_org = db.test_user.find_one({"user": uid}, {"org": 1, "_id": 0})["org"] mongo_quote = db.test_user.find_one({"user": uid}, {"quote": 1, "_id": 0})["quote"] userObj = createUser(mongo_user, "/img/profiles/martin2.png", mongo_org, mongo_quote) try: USERS.addUser(userObj, loginToken) except ValueError as e: print e.message response.set_cookie("cosmosium_login", loginToken, max_age=60 * 60 * 5) redirect("/play") else: return "Wrong Password" else: offlineUser = User() offlineUser.setProfileInfo("OfflineUser", "/img/profiles/martin2.png", "Offline", "Offline") loginToken = ( "OfflineUser" + "loginToken" + "".join(random.choice(string.ascii_letters + string.digits) for _ in range(5)) ) try: USERS.addUser(offlineUser, loginToken) except ValueError as e: print e.message response.set_cookie("cosmosium_login", loginToken, max_age=60 * 60 * 5) redirect("/play")
def createUser(name, icon, agency, subtext ): # basically a User constructor using a given set of values # to save me some typing use = User() use.setProfileInfo(name,icon,agency,subtext) return use
def createUser(name, icon, agency, subtext): # basically a User constructor using a given set of values # to save me some typing use = User() use.setProfileInfo(name, icon, agency, subtext) return use