Day 69 of #100DaysOfCode — and today was a BIG one! 🔐🚀 I built a full authentication & authorization system into my Flask blog app completely from scratch. Here's what went into it: 🔓 𝗔𝘂𝘁𝗵𝗲𝗻𝘁𝗶𝗰𝗮𝘁𝗶𝗼𝗻 ✨ User registration & login with Flask-Login 🔒 Password hashing & salting with Werkzeug ⚠️ Duplicate email detection with flash messaging 👁️ Dynamic navbar toggling based on login state 🛡️ 𝗔𝘂𝘁𝗵𝗼𝗿𝗶𝘇𝗮𝘁𝗶𝗼𝗻 👷 Built a custom @admin_only Python decorator using functools.wraps 🚫 Admin-only routes return HTTP 403 for unauthorized users 👀 UI buttons hidden in templates using current_user.id checks 🗄️ 𝗥𝗲𝗹𝗮𝘁𝗶𝗼𝗻𝗮𝗹 𝗗𝗮𝘁𝗮𝗯𝗮𝘀𝗲 𝗗𝗲𝘀𝗶𝗴𝗻 🔗 One-to-Many: User → BlogPost 🔗 One-to-Many: User → Comment 🔗 One-to-Many: BlogPost → Comment ⚙️ SQLAlchemy relationships with back_populates & cascade deletes 💬 𝗖𝗼𝗺𝗺𝗲𝗻𝘁𝘀 & 𝗣𝗿𝗼𝗳𝗶𝗹𝗲 𝗣𝗶𝗰𝘁𝘂𝗿𝗲𝘀 ✏️ CKEditor-powered rich text comment form 👤 Gravatar integration using hashlib MD5 — zero external packages needed 🎭 Every commenter gets a unique identicon avatar automatically 💡 Key 𝗹𝗲𝘀𝘀𝗼𝗻𝘀: 🚨 Database schema decisions have real consequences — we rebuilt the DB twice as the schema evolved. In production you'd need proper migrations. Flask-Migrate is going on the list! 💥 Learned the hard way about cascade deletes — SQLAlchemy refuses to delete a parent record if children exist and constraints aren't set. One line of code fixes everything: cascade="all, delete-orphan" 31 days to go and the app is starting to feel like a real product! 💪🔥 #Python #Flask #WebDevelopment #SQLAlchemy #FlaskLogin #100DaysOfCode #LearningInPublic #BackendDevelopment #CodingJourney

To view or add a comment, sign in

Explore content categories