UPDATE: Added functions for adding to newsletter
This commit is contained in:
Binary file not shown.
@@ -58,3 +58,10 @@ CREATE TABLE followed_categories
|
|||||||
FOREIGN KEY(user_id) REFERENCES users(user_id) ON DELETE CASCADE,
|
FOREIGN KEY(user_id) REFERENCES users(user_id) ON DELETE CASCADE,
|
||||||
FOREIGN KEY(category_id) REFERENCES categories(category_id) ON DELETE CASCADE
|
FOREIGN KEY(category_id) REFERENCES categories(category_id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS newsletter;
|
||||||
|
CREATE TABLE newsletter
|
||||||
|
(
|
||||||
|
email VARCHAR(256) NOT NULL,
|
||||||
|
PRIMARY KEY(email)
|
||||||
|
);
|
||||||
@@ -7,6 +7,7 @@ from utils.auth import generate_token
|
|||||||
from secrets import token_hex
|
from secrets import token_hex
|
||||||
from .user_utils import get_session_info_email
|
from .user_utils import get_session_info_email
|
||||||
import redis
|
import redis
|
||||||
|
from database.database import Database
|
||||||
|
|
||||||
redis_url = "redis://redis:6379/1"
|
redis_url = "redis://redis:6379/1"
|
||||||
r = redis.from_url(redis_url, decode_responses=True)
|
r = redis.from_url(redis_url, decode_responses=True)
|
||||||
@@ -157,4 +158,35 @@ def newsletter_conf(email):
|
|||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
add_to_newsletter(email)
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
def add_to_newsletter(email):
|
||||||
|
"""
|
||||||
|
Add a person to the newsletter database
|
||||||
|
"""
|
||||||
|
# Create connection to the database
|
||||||
|
db = Database()
|
||||||
|
db.create_connection()
|
||||||
|
|
||||||
|
# Add the users email to the newsletter table
|
||||||
|
db.execute("""
|
||||||
|
INSERT INTO newsletter (email)
|
||||||
|
VALUES (?);
|
||||||
|
""", (email,))
|
||||||
|
|
||||||
|
|
||||||
|
def remove_from_newsletter(email):
|
||||||
|
"""
|
||||||
|
Remove a person from the newsletter database
|
||||||
|
"""
|
||||||
|
# Create connection to the database
|
||||||
|
db = Database()
|
||||||
|
db.create_connection()
|
||||||
|
|
||||||
|
# Remove the users email from the newsletter table
|
||||||
|
db.execute("""
|
||||||
|
DELETE FROM newsletter
|
||||||
|
WHERE email = ?;
|
||||||
|
""", (email,))
|
||||||
|
|||||||
Reference in New Issue
Block a user