From 9661b641409d53dffd027e2bc0de51167f8bf840 Mon Sep 17 00:00:00 2001 From: Arianne Bayliss <baylissa1@cardiff.ac.uk> Date: Wed, 14 Dec 2022 18:56:10 +0000 Subject: [PATCH] modifying shiz --- project_db.sql | 7 +-- static/CSS/loginstyle.css | 4 -- static/JS/login.js | 30 ++++++++++-- static/login.html | 9 ++-- {static => templates}/landingpage.html | 6 +-- testloginserver.py | 63 ++++++++++++-------------- 6 files changed, 68 insertions(+), 51 deletions(-) rename {static => templates}/landingpage.html (95%) diff --git a/project_db.sql b/project_db.sql index ed85e53..ecd3a9c 100644 --- a/project_db.sql +++ b/project_db.sql @@ -13,9 +13,10 @@ CREATE TABLE IF NOT EXISTS "coworking_spaces" ( ); CREATE TABLE IF NOT EXISTS "login" ( - "Email" TEXT, PRIMARY KEY, - "Password" TEXT -) + "Email" TEXT PRIMARY KEY NOT NULL, + "Password" TEXT NOT NULL +); + INSERT INTO "coworking_spaces" VALUES ('Codebase','CodeBase Edinburgh , 37a Castle Terrace, Edinburgh, EH1 2EL','https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1646867535415-4JI39H286BUMT26H4FHN/C36A1915.jpg?format=2500w','https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1646868533510-J1OT4PEG5VM9FCBF8BJE/15.10.19_-_CREATIVE_BRIDGE_C02_-_DAY01_-_LQ-19+%281%29.jpg?format=2500w,https://images.squarespace-cdn.com/content/v1/55439320e4b0f92b5d6c4c8b/1646868421127-07KQ4N1OHTDDKQME686A/15.10.19_-_CREATIVE_BRIDGE_C02_-_DAY01_-_LQ-52+%281%29.jpg?format=2500w','Hi. We’re CodeBase. We''ve been exploring the world of startups and innovation for over five years now. We''re not really sure how to best describe what we do, but we think the words "tech cluster" probably do it best. Please get in touch! We’re friendly people who are geeky about building tech startups, managing disruption and innovation.','https://www.thisiscodebase.com','info@thisiscodebase.com','(+44) 0131 560 2003','08:00 - 17:00','Use the email address or phone number to call ahead and book a desk, let them know you''re a Tramshed member'); INSERT INTO "coworking_spaces" VALUES ('Catalyst','Titanic Quarter, Queens Road, Belfast, BT3 9DT','https://wearecatalyst.org/wp-content/uploads/2022/05/Catalyst03.jpg','https://wearecatalyst.org/wp-content/uploads/2022/03/DSC07673-scaled-2048x1570.jpg,https://wearecatalyst.org/wp-content/uploads/2021/01/2F6A1513.jpg','We are an independent, not-for-profit organisation working together for the greater good, enabling a connected community of like-minded innovators in an entrepreneurial eco-system that is the key driver of the knowledge economy in Northern Ireland.','https://wearecatalyst.org','enquiries@wearecatalyst.org','+44(0)28 9073 7800','08:00 - 18:00','Use the email address or phone number to call ahead and book a desk, let them know you''re a Tramshed member'); INSERT INTO "coworking_spaces" VALUES ('C4DI','C4DI Campus, 31-38 Queen Street, Hull, HU1 1UU','https://images.squarespace-cdn.com/content/v1/5709040420c647579532dbb4/1594914119071-OWI9G22S295OCMSWL0VL/_K5L1162.jpg?format=2500w','https://images.squarespace-cdn.com/content/v1/5709040420c647579532dbb4/1588346951023-V0QWKQI35IDUACMOJ0WM/_MKL2718.jpg?format=750w,https://images.squarespace-cdn.com/content/v1/5709040420c647579532dbb4/1588346977833-LGY6P9473H2C5JF6I2UG/_K5M5505.jpg?format=750w','C4DI is an incubator that helps tech companies grow, and traditional businesses innovate.','http://www.c4di.co.uk','lc@c4di.net','+44 1482 304244','9am - 5pm','Use the email address or phone number to call ahead and book a desk, let them know you''re a Tramshed member'); diff --git a/static/CSS/loginstyle.css b/static/CSS/loginstyle.css index 2c44a02..dcb9b68 100644 --- a/static/CSS/loginstyle.css +++ b/static/CSS/loginstyle.css @@ -22,8 +22,4 @@ body{ font-family: 'Sora', sans-serif; background-color: #212529; color: white; -<<<<<<< HEAD } -======= -} ->>>>>>> 9c7255d510762a8f16afeba2657cad4a0f8b8239 diff --git a/static/JS/login.js b/static/JS/login.js index 075f71b..23973bc 100644 --- a/static/JS/login.js +++ b/static/JS/login.js @@ -1,7 +1,29 @@ function onLoad() { - document.getElementById('loginButton').addEventListener('click', clickLogin) + document.getElementById('loginButton').addEventListener('click', AddRecord) } -function clickLogin() { - -} \ No newline at end of file +function AddRecord(e) { + e.preventDefault(); + e.stopPropagation(); + var recordEmail = document.getElementById("recordEmail").value; + var recordPassword = document.getElementById("recordPassword").value; + + var params = 'recordEmail='+recordEmail+'&recordPassword='+recordPassword; + + var xhttp = new XMLHttpRequest(); + xhttp.open("POST", '/AddRecord', true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.onreadystatechange = function() { + if (xhttp.readyState === 4 && xhttp.status === 200) { + console.log(xhttp.responseText); + serverResponse = JSON.parse(xhttp.responseText); + document.getElementById("recordEmail").value = serverResponse[0][0]; + document.getElementById("recordPassword").value = serverResponse[0][1]; + document.getElementById("DEBUGserverMessage").innerHTML = xhttp.responseText; + } else { + console.error(`Status Text: ${xhttp.statusText}.`); + console.error(`Ready State: ${xhttp.readyState}.`); + } + }; + xhttp.send(params); +} diff --git a/static/login.html b/static/login.html index 7ae1a4d..7105217 100644 --- a/static/login.html +++ b/static/login.html @@ -17,21 +17,22 @@ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Sora:wght@800&display=swap" rel="stylesheet"> <link rel="stylesheet" href="CSS/loginstyle.css"> +<!-- <script src="JS/login.js"></script> --> <title>Login</title> <div id="card" class="card text-dark w-25 text-center"> <div class="card-body text-center"> - <form> + <form action="/login" method="post"> <!-- Email input --> <div class="form-outline mb-4"> - <input type="email" id="recordEmail" class="form-control" /> + <input type="email" name="recordEmail" id="recordEmail" class="form-control" /> <label class="form-label" for="form2Example1">Email address</label> </div> <!-- Password input --> <div class="form-outline mb-4"> - <input type="password" id="recordPassword" class="form-control" /> + <input type="password" name="recordPassword" id="recordPassword" class="form-control" /> <label class="form-label" for="form2Example2">Password</label> </div> @@ -51,7 +52,7 @@ </div> <!-- Submit button --> - <button onclick="window.location.href='landingpage.html';" type="button" class="btn btn-light" id="loginButton"> + <button type="submit" class="btn btn-light" id="loginButton"> <span class="spinner-grow spinner-grow-sm"></span> Sign in </button> diff --git a/static/landingpage.html b/templates/landingpage.html similarity index 95% rename from static/landingpage.html rename to templates/landingpage.html index fca7298..755f6ac 100644 --- a/static/landingpage.html +++ b/templates/landingpage.html @@ -20,7 +20,7 @@ </header> <header class="masthead bg-dark text-white text-left"> <div class="container-fluid"> - <img id="logo" src="Media/logo.png"/> + <img id="logo" src="static/Media/logo.png"/> <h1 id="header">Tramshed Tech</h1> </div> </header> @@ -31,9 +31,9 @@ <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Sora:wght@800&display=swap" rel="stylesheet"> - <link rel="stylesheet" href="CSS/landingstyle.css"> + <link rel="stylesheet" href="static/CSS/landingstyle.css"> <title>Tramshed Tech</title> - <img id="tramshed" src="Media/tramshed.jpg"> + <img id="tramshed" src="static/Media/tramshed.jpg"> <div class="bg-dark p-3"> <div id="buttons" class="flex-container"> <button onclick="window.location.href='locations.html';" type="button" class="btn btn-light"> diff --git a/testloginserver.py b/testloginserver.py index a28f96d..a8e30be 100644 --- a/testloginserver.py +++ b/testloginserver.py @@ -1,46 +1,43 @@ import os import sqlite3 -from flask import Flask, redirect, request, render_template, jsonify +from flask import Flask, request, render_template app = Flask(__name__) -DATABASE = "login.db" ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) -@app.route("/SearchRecord", methods=['POST']) -def searchRecord(): - if request.method =='POST': +@app.route("/login", methods=['GET', 'POST']) +def login(): + error = None + if (request.method =='POST'): + recordEmail = request.form.get('recordEmail') + print(recordEmail) + recordPassword = request.form.get('recordPassword') + print(recordPassword) try: - recordEmail = request.form.get('recordEmail', default="Error") - conn = sqlite3.connect(DATABASE) - cur = conn.cursor() - cur.execute("SELECT * FROM login WHERE Email=?;", [recordEmail]) - recordData = cur.fetchall() - except: - print(f"Error: {recordData}") - conn.close() + conn = sqlite3.connect("login.db") + cur = conn.cursor() + cur.execute("INSERT INTO login ('Email','Password') values (?,?)", (recordEmail, recordPassword)) + conn.commit() + recordData = cur.fetchall() + print(recordData) + return recordData + except Exception as e: + recordData = e + print(f"Error: {e}") + conn.close() finally: - conn.close() - print(f"{str(recordData)} Record found.") - return str(recordData) + conn.close() + return render_template('landingpage.html') + +def select(): + conn = sqlite3.connect("login.db") + cur = conn.cursor() + cur.execute("SELECT Email, Password FROM login") + users = cur.fetchall() + conn.close() + return users -@app.route("/AddRecord", methods=['POST']) -def addRecord(): - if (request.method == 'POST'): - recordEmail = request.form['recordEmail'] - recordPassword = request.form['recordPassword'] - conn = sqlite3.connect(DATABASE) - cur = conn.cursor() - cur.execute("INSERT INTO login ('Email', 'Password')\ - VALUES (?,?)", (recordEmail, recordPassword)) - conn.commit() - conn.close() - - infoMessage = (f'{recordData} Record added.') - - print(infoMessage) - return (infoMessage) - if __name__ == "__main__": app.run(debug=True) \ No newline at end of file -- GitLab