from flask import Flask, render_template, request, redirect, flash from flask_bcrypt import Bcrypt # the "re" module will let us perform some regular expression operations import re # create a regular expression object that we can use run operations on EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') # import the function connectToMySQL from the file mysqlconnections.py from mysqlconnections import connectToMySQL app = Flask(__name__) app.secret_key = "ThisIsSecret!" bcrypt = Bcrypt(app) # invoke the connectToMySQL function and pass it the name of the database we're using # connectToMySQL returns an instance of MySQLConnection, which we will store in the variable 'mysql' mysql = connectToMySQL('emaildb') # now, we may invoke the query_db method # print("all emails", mysql.query_db("SELECT * FROM emails;")) @app.route('/', methods=['GET']) def index(): all_emails = mysql.query_db("SELECT * FROM emaildb") print("Fetched all emails", all_emails) return render_template('index.html', emails=all_emails) @app.route('/process', methods=['POST']) def create(): if len(request.form['emails']) < 1: flash("Email cannot be blank!")
from flask import Flask, render_template, request, redirect, session, flash from flask_bcrypt import Bcrypt # the "re" module will let us perform some regular expression operations import re # create a regular expression object that we can use run operations on EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') # import the function connectToMySQL from the file mysqlconnections.py from mysqlconnections import connectToMySQL app = Flask(__name__) app.secret_key = "ThisIsSecret!" bcrypt = Bcrypt(app) # invoke the connectToMySQL function and pass it the name of the database we're using # connectToMySQL returns an instance of MySQLConnection, which we will store in the variable 'mysql' mysql = connectToMySQL('thewall') # now, we may invoke the query_db method @app.route('/', methods=['GET']) def index(): return render_template('index.html') @app.route('/Registration', methods=['POST']) def confirm(): session.clear() session['counter']=0 pw = request.form['password'] pw_hash = bcrypt.generate_password_hash(pw) pw_hash = str(pw_hash).strip('b').replace("'","") if len(request.form['first_name']) <= 2 :
from flask import Flask, render_template, request, redirect, session, flash from flask_bcrypt import Bcrypt # the "re" module will let us perform some regular expression operations import re # create a regular expression object that we can use run operations on EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') # import the function connectToMySQL from the file mysqlconnections.py from mysqlconnections import connectToMySQL app = Flask(__name__) app.secret_key = "ThisIsSecret!" bcrypt = Bcrypt(app) # invoke the connectToMySQL function and pass it the name of the database we're using # connectToMySQL returns an instance of MySQLConnection, which we will store in the variable 'mysql' mysql = connectToMySQL('loginregistration') # now, we may invoke the query_db method @app.route('/', methods=['GET']) def index(): return render_template('index.html') @app.route('/Registration', methods=['POST']) def confirm(): session.clear() session['counter'] = 0 print() pw = request.form['password'] pw_hash = bcrypt.generate_password_hash(pw) pw_hash = str(pw_hash).strip('b').replace("'", "")
from flask import Flask, render_template, request, redirect, flash, session from mysqlconnections import connectToMySQL from flask_bcrypt import Bcrypt import re app = Flask(__name__) bcrypt = Bcrypt(app) app.secret_key = 'canyoukeepit?' mysql = connectToMySQL('login') EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') @app.route('/') def index(): return render_template("index.html") @app.route('/create_user', methods=['post']) def register(): session['email'] = request.form['email'] session['first_name'] = request.form['first_name'] session['last_name'] = request.form['last_name'] user = mysql.query_db("SELECT * FROM users") if len(request.form['first_name']) < 1: flash('first name is a required field!', 'login') elif len(request.form['first_name']) > 64: flash('first name must be under 64 characters!', 'login') else: if request.form['first_name'].isalpha() == True: session['first_name'] = request.form['first_name'] else:
from flask import Flask, render_template, request, redirect from flask_bcrypt import Bcrypt # import the function connectToMySQL from the file mysqlconnections.py from mysqlconnections import connectToMySQL app = Flask(__name__) bcrypt = Bcrypt(app) # invoke the connectToMySQL function and pass it the name of the database we're using # connectToMySQL returns an instance of MySQLConnection, which we will store in the variable 'mysql' mysql = connectToMySQL('friendsdb') # now, we may invoke the query_db method # print("all the users", mysql.query_db("SELECT * FROM friends;")) @app.route('/') def index(): 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(): 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'] } mysql.query_db(query, data) return redirect('/')
from flask import Flask # import the function connectToMySQL from the file mysqlconnections.py from mysqlconnections import connectToMySQL app = Flask(__name__) # invoke the connectToMySQL function and pass it the name of the database we're using # connectToMySQL returns an instance of MySQLConnection, which we will store in the variable 'mysql' mysql = connectToMySQL('mydb') # now, we may invoke the query_db method print("all the users", mysql.query_db("SELECT * FROM users;")) app.run(debug=True)