Example #1
0
def delete_goals(goals_id):

    query = 'DELETE FROM likes WHERE goals_id = %(goals_id)s'
    data = {'goals_id': goals_id}
    mysql = connectToMySQL('culp')
    mysql.query_db(query, data)

    query = "DELETE FROM goals WHERE id = %(goals_id)s"
    mysql = connectToMySQL('culp')
    mysql.query_db(query, data)
    return redirect("/profile")
Example #2
0
def tasks():
    if 'user_id' not in session:
        return redirect('/')

    mysql = connectToMySQL('culp')
    query = 'SELECT * FROM users WHERE users.id = %(id)s'
    data = {'id': session['user_id']}
    user = mysql.query_db(query, data)

    mysql = connectToMySQL('culp')
    query = 'SELECT tasks.content, tasks.id, tasks.user_id, users.first_name FROM tasks JOIN users on tasks.user_id = users.id'
    tasks = mysql.query_db(query)

    return render_template('todo.html', users=user[0], tasks=tasks)
Example #3
0
def profile():
    if 'user_id' not in session:
        return redirect('/')

    mysql = connectToMySQL('culp')
    query = 'SELECT * FROM users WHERE users.id = %(id)s'
    data = {'id': session['user_id']}
    user = mysql.query_db(query, data)

    mysql = connectToMySQL('culp')
    query = 'SELECT goals.goals, goals.id, goals.user_id, users.first_name FROM goals JOIN users on goals.user_id = users.id'
    goals = mysql.query_db(query)

    return render_template('profile.html', users=user[0], goals=goals)
Example #4
0
def habits():
    if 'user_id' not in session:
        return redirect('/')

    mysql = connectToMySQL('culp')
    query = 'SELECT * FROM users WHERE users.id = %(id)s'
    data = {'id': session['user_id']}
    user = mysql.query_db(query, data)

    mysql = connectToMySQL('culp')
    query = 'SELECT habits.habit, habits.id, habits.user_id, users.first_name FROM habits JOIN users on habits.user_id = users.id'
    habits = mysql.query_db(query)

    return render_template('habits.html', users=user[0], habits=habits)
Example #5
0
def motivation():
    if 'user_id' not in session:
        return redirect('/')

    mysql = connectToMySQL('culp')
    query = 'SELECT * FROM users WHERE users.id = %(id)s'
    data = {'id': session['user_id']}
    user = mysql.query_db(query, data)

    mysql = connectToMySQL('culp')
    query = 'SELECT motivation.motivation, motivation.id, motivation.user_id, users.first_name FROM motivation JOIN users on motivation.user_id = users.id'
    motivation = mysql.query_db(query)

    return render_template('motivation.html',
                           users=user[0],
                           motivation=motivation)
Example #6
0
def delete_tasks(tasks_id):

    query = "DELETE FROM tasks WHERE id = %(tasks_id)s"
    data = {'tasks_id': tasks_id}
    mysql = connectToMySQL('culp')
    mysql.query_db(query, data)
    return redirect("/tasks")
Example #7
0
def display():
    mysql = connectToMySQL('friendsdb')

    all_friends = mysql.query_db("Select * from friends")
    print(all_friends)

    return render_template('CRfriends.html', all_friends=all_friends)
Example #8
0
def add():
    mysql = connectToMySQL('emailverification')
    data = {'hello': session['email']}

    query = "insert into data (email) values (%(hello)s);"
    results = mysql.query_db(query, data)
    return redirect('/success')
Example #9
0
def delete_motivation(motivation_id):

    query = "DELETE FROM motivation WHERE id = %(motivation_id)s"
    data = {'motivation_id': motivation_id}
    mysql = connectToMySQL('culp')
    mysql.query_db(query, data)
    return redirect("/motivation")
Example #10
0
def checking():
    mysql = connectToMySQL('emailverification')

    if not EMAIL_REGEX.match(request.form['email']):
        flash('INVALID EMAIL')
        return redirect('/')

    elif EMAIL_REGEX.match(request.form['email']):
        mysql = connectToMySQL('emailverification')
        echeck = mysql.query_db('select * from data;')
        for i in echeck:
            if i['email'] != request.form['email']:
                session['email'] = request.form['email']
                return redirect('/put')
            else:
                mysql = connectToMySQL('emailverification')
                flash('sorry that email has been taken')
                return redirect('/')
Example #11
0
def displayingInDB():
    mysql = connectToMySQL('friendsdb')
    query = "insert into friends (first_name, last_name, occupation, created_at, updated_at) values (%(first_name)s, %(last_name)s, %(occupation)s, NOW(), NOW());"
    data = {
        'first_name': request.form['first_name'],
        'last_name': request.form['last_name'],
        'occupation': request.form['occupation']
    }
    results = mysql.query_db(query, data)
    return redirect('/')
Example #12
0
def register():
    is_valid = True
    if len(request.form['fname']) < 2:
        is_valid = False
        flash("First name must be at least 2 characters long.")
    if len(request.form['lname']) < 2:
        is_valid = False
        flash("Last name must be at least 2 characters long.")
    if not EMAIL_REGEX.match(request.form['email']):
        flash('The email address you provided is invalid.')
    if len(request.form['pword']) < 8:
        is_valid = False
        flash("Password must be at least 8 characters long.")
    if request.form['pword'] != request.form['cpword']:
        is_valid = False
        flash("Passwords do not match.")

    mysql = connectToMySQL('culp')
    validate_email_query = 'SELECT id FROM users WHERE email = %(email)s;'
    form_data = {'email': request.form['email']}
    existing_users = mysql.query_db(validate_email_query, form_data)

    if existing_users:
        flash("Email address is already in use.")
        is_valid = False

    if not is_valid:
        return redirect('/')

    pw_hash = bcrypt.generate_password_hash(request.form['pword'])
    mysql = connectToMySQL('culp')
    query = 'INSERT INTO users (first_name, last_name, email, password, created_at, updated_at) VALUES (%(fn)s, %(ln)s, %(em)s, %(pw)s, now(), now())'
    data = {
        'fn': request.form['fname'],
        'ln': request.form['lname'],
        'em': request.form['email'],
        'pw': pw_hash
    }

    user_id = mysql.query_db(query, data)
    session['user_id'] = user_id

    return redirect('/profile')
Example #13
0
def login():
    mysql = connectToMySQL('culp')
    valid_email = 'SELECT * FROM users WHERE users.email = %(email)s;'
    valid = {'email': request.form['email']}
    result = mysql.query_db(valid_email, valid)
    if result:
        hashed_password = result[0]['password']
        if bcrypt.check_password_hash(hashed_password, request.form['pword']):
            session['user_id'] = result[0]['id']
            return redirect('/profile')
    flash('You could not be logged in. Please try again.')
    return redirect('/')
Example #14
0
def new_goals():
    is_valid = True

    if 'user_id' not in session:
        return redirect('/')

    if len(request.form['new_goal']) < 5:
        is_valid = False
        flash("A new goal must be at least 5 characters long.")

    if is_valid:
        mysql = connectToMySQL('culp')
        query = 'INSERT INTO goals (goals, user_id, created_at, updated_at) VALUES (%(goal)s, %(id)s, now(), now())'
        data = {'goal': request.form['new_goal'], 'id': session['user_id']}
        goals = mysql.query_db(query, data)
    return redirect('/profile')
Example #15
0
def new_habits():
    is_valid = True

    if 'user_id' not in session:
        return redirect('/')

    if len(request.form['new_habit']) < 5:
        is_valid = False
        flash("A new habit must be at least 5 characters long.")

    if is_valid:
        mysql = connectToMySQL('culp')
        query = 'INSERT INTO habits (habit, user_id, created_at, updated_at) VALUES (%(habit)s, %(id)s, now(), now())'
        data = {'habit': request.form['new_habit'], 'id': session['user_id']}
        habits = mysql.query_db(query, data)
    return redirect('/habits')
Example #16
0
def new_tasks():
    is_valid = True

    if 'user_id' not in session:
        return redirect('/')

    if len(request.form['task_list']) < 5:
        is_valid = False
        flash("A new task must be at least 5 characters long.")

    if is_valid:
        mysql = connectToMySQL('culp')
        query = 'INSERT INTO tasks (content, user_id, created_at, updated_at) VALUES (%(tasks)s, %(id)s, now(), now())'
        data = {'tasks': request.form['task_list'], 'id': session['user_id']}
        motivation = mysql.query_db(query, data)
    return redirect('/tasks')
Example #17
0
def new_motivation():
    is_valid = True

    if 'user_id' not in session:
        return redirect('/')

    if len(request.form['new_motivation']) < 5:
        is_valid = False
        flash("A new motivational quote must be at least 5 characters long.")

    if is_valid:
        mysql = connectToMySQL('culp')
        query = 'INSERT INTO motivation (motivation, user_id, created_at, updated_at) VALUES (%(motivation)s, %(id)s, now(), now())'
        data = {
            'motivation': request.form['new_motivation'],
            'id': session['user_id']
        }
        motivation = mysql.query_db(query, data)
    return redirect('/motivation')
Example #18
0
def yay():
    mysql = connectToMySQL('emailverification')
    email_data = mysql.query_db("select * from data")
    return render_template('successfulEmail.html', email_data=email_data)
Example #19
0
def enter():
    mysql = connectToMySQL('emailverification')
    email_data = mysql.query_db("select * from data")
    return render_template("validateEmail.html")
Example #20
0
def display():
    mysql = connectToMySQL('leadnclient')
    all_data = mysql.query_db("Select * from data")

    return render_template('leadsNclients.html', all_data=all_data)
Example #21
0
def yo():
    mysql = connectToMySQL('leadnclient')
    query = 'insert into data(Customer_Name) values (%(Customer_Name)s);'
    data = {'Customer_Name': request.form['customer_name']}
    results = mysql.query_db(query, data)
    return redirect('/')
Example #22
0
def delete_habits(habits_id):

    query = "DELETE FROM habits WHERE id = %(habits_id)s"
    mysql = connectToMySQL('culp')
    mysql.query_db(query, data)
    return redirect("/habits")