1) Replace Flask-BabelEx with Flask-Babel. Fixes #6088

2) Upgrade Flask to version 2. Fixes #7010
This commit is contained in:
Akshay Joshi
2021-11-24 17:22:57 +05:30
parent 3a30f27153
commit d644b4f94e
120 changed files with 211 additions and 199 deletions

View File

@@ -209,8 +209,11 @@ def upgrade():
os.urandom(32)).decode()
db.engine.execute(sql)
sql = "INSERT INTO keys (name, value) VALUES ('SECRET_KEY', '%s')" % base64.urlsafe_b64encode(
os.urandom(32)).decode()
if hasattr(config, 'SECRET_KEY'):
sql = "INSERT INTO keys (name, value) VALUES ('SECRET_KEY', '%s')" % config.SECRET_KEY
else:
sql = "INSERT INTO keys (name, value) VALUES ('SECRET_KEY', '%s')" % base64.urlsafe_b64encode(
os.urandom(32)).decode()
db.engine.execute(sql)
# If SECURITY_PASSWORD_SALT is not in the config, but we're upgrading, then it must (unless the

View File

@@ -22,7 +22,7 @@ import sqlalchemy as sa
from alembic import op
from flask import current_app
from flask_security import Security, SQLAlchemyUserDatastore
from flask_security.utils import encrypt_password
from flask_security.utils import hash_password
from pgadmin.model import db, User, Role
from pgadmin.setup import get_version
from pgadmin.setup import user_info
@@ -116,14 +116,24 @@ VALUES(1, 1, 'Servers')
os.urandom(32)
).decode()
)
secret_key = getattr(
config, 'SECRET_KEY', base64.urlsafe_b64encode(
os.urandom(32)
).decode()
)
if current_app.extensions.get('security') is None:
current_app.config['SECURITY_PASSWORD_SALT'] = current_salt
current_app.config['SECRET_KEY'] = secret_key
user_datastore = SQLAlchemyUserDatastore(db, User, Role)
Security(current_app, user_datastore, register_blueprint=False)
else:
current_app.config['SECURITY_PASSWORD_SALT'] = current_salt
current_app.config['SECRET_KEY'] = secret_key
setattr(config, 'SECURITY_PASSWORD_SALT', current_salt)
password = encrypt_password(password)
setattr(config, 'SECRET_KEY', secret_key)
password = hash_password(password)
db.engine.execute("""
INSERT INTO "user"