コード例 #1
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLLogin
def checkEmailInDB(email):
    mysql = connectToMySQL("loginandregistration")
    query = "SELECT * FROM loginandregistrations where email = %(email)s;"
    data = {"email": email}
    query_check = "SELECT COUNT(*) as doesExist FROM loginandregistrations where email = %(email)s;"
    if mysql.query_db(query_check, data)[0]['doesExist'] == 0:
        result = False
    else:
        mysql = connectToMySQL("loginandregistration")
        result = mysql.query_db(query, data)
    return result
コード例 #2
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLLogin
def delete_msg():
    mysql = connectToMySQL('loginandregistration')
    query = "SELECT sent_to_user_id from messages where id = %(message_id)s;"
    data = {"message_id": request.form['message_id']}
    # print(mysql.query_db(query,data))
    # print("*!*!*!**!*!")
    if mysql.query_db(query, data)[0]['sent_to_user_id'] != str(
            session['user_id']):
        return redirect('/terribleperson')
    else:
        mysql = connectToMySQL('loginandregistration')
        queryDelete = "DELETE from messages where id = %(message_id)s;"
        data = {"message_id": request.form['message_id']}
    mysql.query_db(queryDelete, data)
    return redirect('/wall')
コード例 #3
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLPets
def add_pet():
    mysql = connectToMySQL('pets')
    query = "INSERT INTO pets (name, type, created_at, updated_at) VALUES (%(name)s, %(type)s, NOW(), NOW());"
    data = {"name": request.form["name"], "type": request.form["type"]}
    id = mysql.query_db(query, data)

    return redirect("/")
コード例 #4
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLLogin
def register():
    current_form = request.form
    isTrue = True
    if validateEmail(request.form["email"]) == False:
        isTrue = False
    if validateFirstName(request.form["first_name"]) == False:
        isTrue = False
    if validateLastName(request.form["last_name"]) == False:
        isTrue = False
    if validatePassword(request.form["password"]) == False:
        isTrue = False
    if validateConfirmPW(request.form["password"],
                         request.form["pwconfirm"]) == False:
        isTrue = False
    if isTrue == False:
        flash(request.form["first_name"], "holdFName")
        flash(request.form["last_name"], "holdLName")
        flash(request.form["email"], "holdEmail")
        return redirect('/')
    elif isTrue == True:
        mysql = connectToMySQL('loginandregistration')
        pw_hash = bcrypt.generate_password_hash(request.form['password'])
        query = "INSERT INTO loginandregistrations (FirstName, LastName, Email, Password, created_at, updated_at) VALUES (%(firstname)s, %(lastname)s, %(email)s, %(password)s, NOW(), NOW());"
        data = {
            "firstname": request.form["first_name"],
            "lastname": request.form["last_name"],
            "email": request.form["email"],
            "password": pw_hash
        }
        id = mysql.query_db(query, data)
        session["isLoggedIn"] = True
        session["user_id"] = id
        session["email_address"] = request.form["email"]
        return redirect("/wall")
コード例 #5
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLPets
def index():
    mysql = connectToMySQL(
        'pets')  # call the function, passing in the name of our db
    pets = mysql.query_db(
        'SELECT * FROM pets;'
    )  # call the query_db function, pass in the query as a string
    print(pets)
    return render_template("index.html", all_pets=pets)
コード例 #6
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLLogin
def email():
    found = False
    mysql = connectToMySQL('loginandregistration')  # connect to the database
    query = "SELECT email from loginandregistrations WHERE loginandregistrations.email = %(email)s;"
    data = {'email': request.form['email']}
    result = mysql.query_db(query, data)
    if result:
        found = True
    return render_template('partials/email.html',
                           found=found)  # render a partial and return it
コード例 #7
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLUsers
def add_user():
    mysql = connectToMySQL('users')
    query = "INSERT INTO users (FirstName, LastName, Email, description, created_at, updated_at) VALUES (%(firstname)s, %(lastname)s, %(email)s, %(description)s, NOW(), NOW());"
    data = {
        "firstname": request.form["firstname"],
        "lastname": request.form["lastname"],
        "email": request.form["email"],
        "description": request.form["description"]
    }
    id = mysql.query_db(query, data)
    return redirect("/users/" + str(id))
コード例 #8
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLUsers
def update_user():
    mysql = connectToMySQL('users')
    query = "UPDATE users set FirstName = %(firstname)s, LastName = %(lastname)s, Email = %(email)s, description = %(description)s, updated_at = NOW() where id = %(id)s;"
    data = {
        "firstname": request.form["firstname"],
        "lastname": request.form["lastname"],
        "email": request.form["email"],
        "description": request.form["description"],
        "id": request.form["id"]
    }
    mysql.query_db(query, data)
    return redirect("/users/" + str(request.form['id']))
コード例 #9
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLLogin
def validateEmail(emailaddress):
    EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$')
    if not EMAIL_REGEX.match(emailaddress):
        flash("Invalid Email Address!", "email")
        return False
    else:
        mysql = connectToMySQL("loginandregistration")
        query = "SELECT COUNT(*) as doesExist FROM loginandregistrations where email = %(email)s;"
        data = {"email": emailaddress}
        if (mysql.query_db(query, data)[0]['doesExist'] == 0):
            return True
        else:
            flash("Email already in system", "email")
            return False
コード例 #10
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLLogin
def success():
    if session["isLoggedIn"] == False:
        return redirect("/")
    else:
        user = checkEmailInDB(session['email_address'])
        mysql = connectToMySQL('loginandregistration')
        query = "SELECT concat(Sender.FirstName, ' ', Sender.LastName) as who_sent_me, messages.id as message_id, messages.sent_to_user_id AS sent_to_user_id, messages.sending_user_id AS sending_user_id, messages.message as message, messages.sent_at AS timestamp, timediff(now(), messages.sent_at) AS timepassed from messages join loginandregistrations as Sender on messages.sending_user_id = Sender.id join loginandregistrations as SentTo on messages.sent_to_user_id = SentTo.id where sent_to_user_id = %(user_id)s;"
        data = {"user_id": user[0]['id']}
        received_messages = mysql.query_db(query, data)
        if received_messages == False:
            received_messages = []
        all_users = allUsersReturn()
    return render_template("success.html",
                           all_users=all_users,
                           user=user,
                           received_messages=received_messages)
コード例 #11
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLLogin
def send_msg():
    if len(request.form['message_text']) < 5:
        flash('Your message must be at least 5 characters long',
              'message_send')
        return redirect('/wall')
    mysql = connectToMySQL('loginandregistration')
    query = 'INSERT INTO messages (sending_user_id, sent_to_user_id, message, sent_at) VALUES ( %(sender)s, %(receiver)s, %(message)s, NOW() )'
    data = {
        'sender': session['user_id'],
        'receiver': request.form['message_to'],
        'message': request.form['message_text']
    }
    print(session['user_id'])
    print(request.form['message_to'])
    print(request.form['message_text'])
    mysql.query_db(query, data)
    return redirect('/wall')
コード例 #12
0
ファイル: server.py プロジェクト: tehtertot/DojoPoll
from flask import Flask, render_template, request, redirect
from flask_socketio import SocketIO, join_room, leave_room
from mysql import connectToMySQL
import random, string

app = Flask(__name__)
mysql = connectToMySQL("dojopolls")

app.config["SECRET_KEY"] = "1234567890qwertyuiop"
socketio = SocketIO(app)


@app.route('/')
def index():
    return render_template("index.html")


@app.route('/start', methods=["POST", "GET"])
def start_room():
    if request.method == "GET":
        return render_template("create/start.html")
    else:
        # generate a random room code
        room_code = ''.join(
            random.choices(string.ascii_uppercase + string.digits, k=5))
        print(room_code)

        # save room in db
        room_created = mysql.query_db(
            f"INSERT INTO polls (title, admin, password, poll_id) VALUES ('{request.form['title']}','{request.form['name']}', '{request.form['password']}', '{room_code}')"
        )
コード例 #13
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLLogin
def allUsersReturn():
    mysql = connectToMySQL("loginandregistration")
    query = "SELECT *  FROM loginandregistrations ;"
    all_users = mysql.query_db(query)
    return all_users
コード例 #14
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLUsers
def index():
    mysql = connectToMySQL('users')
    users = mysql.query_db('SELECT * FROM users;')
    return render_template("index.html", all_users=users)
コード例 #15
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLUsers
def show_user(id):
    mysql = connectToMySQL('users')
    query = 'SELECT * FROM users where id = %(id)s;'
    data = {"id": id}
    user = mysql.query_db(query, data)
    return render_template("show_user.html", user=user, id=id)
コード例 #16
0
ファイル: server.py プロジェクト: maiya-tracy/FlaskSQLUsers
def delete_user(id):
    mysql = connectToMySQL('users')
    query = "DELETE from users where id = %(id)s;"
    data = {"id": id}
    mysql.query_db(query, data)
    return redirect("/users")