mirror of
https://github.com/Adam-Ant/QuotesDB
synced 2024-12-20 11:34:35 +00:00
Small restructure, add initial SQL set up and related SQL file
This commit is contained in:
parent
fd8e17926e
commit
679a2d872e
@ -1,7 +1,9 @@
|
|||||||
CREATE TABLE Users (
|
CREATE TABLE Users (
|
||||||
uid int NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
uid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
user varchar(255) NOT NULL,
|
user VARCHAR(255) NOT NULL,
|
||||||
realname varchar(255) NOT NULL
|
realname VARCHAR(255) NOT NULL,
|
||||||
|
password VARCHAR(255),
|
||||||
|
isadmin BIT
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE Quotes (
|
CREATE TABLE Quotes (
|
||||||
|
9
main.py
9
main.py
@ -8,8 +8,6 @@ pp = pprint.PrettyPrinter(indent=4)
|
|||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
app.secret_key = rand(24)
|
|
||||||
|
|
||||||
# Thank you based StackOverflow
|
# Thank you based StackOverflow
|
||||||
def cleanup_string(text):
|
def cleanup_string(text):
|
||||||
text = text.encode("ascii", "replace").decode()
|
text = text.encode("ascii", "replace").decode()
|
||||||
@ -26,8 +24,14 @@ def mysql_do(query):
|
|||||||
db.close()
|
db.close()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def app_init():
|
||||||
|
mysql_do("CREATE TABLE IF NOT EXISTS Users ( uid INT NOT NULL AUTO_INCREMENT PRIMARY KEY, user VARCHAR(255) NOT NULL, realname VARCHAR(255) NOT NULL, password VARCHAR(255), isadmin BIT );")
|
||||||
|
mysql_do("CREATE TABLE IF NOT EXISTS Quotes ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, quote VARCHAR(2048) NOT NULL, date VARCHAR(255) NOT NULL, user INT NOT NULL, context VARCHAR(8000), FOREIGN KEY (user) REFERENCES Users(uid) );")
|
||||||
|
app.secret_key = rand(24)
|
||||||
|
global userdb
|
||||||
userdb = mysql_do("SELECT * FROM Users")
|
userdb = mysql_do("SELECT * FROM Users")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
if 'username' in session:
|
if 'username' in session:
|
||||||
@ -109,4 +113,5 @@ def utility_processor():
|
|||||||
return dict(uid_to_user=uid_to_user)
|
return dict(uid_to_user=uid_to_user)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
app_init()
|
||||||
app.run(host="0.0.0.0", debug=True)
|
app.run(host="0.0.0.0", debug=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user