Email SMTP Fix
This commit is contained in:
43
migrate_password_reset.py
Normal file
43
migrate_password_reset.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
Migration script to add password reset fields to users table.
|
||||
Run this once to update the database schema for password reset functionality.
|
||||
"""
|
||||
|
||||
from database import engine
|
||||
from sqlalchemy import text
|
||||
|
||||
def add_password_reset_columns():
|
||||
"""Add password reset token, expiration, and force change columns to users table"""
|
||||
|
||||
migrations = [
|
||||
# Password reset token (secure random string)
|
||||
"ALTER TABLE users ADD COLUMN IF NOT EXISTS password_reset_token VARCHAR",
|
||||
|
||||
# Password reset expiration (1 hour from token creation)
|
||||
"ALTER TABLE users ADD COLUMN IF NOT EXISTS password_reset_expires TIMESTAMP",
|
||||
|
||||
# Force password change on next login (for admin resets)
|
||||
"ALTER TABLE users ADD COLUMN IF NOT EXISTS force_password_change BOOLEAN NOT NULL DEFAULT FALSE"
|
||||
]
|
||||
|
||||
try:
|
||||
print("Adding password reset columns to users table...")
|
||||
with engine.connect() as conn:
|
||||
for sql in migrations:
|
||||
print(f" Executing: {sql[:70]}...")
|
||||
conn.execute(text(sql))
|
||||
conn.commit()
|
||||
|
||||
print("\n✅ Migration completed successfully!")
|
||||
print("\nAdded columns:")
|
||||
print(" - password_reset_token (VARCHAR)")
|
||||
print(" - password_reset_expires (TIMESTAMP)")
|
||||
print(" - force_password_change (BOOLEAN, default=FALSE)")
|
||||
print("\nYou can now run password reset functionality.")
|
||||
|
||||
except Exception as e:
|
||||
print(f"\n❌ Migration failed: {e}")
|
||||
raise
|
||||
|
||||
if __name__ == "__main__":
|
||||
add_password_reset_columns()
|
||||
Reference in New Issue
Block a user