diff --git a/project_db.sql b/project_db.sql index 65d9b087e57eae411834ef03779849edf0270f18..ecd3a9c236dfbbe12d3905c0a44ea6bc397d88ac 100644 --- a/project_db.sql +++ b/project_db.sql @@ -11,9 +11,15 @@ CREATE TABLE IF NOT EXISTS "coworking_spaces" ( "Opening_Hours" TEXT, "Checkin_Instructions" TEXT ); + +CREATE TABLE IF NOT EXISTS "login" ( + "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'); INSERT INTO "coworking_spaces" VALUES ('Dogpatch Labs','Custom House Quay, Dublin, D01 Y6H7','https://dogpatchlabs.wpenginepowered.com/wp-content/uploads/2022/09/ian_browne.jpg','https://dogpatchlabs.wpenginepowered.com/wp-content/uploads/2021/07/bordered.jpg,https://dogpatchlabs.com/wp-content/uploads/2020/03/UG_3-1.jpg','Dogpatch Labs is a startup hub, located in the heart of Dublin’s Digital Docklands.','https://dogpatchlabs.com','info@dogpatchlabs.com',NULL,'8:30 - 5:30','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 ('Stafion F','5 Parvis Alan Turing, Paris','https://stationf.co/img/misc/create-zone.jpg',',https://stationf.co/img/flatmates/coffee-restaurant.jpg','Based in central Paris, STATION F gathers a whole entrepreneurial ecosystem under one roof. We help entrepreneurs bring their ambitious ideas to life.','https://stationf.co',NULL,NULL,'0:00 - 0:00','Book through the Tramshed Tech app'); +INSERT INTO "coworking_spaces" VALUES ('Station F','5 Parvis Alan Turing, Paris','https://stationf.co/img/misc/create-zone.jpg',',https://stationf.co/img/flatmates/coffee-restaurant.jpg','Based in central Paris, STATION F gathers a whole entrepreneurial ecosystem under one roof. We help entrepreneurs bring their ambitious ideas to life.','https://stationf.co',NULL,NULL,'0:00 - 0:00','Book through the Tramshed Tech app'); COMMIT; diff --git a/project_server.py b/project_server.py index 33dda74ecc13f18f519566e86460ad94285e2036..6b4f7a08ea524499c2d7e7fbd160f0187ab170bd 100644 --- a/project_server.py +++ b/project_server.py @@ -18,6 +18,10 @@ def connect_db(db_file=DATABASE): print("Error connecting to database.") return conn +@app.route("/home", methods=["GET"]) +def load(): + return render_template('landingpage.html') + @app.route("/", methods=['GET']) def returnIndex(): if (request.method == 'GET'): @@ -209,7 +213,33 @@ def Locations(): return render_template('locations.html') +@app.route("/login", methods=["GET"]) +def loadlogin(): + return render_template('login.html') +@app.route("/signin", 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: + conn = sqlite3.connect(DATABASE) + 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() + return render_template('locations.html') if __name__ == "__main__": diff --git a/static/CSS/loginstyle.css b/static/CSS/loginstyle.css index 2c44a02a44c292502c7c4862d8e8b78d86024f40..dcb9b6845e58916f793bc9f3e02e554da07a83d2 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 new file mode 100644 index 0000000000000000000000000000000000000000..23973bcbaa5ea39be6a75311c8293b0e8ccb6711 --- /dev/null +++ b/static/JS/login.js @@ -0,0 +1,29 @@ +function onLoad() { + document.getElementById('loginButton').addEventListener('click', AddRecord) +} + +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 deleted file mode 100644 index 5bbe1b72a5529fc7b8b0ff4c1c3fa16cd0b44f59..0000000000000000000000000000000000000000 --- a/static/login.html +++ /dev/null @@ -1,75 +0,0 @@ -<!DOCTYPE html> -<head> - <meta charset="utf-8"> - <meta name="viewport" content="width=device-width, initial-scale=1"> -</head> -<header class="masthead bg-dark text-white text-center"> - <div class="container-fluid"> - <img id="logo" src="Media/logo.png"/> - <h1 id="header">Tramshed Tech</h1> - </div> - </header> -<body> - <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"> - <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" ></script> - <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js" integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT" crossorigin="anonymous"></script> - <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/loginstyle.css"> - <title>Login</title> - <div id="card" class="card text-dark w-25 text-center"> - <div class="card-body text-center"> - - - <form> - <!-- Email input --> - <div class="form-outline mb-4"> -<<<<<<< HEAD - <input type="email" id="recordEmail" class="form-control" /> -======= - <input type="email" id="form2Example1" class="form-control" /> ->>>>>>> 9c7255d510762a8f16afeba2657cad4a0f8b8239 - <label class="form-label" for="form2Example1">Email address</label> - </div> - - <!-- Password input --> - <div class="form-outline mb-4"> -<<<<<<< HEAD - <input type="password" id="recordPassword" class="form-control" /> -======= - <input type="password" id="form2Example2" class="form-control" /> ->>>>>>> 9c7255d510762a8f16afeba2657cad4a0f8b8239 - <label class="form-label" for="form2Example2">Password</label> - </div> - - <!-- 2 column grid layout for inline styling --> - <div class="row mb-4"> - <div class="col d-flex justify-content-center"> - <!-- Checkbox --> - <div class="form-check"> - <input class="form-check-input" type="checkbox" value="" id="form2Example31" checked /> - <label class="form-check-label" for="form2Example31"> Remember me </label> - </div> - </div> - - <div class="col"> - <!-- Simple link --> - <a href="#!">Forgot password?</a> - </div> - - <!-- Submit button --> - <button onclick="window.location.href='landingpage.html';" type="button" class="btn btn-light"> - <span class="spinner-grow spinner-grow-sm"></span> - Sign in - </button> - <!-- Register buttons --> - <div class="text-center"> - <p>Not a member? <a href="#!">Register</a></p> - </form> - </body> -<<<<<<< HEAD -</html> -======= -</html> ->>>>>>> 9c7255d510762a8f16afeba2657cad4a0f8b8239 diff --git a/static/landingpage.html b/templates/landingpage.html similarity index 90% rename from static/landingpage.html rename to templates/landingpage.html index fca729848a41a620680e438f5ae7728876e074c1..9d4844de16795be0fc0306728d27535ad30e0261 100644 --- a/static/landingpage.html +++ b/templates/landingpage.html @@ -9,18 +9,21 @@ <div class="container-fluid"> <ul class="navbar-nav"> <li class="nav-item"> - <a class="nav-link" href="locations.html">Coworking locations</a> + <a class="nav-link" href="/locations">Coworking locations</a> </li> <li class="nav-item"> <a class="nav-link" href="/Manage_Coworking_Spaces">Manage locations</a> </li> + <li class="nav-item"> + <a class="nav-link" href="/login">Login</a> + </li> </ul> </div> </nav> </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 +34,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/templates/login.html b/templates/login.html new file mode 100644 index 0000000000000000000000000000000000000000..714500970704d5cf0a6418864b2e8724fa3e904e --- /dev/null +++ b/templates/login.html @@ -0,0 +1,55 @@ +<!DOCTYPE html> +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> +</head> +<nav class="navbar navbar-expand-sm bg-dark navbar-dark"> + <div class="container-fluid"> + <ul class="navbar-nav"> + <li class="nav-item"> + <a class="nav-link" href="/home">Back</a> + </li> + </ul> + </div> + </nav> +<header class="masthead bg-dark text-white text-center"> + <div class="container-fluid"> + <img id="logo" src="static/Media/logo.png"/> + <h1 id="header">Tramshed Tech</h1> + </div> + </header> +<body> + <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"> + <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" ></script> + <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js" integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT" crossorigin="anonymous"></script> + <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="static/CSS/loginstyle.css"> + <script src="static/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 action="/signin" method="post"> + <!-- Email input --> + <div class="form-outline mb-4"> + <input type="email" name="recordEmail" id="recordEmail" class="form-control" /> + <label class="form-label">Email address</label> + </div> + + <!-- Password input --> + <div class="form-outline mb-4"> + <input type="password" name="recordPassword" id="recordPassword" class="form-control" /> + <label class="form-label">Password</label> + </div> + + <!-- Submit button --> + <button type="submit" class="btn btn-light" id="loginButton" href="/locations"> + <span class="spinner-grow spinner-grow-sm"></span> + Sign in + </button> + </form> + </body> +</html> diff --git a/static/make_booking.html b/templates/make_booking.html similarity index 100% rename from static/make_booking.html rename to templates/make_booking.html diff --git a/testloginserver.py b/testloginserver.py index a28f96dad8ccf4b267f013c3699da65f0ade7f50..1cb3a9abdc0a10574357b2d40b3b6d9aabe675b3 100644 --- a/testloginserver.py +++ b/testloginserver.py @@ -1,46 +1,50 @@ import os import sqlite3 -from flask import Flask, redirect, request, render_template, jsonify +from flask import Flask, request, render_template, send_from_directory app = Flask(__name__) -DATABASE = "login.db" ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif']) -@app.route("/SearchRecord", methods=['POST']) -def searchRecord(): +@app.route("/home", methods=["GET"]) +def load(): + return render_template('landingpage.html') - if request.method =='POST': +@app.route("/locations", methods=["GET"]) +def loadlocations(): + return send_from_directory('static', 'locations.html') + +@app.route("/coworking", methods=["GET"]) +def loadcoworking(): + return render_template('manage_coworking_spaces.html') + +@app.route("/login", methods=["GET"]) +def loadlogin(): + return render_template('login.html') + +@app.route("/signin", 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) - -@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) - + conn.close() + return render_template('locations.html') + if __name__ == "__main__": app.run(debug=True) \ No newline at end of file