Ejemplo n.º 1
0
def create():
    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']
    }
    new_friend_id = mysql.query_db(query, data)

    return redirect('/')
Ejemplo n.º 2
0
def index():
    mysql = connectToMySQL("emailvalidationdb")
    all_emails = mysql.query_db("SELECT * FROM emails")

    return render_template("index.html", emails=all_emails)
Ejemplo n.º 3
0
def delete_review(id):
    mysql = connectToMySQL("majorrater")
    data = {"id": id}
    query = "DELETE FROM reviews where id = %(id)s"
    mysql.query_db(query, data)
    return redirect("/")
Ejemplo n.º 4
0
def unlike_quote(p_id):
    mysql = connectToMySQL(SCHEMA)
    query = "DELETE FROM users_likes_quotes WHERE users_id = %(uid)s AND quotes_id = %(pid)s"
    data = {'uid': session['user_id'], 'pid': p_id}
    mysql.query_db(query, data)
    return redirect("/dash")
Ejemplo n.º 5
0
def login_register():
    mysql = connectToMySQL('private_wall')
    users = mysql.query_db('SELECT * FROM users;')
    print(users)
    return render_template('log_reg_page.html')
Ejemplo n.º 6
0
def all():
    db = connectToMySQL(SCHEMA)
    query = "SELECT * FROM locations;"
    location_list = db.query_db(query)
    return location_list
Ejemplo n.º 7
0
def users():
    mysql = connectToMySQL('semi-restful_users')	        
    friends = mysql.query_db('SELECT * FROM friends;')  
   
    
    return render_template("index.html", all_friends = friends)
Ejemplo n.º 8
0
def all_users():
    db = connectToMySQL('users')
    user_list = db.query_db('SELECT * FROM users;')
    return render_template("index.html", user_list = user_list)
Ejemplo n.º 9
0
def delete_user(num):
    mysql = connectToMySQL('user')
    delete_this_user = mysql.query_db("DELETE FROM users WHERE (`user_id` =" +
                                      num + ");")
    return redirect('/')
Ejemplo n.º 10
0
def edit_user(num):
    mysql = connectToMySQL('user')
    this_user = mysql.query_db("SELECT * FROM users WHERE user_id =" + num +
                               ";")
    print(this_user)
    return render_template('update.html', user_info=this_user[0])
Ejemplo n.º 11
0
def show_user(num):
    mysql = connectToMySQL('user')
    one_user = mysql.query_db("SELECT * FROM users WHERE user_id =" + num +
                              ";")
    print(one_user)
    return render_template('one_user.html', user_info=one_user[0])
Ejemplo n.º 12
0
def index():
    mysql = connectToMySQL('user')
    users = mysql.query_db('SELECT * FROM users;')
    print(users)
    return render_template('index.html', all_users=users)
Ejemplo n.º 13
0
def create():

    mysql = connectToMySQL('somethingnew')
    email_verify = mysql.query_db("SELECT email FROM user;")
    passStrength = 0
    query = "INSERT INTO user (first_name,last_name,email,password_hash) VALUES (%(first_name)s, %(last_name)s, %(email)s, %(password)s);"
    hidden = {
        'password': request.form['password'],
        'password_confirm': request.form['password_confirm']
    }
    if hidden['password']:
        pw_hash = bcrypt.generate_password_hash(hidden['password'])
    else:
        flash('Password must be at least 8 characters long!', 'password')
        return redirect('/')
    data = {
        'password': pw_hash,
        'email': request.form['email'],
        'first_name': request.form['first_name'],
        'last_name': request.form['last_name']
    }
    password = request.form['password']

    for email in email_verify:
        if email['email'] == data['email']:
            flash("Email already exists!", 'email')
    if len(data['email']) < 1:
        flash("Email cannot be blank!", 'email')
    elif not EMAIL_REGEX.match(data['email']):
        flash("Invalid Email Address!", 'email')

    if len(data['first_name']) < 1:
        flash("Name cannot be blank!", 'first_name')
    elif len(data['first_name']) <= 2:
        flash("Name must be 2+ characters", 'first_name')

    if len(data['last_name']) < 1:
        flash("Name cannot be blank!", 'last_name')
    elif len(data['last_name']) <= 2:
        flash("Name must be 2+ characters", 'last_name')
    if hidden['password'] != hidden['password_confirm']:
        flash('Passwords do not match!', 'password')
    passFlash = []

    if (len(password) >= 8):  #tests if password is at least of length 8
        passStrength += 1
    else:
        passFlash.append(
            ['Password should be at least 8 characters long!', 'password'])
    if (re.compile(r'.*[A-Z].*[A-Z]').match(password)
        ):  #tests for at least 2 capital letters
        passStrength += 1
    else:
        passFlash.append(
            ["Password should contain one capital letter", 'password'])

    if (re.compile(r'.*[!@#$&*]').match(password)
        ):  #tests for at least one special character
        passStrength += 1
    else:
        passFlash.append(
            ["Password should contain one special character", 'password'])

    if (re.compile(r'.*[0-9].*[0-9]').match(
            hidden['password'])):  #tests for at least 2 digits
        passStrength += 1
    else:
        passFlash.append(
            ["Password should contain at least two digits", 'password'])

    if (re.compile(r'.*[a-z].*[a-z].*[a-z]').match(
            hidden['password'])):  #tests for at least 3 lower case letters
        passStrength += 1
    else:
        passFlash.append([
            "Password should contatin at least 3 lower case letters",
            'password'
        ])

    if passStrength < 3:
        for flashed in passFlash:
            flash(flashed[0], flashed[1])

    if '_flashes' in session.keys():
        return redirect("/")
    else:
        mysql = connectToMySQL('somethingnew')
        new_user_id = mysql.query_db(query, data)
        session['user_id'] = new_user_id
        session['first_name'] = data['first_name']
        flash("You have successfully registered!", 'home')
        return redirect('/home')
Ejemplo n.º 14
0
def like_tweet(tweet_id):
    mysql = connectToMySQL(database)
    query = "INSERT INTO liked_tweets (user_id, tweet_id) VALUES (%(user_id)s, %(tweet_id)s)"
    data = {'user_id': session['user_id'], 'tweet_id': tweet_id}
    mysql.query_db(query, data)
    return redirect("/success")
Ejemplo n.º 15
0
def index():
    mysql = connectToMySQL("friendsdb")
    all_friends = mysql.query_db("SELECT * FROM friends")
    print("Fetched all friends", all_friends)
    return render_template('index.html', friends=all_friends)
def index():
    mysql = connectToMySQL(db_name)
    query = "SELECT * from friends;"
    query_result = mysql.query_db(query)
    return render_template('index.html', friends=query_result)
Ejemplo n.º 17
0
def validate_reg():
    is_valid = True

    if len(request.form['fname']) < 2:
        is_valid = False
        flash("Please enter a valid name.")
    if len(request.form['fname']) > 20:
        is_valid = False
        flash("First name is too long. Name must be less than 20 characters.")
    elif not (request.form['fname']).isalpha():
        is_valid = False
        flash("Please enter letters (a-z) only.")
    if len(request.form['lname']) < 2:
        is_valid = False
        flash("Please enter a valid last name")
    if len(request.form['lname']) > 20:
        is_valid = False
        flash("Last name is too long. Name must be less than 20 characters.")
    elif not (request.form['lname']).isalpha():
        is_valid = False
        flash("Please enter letters (a-z) only.")
    if len(request.form['email']) < 2:
        is_valid = False
        flash("Please enter a valid email address.")
    if len(request.form['email']) > 20:
        is_valid = False
        flash("Email address is too long.")
    elif not EMAIL_REGEX.match(request.form['email']):
        is_valid = False
        flash('Invalid email address.')
    if len(request.form['password']) == '':
        is_valid = False
        flash("Password cannot be blank")
    elif len(request.form['password']) < 8:
        is_valid = False
        flash("Password must be at least 8 characters.")
    if len(request.form['password']) > 20:
        is_valid = False
        flash("Password must not exceed 20 characters.")
    if len(request.form['confirm_password']) == '':
        is_valid = False
        flash('Please confirm password')
    elif request.form['confirm_password'] != request.form['password']:
        is_valid = False
        flash('Passwords do not match.')

    mysql = connectToMySQL("login")
    query = "SELECT * FROM users WHERE email = %(em)s;"
    data = {"em": request.form["email"]}
    result = mysql.query_db(query, data)
    if len(result) > 0:
        is_valid = False
        flash("Email already taken. If already registered, try logging in.")
    if not is_valid:
        return redirect("/")
    else:
        pw_hash = bcrypt.generate_password_hash(request.form['password'])
        print(pw_hash)
        mysql = connectToMySQL("login")
        query = "INSERT INTO users (first_name, last_name, email, password, created_at, updated_at) VALUES (%(fn)s, %(ln)s, %(em)s, %(password_hash)s, NOW(), NOW());"
        data = {
            "fn": request.form['fname'],
            "ln": request.form['lname'],
            "em": request.form['email'],
            "password_hash": pw_hash,
        }
        db = connectToMySQL('login')
        id = mysql.query_db(query, data)
        print(id)
        return redirect('/success')
Ejemplo n.º 18
0
def destroy(id):
    db = connectToMySQL('users')
    query = 'DELETE FROM users WHERE id = %(id)s;'
    data ={'id': int(id)}
    db.query_db(query,data)
    return redirect('/users')
def home():
    mysql = connectToMySQL('semirestful')
    query = 'SELECT * FROM users'
    result = mysql.query_db(query)
    return render_template('home.html', userallinfo=result)
Ejemplo n.º 20
0
def users():
    mysql = connectToMySQL("flask_users")
    users = mysql.query_db("SELECT * FROM users WHERE deleted IS NULL;")
    print(users)
    return render_template("users.html", user_data = { 'user_list': users })
def deleteuser(userid):
    mysql = connectToMySQL('semirestful')
    query = 'DELETE FROM users WHERE id=%(id)s;'
    data = {'id': userid}
    result = mysql.query_db(query, data)
    return redirect('/users')
Ejemplo n.º 22
0
def recieve():
    query = "SELECT * FROM posts JOIN users ON posts.sender_id = users.id ORDER BY posts.created_at DESC"
    posts = connectToMySQL('private_wall').query_db(query)
    print(posts)
    return render_template("main_wall.html", posts = posts)
Ejemplo n.º 23
0
def success():
    mysql = connectToMySQL('email_data')
    the_emails = mysql.query_db('SELECT * FROM emails;')
    return render_template('success.html', emaildata = the_emails)
Ejemplo n.º 24
0
def like_quote(p_id):
    mysql = connectToMySQL(SCHEMA)
    query = "INSERT INTO users_likes_quotes (users_id, quotes_id, created_at, updated_at) VALUES (%(uid)s, %(pid)s, NOW(), NOW());"
    data = {'uid': session['user_id'], 'pid': p_id}
    mysql.query_db(query, data)
    return redirect("/dash")
Ejemplo n.º 25
0
from flask import Flask, render_template, request, redirect, flash, session
from mysqlconnection import connectToMySQL

import re
EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$')
name_regex = re.compile(r'^[a-zA-Z]+$')

mysql = connectToMySQL('users_flask')

app = Flask(__name__)
app.secret_key = "Secretusers"

@app.route('/')
@app.route('/users')
def index():
    query = f"SELECT * FROM users;"
    users = mysql.query_db(query)
    return render_template("userindex.html", users = users)

@app.route('/users/new')
def new():
    return render_template("newuser.html")

@app.route('/users/create', methods = ['POST'])
def create():
    first_name = request.form['first_name']
    last_name = request.form['last_name']
    email = request.form['email']

    if len(first_name) < 2:
        flash(u"The first name should be two or more characters long.", 'first_name')
Ejemplo n.º 26
0
def users_new():
    valid = True

    if len(request.form['first_name']) < 2:
        flash("First name must be longer")
        valid = False

    if len(request.form['last_name']) < 2:
        flash("Last name must be longer")
        valid = False

    if len(request.form['username']) < 3:
        flash("Username must be longer")
        valid = False

    if not EMAIL_REGEX.match(request.form['email']):
        flash("Email must be valid")
        valid = False

    if len(request.form['password']) < 8:
        flash("Password must be at least 8 characters")
        valid = False

    if INVALID_PASSWORD_REGEX.match(request.form['password']):
        flash(
            "Password must have at least one uppercase character and at least one number"
        )
        valid = False

    if request.form['password'] != request.form['confirm']:
        flash("Passwords must match")
        valid = False

    mysql = connectToMySQL(SCHEMA)
    query = 'SELECT id FROM users WHERE username=%(username)s;'
    data = {'username': request.form['username']}
    existing_username = mysql.query_db(query, data)

    if existing_username:
        flash("Username already in use")
        valid = False

    mysql = connectToMySQL(SCHEMA)
    query = 'SELECT id FROM users WHERE email=%(email)s;'
    data = {'email': request.form['email']}
    existing_email = mysql.query_db(query, data)

    if existing_email:
        flash("Email already in use")
        valid = False

    if not valid:
        return redirect('/')

    pw_hash = bcrypt.generate_password_hash(request.form['password'])
    mysql = connectToMySQL(SCHEMA)
    query = "INSERT INTO users (first_name, last_name, email, username, pw_hash, created_at, updated_at) VALUES (%(first)s, %(last)s, %(mail)s, %(un)s, %(pw)s, NOW(), NOW());"
    data = {
        'first': request.form['first_name'],
        'last': request.form['last_name'],
        'mail': request.form['email'],
        'un': request.form['username'],
        'pw': pw_hash
    }
    user_id = mysql.query_db(query, data)
    session['user_id'] = user_id

    return redirect('/dash')
Ejemplo n.º 27
0
def register():
    mysql = connectToMySQL("email_registration")
    users = mysql.query_db("SELECT * FROM users;")
    print(users)
    EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$')
    PW_REGEX = re.compile(
        r'^.*(?=.{8,10})(?=.*[a-zA-Z])(?=.*?[A-Z])(?=.*\d)[a-zA-Z0-9!@£$%^&*()_+={}?:~\[\]]+$'
    )
    firstName = request.form['first_name']
    lastName = request.form['last_name']
    email = request.form['email']
    password = request.form['password']
    conPassword = request.form['passwordConfirm']
    isValid = True

    if len(firstName) <= 0:
        isValid = False
        flash('Please enter a first name', 'name')

    if not firstName.isalpha():
        isValid = False
        flash('Please enter a first name using only alphabetic characters',
              'name')

    if len(lastName) <= 0:
        isValid = False
        flash('Please enter a last name', 'name')

    if not lastName.isalpha():
        isValid = False
        flash('Please enter a last name using only alphabetic characters',
              'name')

    if len(email) <= 3:
        isValid = False
        flash('Please enter an email address', 'email')

    if not EMAIL_REGEX.match(request.form['email']):
        isValid = False
        flash("Invalid email address!", 'email')

    if not PW_REGEX.match(request.form['password']):
        isValid = False
        flash(
            "Invalid password! Minimum 8 characters, 1 number, and 1 special character",
            'password')

    if len(password) <= 4:
        isValid = False
        flash('Please enter a valid password (minimum 5 characters)',
              'password')

    if not password == conPassword:
        isValid = False
        flash('Password doesnt match confirm password', 'password')

    if isValid == True:
        mysql = connectToMySQL("email_registration")
        query = "INSERT INTO users (first_name, last_name, email, password) VALUES (%(fname)s, %(lname)s, %(email)s, %(pw)s);"
        data = {
            "fname": firstName,
            "lname": lastName,
            "email": email,
            "pw": password
        }
        new_user_id = mysql.query_db(query, data)

        mysql = connectToMySQL("email_registration")
        users = mysql.query_db("SELECT * FROM users;")
        print(users)
        flash('Success!')
        return redirect('/')
    else:
        return redirect('/')
Ejemplo n.º 28
0
from flask import Flask, flash, redirect, render_template, request, url_for, session
from mysqlconnection import connectToMySQL
import re
app = Flask(__name__, template_folder="templates")
EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$')
app.secret_key = 'randomstring'
mysql = connectToMySQL('emailvalidationdb')


@app.route('/', methods=['GET'])
def index():
    mysql = connectToMySQL("emailvalidationdb")
    all_emails = mysql.query_db("SELECT * FROM emails")

    return render_template("index.html", emails=all_emails)


@app.route('/email', methods=['POST'])
def create():
    email = request.form['email']
    mysql = connectToMySQL("emailvalidationdb")
    query = "SELECT * FROM emails WHERE email = some_email"
    data = {'some_email': request.form['email']}
    email = request.form['email']
    if len(email) < 1:
        flash("Email cannot be blank!", 'error')
        return redirect('/')
    if mysql.query_db(query, data):
        mysql = connectToMySQL("emailvalidationdb")
        flash("Email already in use!", 'error')
        return redirect('/')
Ejemplo n.º 29
0
def index():
    mysql = connectToMySQL("email_registration")
    users = mysql.query_db("SELECT * FROM users;")
    print(users)
    return render_template("index.html", all_users=users)
Ejemplo n.º 30
0
from flask import Flask, render_template, redirect, request
from mysqlconnection import connectToMySQL

mysql = connectToMySQL('friendsdb')

print("all the users", mysql.query_db("SELECT * FROM friends;"))
app=Flask(__name__)


@app.route('/')
def index():
    mysql = connectToMySQL("friendsdb")
    all_friends = mysql.query_db("SELECT * FROM friends")
    print("Fetched all friends", all_friends)
    return render_template('index.html', friends=all_friends)

@app.route('/create_friend', methods=['POST'])
def create():
    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']
    }
    new_friend_id = mysql.query_db(query, data)

    return redirect('/')

Ejemplo n.º 31
0
from flask import Flask, render_template, redirect, request
from mysqlconnection import connectToMySQL

mysql = connectToMySQL('friendsdb')

print("all the users", mysql.query_db("SELECT * FROM friends;"))
app = Flask(__name__)


@app.route('/')
def index():
    mysql = connectToMySQL("friendsdb")
    all_friends = mysql.query_db("SELECT * FROM friends")
    print("Fetched all friends", all_friends)
    return render_template('index.html', friends=all_friends)


@app.route('/create_friend', methods=['POST'])
def create():
    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']
    }
    new_friend_id = mysql.query_db(query, data)

    return redirect('/')
Ejemplo n.º 32
0
def index():
    mysql = connectToMySQL("friendsdb")
    all_friends = mysql.query_db("SELECT * FROM friends")
    print("Fetched all friends", all_friends)
    return render_template('index.html', friends=all_friends)
Ejemplo n.º 33
0
from flask import Flask, render_template, request, session, redirect, flash
from flask_bcrypt import Bcrypt
from mysqlconnection import connectToMySQL
import re
app = Flask(__name__)
bcrypt = Bcrypt(app)
app.secret_key = 'whatsecret?'
EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$')
mysql = connectToMySQL('sti')


@app.route("/")
def index():
    if 'Fname' not in session:
        session['Fname'] = ""
    if 'lname' not in session:
        session['Lname'] = ""
    if 'Mail' not in session:
        session['Mail'] = ""
    return render_template("index.html",
                           Fname=session['Fname'],
                           Lname=session['Lname'],
                           Email=session['Mail'])


@app.route('/create', methods=['POST'])
def create():

    if len(request.form['Fname']) < 2:
        flash("First Name cannot be blank!")
        return redirect("/")