Esempio n. 1
0
def login():
    """Logs in the user."""
    if 'username' in session:
        return jsonify(ok=0, msg='You are already log in')
    user = request.form['user']
    passw = request.form['pass']
    if database.login_user(user, passw):
        session['username'] = user
        session['userid'] = database.get_userid(user)
        session['password'] = passw
        return jsonify(ok=1, msg='User is log in now')
    return jsonify(ok=0, msg='User could not be log in')
Esempio n. 2
0
def login():
    """Logs in the user."""
    if 'username' in session:
        return jsonify(ok=0, msg='You are already log in')
    user = request.form['user']
    passw = request.form['pass']
    if database.login_user(user, passw):
        session['username'] = user
        session['userid'] = database.get_userid(user)
        session['password'] = passw
        return jsonify(ok=1, msg='User is log in now')
    return jsonify(ok=0, msg='User could not be log in')
Esempio n. 3
0
def create_user():
    """Creates a new user."""
    if 'username' in session:
        return jsonify(ok=0, msg='First logout before creating a new user')
    user = request.form['user']
    passw = request.form['pass']
    if database.user_exists(user):
        return jsonify(ok=0, msg='User already exists')

    if database.create_user(user, passw):
        session['username'] = user
        session['userid'] = database.get_userid(user)
        session['password'] = passw
        return jsonify(ok=1, msg='User created!')
    return jsonify(ok=0, msg='User could not be created')
Esempio n. 4
0
def create_user():
    """Creates a new user."""
    if 'username' in session:
        return jsonify(ok=0, msg='First logout before creating a new user')
    user = request.form['user']
    passw = request.form['pass']
    if database.user_exists(user):
        return jsonify(ok=0, msg='User already exists')

    if database.create_user(user, passw):
        session['username'] = user
        session['userid'] = database.get_userid(user)
        session['password'] = passw
        return jsonify(ok=1, msg='User created!')
    return jsonify(ok=0, msg='User could not be created')
Esempio n. 5
0
def add_entry():
    """ Adds an entry to the CSV database, and refreshes the home page to update """
    username = util.remove_commas_from_string(request.form["name"])
    link = util.remove_commas_from_string(request.form["ytLink"])
    song = util.remove_commas_from_string(request.form["songName"])

    festive = CHRISTMAS_MODE and "christmasSong" in request.form

    with database.connect_to_database() as db:
        user_id = database.get_userid(db, username)
        database.add_song(db,
                          link,
                          song,
                          user_id,
                          month=12 if festive else None)

    return redirect(url_for('main'))
Esempio n. 6
0
def main(playlist=PLAYLIST_CSV):
    songs = read_playlist(playlist)
    with connect_to_database() as db:
        db_size_before = get_songs_size(db)
        for url, played, title, user in songs:
            played = ast.literal_eval(played)
            assert type(played) is bool
            user_id = get_userid(db, user)
            title = title.replace("'", '')
            added = add_song(db, url, title, user_id)
            logging.info("%s %s by %s", "Added " if added else "Did not add ",
                         title, user)
            if played:
                set_song_played(db, url)
                logging.info("Set song played: %s", title)
        db_size_after = get_songs_size(db)

    no_songs_added = db_size_after - db_size_before
    logging.info(
        "Populated database with playlist. Added %d songs. Database size: %d -> %d",
        no_songs_added, db_size_before, db_size_after)
Esempio n. 7
0
def input_commands(username: str):
    """
    Runs an infinite loop for the logged in user to enter commands.
    """

    print(f"\nWelcome, {username}\n")
    print("For help on how to use PyExpense, type 'help'. To exit, type 'exit'.")

    userid = database.get_userid(username)   
    while True:
        try:
            command = input("> ").strip()
            if command == 'exit':
                exit()
            elif command == 'logout':
                break
            command_manager.route(userid, command)
        except KeyboardInterrupt:
            print("\nTo exit PyExpense, type 'exit'.")
        except AssertionError as e:
            print(e.args[0])
        except Exception as e:
            print(e)