def get_user(): from merveilles.database import _get_user_str user = None username = session.get("username") if username: oleg = g.oleg user_str = _get_user_str(username) user = oleg.get(user_str) return {"user": user}
def sign_up(connection, username, password, admin=False): salt = gensalt() pwhash = _hash_pw(username, password, salt) user = connection.get(_get_user_str(username)) if not user: new_user = { "api_version": SCHEMA_VERSION, "username": username, "password": pwhash, "starred": [], "icon_hash": None, "salt": salt, "admin": admin } connection.set(_get_user_str(username), new_user) return (True, new_user) else: return (False, "Username already taken.") return (False, "Could not create user for some reason.")
def auth_user(connection, username, pw): getstr = _get_user_str(username) userobj = connection.get(getstr) if userobj and userobj['username'] == username: salt = userobj['salt'] sent_hash = _hash_pw(username, pw, salt) if sent_hash == userobj['password']: return True return False
def set_user(user_obj): from merveilles.database import _get_user_str username = session.get("username") if username: oleg = g.oleg user_str = _get_user_str(username) oleg.set(user_str, user_obj) return True return False