Example #1
0
def load_user(user_id):
    result = User.get(user_id)
    if result:
        name, display_name, password_hash = User.user_database[user_id]
        return User(name, display_name, password_hash)
    else:
        return None
Example #2
0
def login():
    error = None
    form = LoginForm(request.form)
    if request.method == "POST":
        if form.validate_on_submit():
            username = request.form["username"]
            password = request.form["password"]
            if (not username in User.user_database) or gen_hash(password) != User.get_password_hash(username):
                error = "Invalid Credentials. Try again."
            else:
                login_user(load_user(username))
                flash("You were just logged in")
                return redirect(url_for("home"))
        else:
            return render_template("login.html", form=form, error=error)
    return render_template("login.html", form=form, error=error)
Example #3
0
    def getUser(connection, userID):
        """Get a User object given a user ID"""

        cursor = connection.cursor()

        columns = "usr, name, email, city, timezone"
        variables = (userID, )
        inputSizes = [int]

        statement = "select {0} from {1} where usr = :1".format(
            columns, UsersTableTools._USERS_TABLE)

        TableTools.execute(connection, cursor, statement, variables,
                           inputSizes)

        result = cursor.fetchone()

        return User(result[0], result[1], result[2], result[3], result[4])