Make sessions permanent
This commit is contained in:
@@ -1,9 +1,15 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
"""Base configuration."""
|
"""Base configuration."""
|
||||||
SECRET_KEY = os.environ.get('SECRET_KEY', '234234sdfsdfsdfsdf345345')
|
SECRET_KEY = os.environ.get('SECRET_KEY', '234234sdfsdfsdfsdf345345')
|
||||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
|
|
||||||
|
# Session and Remember Me configurations to keep user logged in almost indefinitely (10 years)
|
||||||
|
PERMANENT_SESSION_LIFETIME = timedelta(days=3650)
|
||||||
|
REMEMBER_COOKIE_DURATION = timedelta(days=3650)
|
||||||
|
|
||||||
class DevelopmentConfig(Config):
|
class DevelopmentConfig(Config):
|
||||||
"""Development configuration."""
|
"""Development configuration."""
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ def login():
|
|||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
user = User.query.filter_by(username=form.username.data).first()
|
user = User.query.filter_by(username=form.username.data).first()
|
||||||
if user and check_password_hash(user.password_hash, form.password.data):
|
if user and check_password_hash(user.password_hash, form.password.data):
|
||||||
login_user(user)
|
from flask import session
|
||||||
|
session.permanent = True
|
||||||
|
login_user(user, remember=True)
|
||||||
flash("Logged in successfully.", "success")
|
flash("Logged in successfully.", "success")
|
||||||
return redirect(url_for('main.dashboard'))
|
return redirect(url_for('main.dashboard'))
|
||||||
flash("Invalid username or password.", "danger")
|
flash("Invalid username or password.", "danger")
|
||||||
|
|||||||
Reference in New Issue
Block a user