Skip to content
Snippets Groups Projects
Commit a7d79b10 authored by fcrisafulli-dev's avatar fcrisafulli-dev
Browse files

added user impl

parent d5f91a45
No related branches found
No related tags found
No related merge requests found
# Crisis Events Text Summarization
## Adgenda
## Index
## QSL Schema
- [SQL](#SQL)
```
Enum CollectionType {
TextFileList
URLList
HTMLFileList
}
## Specification
Table EventCollections {
User: UUID,
CollectionType: CollectionType
CollectionID: UUID,
Summary: BLOB
}
### SQL
Table TextFileCollections{
ID: UUID,
Collection: idk
}
... similar for all other enum types
```sql
TABLE event_collections(
collection_id INTEGER PRIMARY KEY,
owner_id INTEGER,
--stores a json with 3 categories of input data. See Collection Data chapter for more info
collection_data TEXT,
collection_summary TEXT,
collection_name TEXT
);
DROP TABLE IF EXISTS users;
CREATE TABLE users(
user_id INTEGER,
user_name TEXT,
-- hashed username and password for authentication. No, this isnt the most secure thing in the world
user_hash TEXT
);
```
\ No newline at end of file
No preview for this file type
No preview for this file type
{"Users": 0, "Collections": 3}
\ No newline at end of file
{"Users": 1, "Collections": 3}
\ No newline at end of file
......@@ -20,6 +20,9 @@ class CrisisEventsDatabase:
"""
raise "Not Implemented"
def create_user(self, username: str, password: str):
raise "Not Implemented"
def get_collection(self, collection_id:int, user_id: int):
"""
Returns the collection data if the `user_id` matches in the corresponding `collection_id` entry.
......
No preview for this file type
......@@ -2,6 +2,7 @@ import sqlite3
import shutil
import os
import json
import hashlib
import database_api
......@@ -55,6 +56,16 @@ class SqliteDatabaseAPI(database_api.CrisisEventsDatabase):
print(f"Created new collection '{collection_name}' owned by {user_id}")
self._disconnect(connection, cur)
return collection_id
def create_user(self, username: str, password: str):
connection, cur = self._connect()
user_id = self.get_next_user_id()
user_hash = hashlib.md5(password.encode()).digest().hex()
print(user_hash)
cur.execute("INSERT INTO users VALUES (?, ?, ?)", (user_id,username,user_hash,))
print(f"Created new user '{username}'")
self._disconnect(connection, cur)
return user_id
def get_collection(self,collection_id:int, user_id: int):
connection, cur = self._connect()
......@@ -84,6 +95,13 @@ class SqliteDatabaseAPI(database_api.CrisisEventsDatabase):
result = cur.fetchall()
self._disconnect(connection, cur)
return result
def get_sample_of_users(self):
connection, cur = self._connect()
cur.execute("SELECT * FROM users LIMIT 10;")
result = cur.fetchall()
self._disconnect(connection, cur)
return result
def initialize(self, reset = False):
#try to delete the databse and all relevant data
......
......@@ -9,8 +9,13 @@ database:CrisisEventsDatabase = None
#this function is terrible, oh well!
def database_debug_view():
db_html = ""
user_db_html = ""
for collection in database.get_sample_of_collections():
db_html += f"<br/><code>{collection}</code>"
for collection in database.get_sample_of_users():
user_db_html += f"<br/><code>{collection}</code>"
return f"""
<html>
<head></head>
......@@ -19,6 +24,9 @@ def database_debug_view():
<p>Warning: if there are any '<' or '>' or '/' or '\\' in the database: this will break! </p>
<code>CollectionID, UserID, CollectionData, CollectionSummary, CollectionName</code>
{db_html}
<br/><br/><br/>
<code>UserID, UserName, Hash</code>
{user_db_html}
</body>
</html>
"""
......@@ -52,6 +60,7 @@ def database_service():
if __name__ == '__main__':
database = runtime_import("database_implementation/")[0].IMPLEMENTATION()
database.initialize()
database.create_user("test_user","12345")
database.create_collection(0,"First Collection")
database.create_collection(0,"Second Collection")
database.create_collection(0,"Third Collection")
......
......@@ -5,4 +5,11 @@ CREATE TABLE event_collections(
collection_data TEXT,
collection_summary TEXT,
collection_name TEXT
);
DROP TABLE IF EXISTS users;
CREATE TABLE users(
user_id INTEGER,
user_name TEXT,
user_hash TEXT
);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment