Beispiel #1
0
def register():
    if len(request.form['r_fname']) < 2:
        flash("Please enter a valid first name")
    if len(request.form['r_lname']) < 3:
        flash("Please enter a valid last name")
    if not EMAIL_REGEX.match(request.form['r_email']):
        flash("Invalid email address")
    if len(request.form['r_password']) < 8:
        flash("Password too short")
    if request.form['r_password'] != request.form['r_confirm']:
        flash("Passwords do not match")
        return redirect('/')
    elif EMAIL_REGEX.match(request.form['r_email']):
        pw_hash = bcrypt.generate_password_hash(request.form['r_password'])
        mysql = connectToMySQL("exam")
        reg_query = "INSERT INTO exam.users (first_name, last_name, email, password) VALUES (%(rfn)s, %(rln)s, %(rem)s, %(rpw)s);"
        reg_data = {
            "rfn": request.form['r_fname'],
            "rln": request.form['r_lname'],
            "rem": request.form['r_email'],
            "rpw": pw_hash
        }
        session['reg_email'] = request.form['r_email']
        session['name'] = request.form['r_fname']
        reg_users = mysql.query_db(reg_query, reg_data)
        session['userid'] = reg_users
        return redirect('/success')
    return redirect('/')
Beispiel #2
0
def remove_trip(id):
    if 'userid' in session:
        mysql = connectToMySQL("exam")
        tripDelete_query = "DELETE FROM exam.trips WHERE id = %(tid)s and user_id = %(uid)s;"
        tripDelete_data = {
            "tid": id,
            "uid": session['userid']
        }
        tripDeleted = mysql.query_db(tripDelete_query, tripDelete_data)
        return redirect('/dashboard')
    flash("Please login to continue")
    return redirect('/')
Beispiel #3
0
def view_trip(id):
    if 'userid' in session:
        mysql = connectToMySQL("exam")
        trip_query = "SELECT * FROM exam.trips JOIN exam.users ON exam.users.id = exam.trips.user_id WHERE exam.trips.id = %(tid)s;"
        trip_data = {
            "tid": id
        }
        trips = mysql.query_db(trip_query, trip_data)
        session['trip_name'] = trips[0]['destination']
        return render_template('view_trip.html', trips = trips)
    flash("Please login to continue")
    return redirect("/")
Beispiel #4
0
def dash():
    if 'userid' in session:
        # GETTING TRIP LOCATION AND PLAN
        mysql = connectToMySQL("exam")
        userTrips_query = "SELECT * FROM exam.trips WHERE user_id = %(uid)s;"
        userTrips_data = {
            "uid": session['userid']
        }
        userTrips = mysql.query_db(userTrips_query, userTrips_data)

        return render_template("dashboard.html", alltrips = userTrips)
    flash("Please login to continue")
    return redirect('/')
Beispiel #5
0
def success():
    if 'userid' in session:
        mysql = connectToMySQL("exam")
        email_query = "SELECT * FROM exam.users WHERE email = %(em)s;"
        email_data = {
            "em": session['reg_email']
        }
        email = mysql.query_db(email_query, email_data)
        session['userid'] = email[0]['id']
        print(session['userid'])
        return render_template('dashboard.html')
    flash("Please register or login")
    return redirect('/')
Beispiel #6
0
def login():
    mysql = connectToMySQL("exam")
    log_query = "SELECT * FROM exam.users WHERE email = %(rem)s;"
    log_data = { 
        "rem": request.form['l_email'] 
        }
    log_users = mysql.query_db(log_query, log_data)
    if len(log_users) > 0:
        if bcrypt.check_password_hash(log_users[0]['password'], request.form['l_password']):
            session['userid'] = log_users[0]['id']
            session['name'] = log_users[0]['first_name']
            return redirect('/dashboard')

    flash("Please check email and/or password")
    return redirect('/')
Beispiel #7
0
def edit_trip():
    if 'userid' in session:
        if request.form['button'] == 'Submit':
            if len(request.form['destination']) < 4:
                flash("A trip destination must consist of at least 3 characters")
            if len(request.form['plan']) < 4:
                flash("A plan must be provided!")
                return redirect('/trips/edit/<id>')
            if request.form['button'] == 'Submit':
                mysql = connectToMySQL("exam")
                edit_query = "UPDATE exam.trips SET destination = %(des)s, plan = %(p)s, start_date = %(sd)s, end_date = %(ed)s WHERE id = %(tid)s;"
                edit_data = {
                    "des": request.form['destination'],
                    "p": request.form['plan'],
                    "sd": request.form['start'],
                    "ed": request.form['end'],
                    "tid": session['trip_id']
                }
                trip_edited = mysql.query_db(edit_query, edit_data)
            return redirect('/dashboard')
        return redirect('/dashboard')
    flash("Please login to continue")
    return redirect('/')
Beispiel #8
0
def create_trip():
    if request.form['button'] == 'Submit':
        if len(request.form['destination']) < 4:
            flash("A trip destination must consist of at least 3 characters")
        if len(request.form['start']) < 1:
            flash("Invalid start date")
        if len(request.form['end']) < 1:
            flash("Invalid end date")
        if len(request.form['plan']) < 4:
            flash("A plan must be provided!")
            return redirect('/trips/new')
        # ADD NEW TRIP
        mysql = connectToMySQL("exam")
        create_query = "INSERT INTO exam.trips (destination, plan, start_date, end_date, user_id) VALUES (%(des)s, %(p)s, %(sd)s, %(ed)s, %(uid)s);"
        create_data = {
            "des": request.form['destination'],
            "p": request.form['plan'],
            "sd": request.form['start'],
            "ed": request.form['end'],
            "uid": session['userid']
        }
        trip_created = mysql.query_db(create_query, create_data)
        return redirect('/dashboard')
    return redirect('/dashboard')