merging toms commits
This commit is contained in:
commit
81e2357e2f
151
db.py
151
db.py
|
@ -15,86 +15,85 @@ class DB(object):
|
||||||
'ticketfrei.sqlite')
|
'ticketfrei.sqlite')
|
||||||
self.conn = sqlite3.connect(dbfile)
|
self.conn = sqlite3.connect(dbfile)
|
||||||
self.cur = self.conn.cursor()
|
self.cur = self.conn.cursor()
|
||||||
self.cur.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='user';")
|
self.create()
|
||||||
if self.cur.fetchall() == []:
|
|
||||||
self.create()
|
|
||||||
print("Initialized new sqlite database.")
|
|
||||||
self.secret = urandom(32)
|
self.secret = urandom(32)
|
||||||
self.config = ticketfrei.get_config()
|
self.config = ticketfrei.get_config()
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
# init db
|
# init db
|
||||||
self.cur.executescript('\
|
self.cur.executescript('''
|
||||||
CREATE TABLE "user" (\
|
CREATE TABLE IF NOT EXISTS user (
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
`email` TEXT,\
|
email TEXT,
|
||||||
`passhash` TEXT,\
|
passhash TEXT,
|
||||||
`enabled` INTEGER DEFAULT 1\
|
enabled INTEGER DEFAULT 1
|
||||||
);\
|
);
|
||||||
CREATE TABLE "twitter_request_tokens" (\
|
CREATE TABLE IF NOT EXISTS twitter_request_tokens (
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
`user_id` INTEGER,\
|
user_id INTEGER,
|
||||||
`request_token` TEXT,\
|
request_token TEXT,
|
||||||
FOREIGN KEY(`user_id`) REFERENCES `user` ( `id` )\
|
FOREIGN KEY(user_id) REFERENCES user(id)
|
||||||
);\
|
);
|
||||||
CREATE TABLE "twitter_accounts" (\
|
CREATE TABLE IF NOT EXISTS twitter_accounts (
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
`user_id` INTEGER,\
|
user_id INTEGER,
|
||||||
`client_id` TEXT,\
|
client_id TEXT,
|
||||||
`client_secret` TEXT,\
|
client_secret TEXT,
|
||||||
FOREIGN KEY(`user_id`) REFERENCES `user` ( `id` )\
|
FOREIGN KEY(user_id) REFERENCES user(id)
|
||||||
);\
|
);
|
||||||
CREATE TABLE "trigger_good" (\
|
CREATE TABLE IF NOT EXISTS trigger_good (
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
`user_id` INTEGER,\
|
user_id INTEGER,
|
||||||
`words` TEXT,\
|
words TEXT,
|
||||||
FOREIGN KEY(`user_id`) REFERENCES `user` ( `id` )\
|
FOREIGN KEY(user_id) REFERENCES user(id)
|
||||||
);\
|
);
|
||||||
CREATE TABLE "trigger_bad" (\
|
CREATE TABLE IF NOT EXISTS trigger_bad (
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
`user_id` INTEGER,\
|
user_id INTEGER,
|
||||||
`words` TEXT,\
|
words TEXT,
|
||||||
FOREIGN KEY(`user_id`) REFERENCES `user` ( `id` )\
|
FOREIGN KEY(user_id) REFERENCES user(id)
|
||||||
);\
|
);
|
||||||
CREATE TABLE "mastodon_instances" (\
|
CREATE TABLE IF NOT EXISTS mastodon_instances (
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
`instance` TEXT,\
|
instance TEXT,
|
||||||
`client_id` TEXT,\
|
client_id TEXT,
|
||||||
`client_secret` TEXT\
|
client_secret TEXT
|
||||||
);\
|
);
|
||||||
CREATE TABLE "mastodon_accounts" (\
|
CREATE TABLE IF NOT EXISTS mastodon_accounts (
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
`user_id` INTEGER,\
|
user_id INTEGER,
|
||||||
`access_token` TEXT,\
|
access_token TEXT,
|
||||||
`instance_id` TEXT,\
|
instance_id TEXT,
|
||||||
`active` INTEGER,\
|
active INTEGER,
|
||||||
FOREIGN KEY(`user_id`) REFERENCES `user` ( `id` ),\
|
FOREIGN KEY(user_id) REFERENCES user(id),
|
||||||
FOREIGN KEY(`instance_id`) REFERENCES `mastodon_instances` ( `id` )\
|
FOREIGN KEY(instance_id) REFERENCES mastodon_instances(id)
|
||||||
);\
|
);
|
||||||
CREATE TABLE "seen_toots" (\
|
CREATE TABLE IF NOT EXISTS seen_toots (
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
`user_id` INTEGER,\
|
user_id INTEGER,
|
||||||
`mastodon_accounts_id` INTEGER,\
|
mastodon_accounts_id INTEGER,
|
||||||
`toot_id` TEXT,\
|
toot_id TEXT,
|
||||||
FOREIGN KEY(`user_id`) REFERENCES `user` ( `id` ),\
|
FOREIGN KEY(user_id) REFERENCES user(id),
|
||||||
FOREIGN KEY(`mastodon_accounts_id`) REFERENCES `mastodon_accounts` ( `id` )\
|
FOREIGN KEY(mastodon_accounts_id)
|
||||||
);\
|
REFERENCES mastodon_accounts(id)
|
||||||
CREATE TABLE "mail" (\
|
);
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\
|
CREATE TABLE IF NOT EXISTS mail (
|
||||||
`user_id` INTEGER,\
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
`email` TEXT,\
|
user_id INTEGER,
|
||||||
`active` INTEGER,\
|
email TEXT,
|
||||||
FOREIGN KEY(`user_id`) REFERENCES `user` ( `id` )\
|
active INTEGER,
|
||||||
);\
|
FOREIGN KEY(user_id) REFERENCES user(id)
|
||||||
CREATE TABLE "seen_tweets" (\
|
);
|
||||||
`id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,\
|
CREATE TABLE IF NOT EXISTS seen_tweets (
|
||||||
`user_id` INTEGER,\
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||||
`twitter_accounts_id` INTEGER,\
|
user_id INTEGER,
|
||||||
`tweet_id` TEXT,\
|
twitter_accounts_id INTEGER,
|
||||||
FOREIGN KEY(`user_id`) REFERENCES `user` ( `id` )\
|
tweet_id TEXT,
|
||||||
FOREIGN KEY(`twitter_accounts_id`) REFERENCES `twitter_accounts` ( `id` )\
|
FOREIGN KEY(user_id) REFERENCES user(id)
|
||||||
);\
|
FOREIGN KEY(twitter_accounts_id)
|
||||||
')
|
REFERENCES twitter_accounts(id)
|
||||||
|
);
|
||||||
|
''')
|
||||||
|
|
||||||
def token(self, email, password):
|
def token(self, email, password):
|
||||||
return jwt.encode({
|
return jwt.encode({
|
||||||
|
@ -117,7 +116,7 @@ class DB(object):
|
||||||
row = self.cur.fetchone()
|
row = self.cur.fetchone()
|
||||||
if not row:
|
if not row:
|
||||||
return None # No user with this email
|
return None # No user with this email
|
||||||
if not scrypt_mcf_check(row[1].encode("utf-8"),
|
if not scrypt_mcf_check(row[1].encode('ascii'),
|
||||||
password.encode('utf-8')):
|
password.encode('utf-8')):
|
||||||
return None # Wrong passphrase
|
return None # Wrong passphrase
|
||||||
return User(self, row[0])
|
return User(self, row[0])
|
||||||
|
|
Loading…
Reference in a new issue