This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def login_required(f): | |
""" | |
Decorate routes to require login. | |
http://flask.pocoo.org/docs/1.0/patterns/viewdecorators/ | |
""" | |
@wraps(f) | |
def decorated_function(*args, **kwargs): | |
if session.get("user_id") is None: | |
return redirect("/") | |
return f(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
def dbinit(): | |
connection = sqlite3.connect('database.db') | |
with open('schema.sql') as f: | |
connection.executescript(f.read()) | |
cur = connection.cursor() | |
connection.commit() | |
connection.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function () { | |
// Check local storage for user's theme preference | |
const currentTheme = localStorage.getItem('theme'); | |
if (currentTheme) { | |
$('#theme-stylesheet').attr('href', currentTheme); | |
} | |
// Toggle dark mode when the checkbox changes | |
$('#dark-mode-toggle').change(function () { | |
if ($(this).is(':checked')) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a new SQLite database or open an existing one | |
sqlite3 e_commerce.db | |
# Define the Users table | |
CREATE TABLE Users ( | |
user_id INTEGER PRIMARY KEY, | |
username TEXT, | |
email TEXT, | |
password_hash TEXT, | |
first_name TEXT, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
//when a button is clicked | |
$('.page-button').on('click', function(){ | |
// Get the target page | |
var $target = $(this).attr('data-target'); | |
var $targetSelector = 'section#' + $target; | |
// Show target page | |
$($targetSelector).removeClass('page-hidden'); | |
$($targetSelector).addClass('page-visible'); | |
// Hide everything page |