Merge branch 'PowerDNS-Admin:master' into setup-new-wiki-docs-2

This commit is contained in:
David Mc Ken 2022-12-08 23:11:29 -04:00 committed by GitHub
commit 4864bff51d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 28 deletions

View File

@ -19,7 +19,7 @@ logger = logging.getLogger('alembic.env')
# target_metadata = mymodel.Base.metadata # target_metadata = mymodel.Base.metadata
from flask import current_app from flask import current_app
config.set_main_option('sqlalchemy.url', config.set_main_option('sqlalchemy.url',
current_app.config.get('SQLALCHEMY_DATABASE_URI')) current_app.config.get('SQLALCHEMY_DATABASE_URI').replace("%","%%"))
target_metadata = current_app.extensions['migrate'].db.metadata target_metadata = current_app.extensions['migrate'].db.metadata
# other values from the config, defined by the needs of env.py, # other values from the config, defined by the needs of env.py,

View File

@ -14,9 +14,9 @@ def forward_request():
msg_str = "Sending request to powerdns API {0}" msg_str = "Sending request to powerdns API {0}"
if request.method != 'GET' and request.method != 'DELETE': if request.method != 'GET' and request.method != 'DELETE':
msg = msg_str.format(request.get_json(force=True)) msg = msg_str.format(request.get_json(force=True, silent=True))
current_app.logger.debug(msg) current_app.logger.debug(msg)
data = request.get_json(force=True) data = request.get_json(force=True, silent=True)
verify = False verify = False

View File

@ -60,31 +60,31 @@ class ApiKey(db.Model):
def update(self, role_name=None, description=None, domains=None, accounts=None): def update(self, role_name=None, description=None, domains=None, accounts=None):
try: try:
if role_name: if role_name:
role = Role.query.filter(Role.name == role_name).first() role = Role.query.filter(Role.name == role_name).first()
self.role_id = role.id self.role_id = role.id
if description: if description:
self.description = description self.description = description
if domains is not None: if domains is not None:
domain_object_list = Domain.query \ domain_object_list = Domain.query \
.filter(Domain.name.in_(domains)) \ .filter(Domain.name.in_(domains)) \
.all() .all()
self.domains[:] = domain_object_list self.domains[:] = domain_object_list
if accounts is not None: if accounts is not None:
account_object_list = Account.query \ account_object_list = Account.query \
.filter(Account.name.in_(accounts)) \ .filter(Account.name.in_(accounts)) \
.all() .all()
self.accounts[:] = account_object_list self.accounts[:] = account_object_list
db.session.commit() db.session.commit()
except Exception as e: except Exception as e:
msg_str = 'Update of apikey failed. Error: {0}' msg_str = 'Update of apikey failed. Error: {0}'
current_app.logger.error(msg_str.format(e)) current_app.logger.error(msg_str.format(e))
db.session.rollback db.session.rollback() # fixed line
raise e raise e
def get_hashed_password(self, plain_text_password=None): def get_hashed_password(self, plain_text_password=None):
# Hash a password for the first time # Hash a password for the first time

View File

@ -94,7 +94,7 @@ class User(db.Model):
def verify_totp(self, token): def verify_totp(self, token):
totp = pyotp.TOTP(self.otp_secret) totp = pyotp.TOTP(self.otp_secret)
return totp.verify(token) return totp.verify(token, valid_window = 5)
def get_hashed_password(self, plain_text_password=None): def get_hashed_password(self, plain_text_password=None):
# Hash a password for the first time # Hash a password for the first time
@ -107,7 +107,7 @@ class User(db.Model):
def check_password(self, hashed_password): def check_password(self, hashed_password):
# Check hashed password. Using bcrypt, the salt is saved into the hash itself # Check hashed password. Using bcrypt, the salt is saved into the hash itself
if (self.plain_text_password): if hasattr(self, "plain_text_password"):
return bcrypt.checkpw(self.plain_text_password.encode('utf-8'), return bcrypt.checkpw(self.plain_text_password.encode('utf-8'),
hashed_password.encode('utf-8')) hashed_password.encode('utf-8'))
return False return False
@ -423,7 +423,7 @@ class User(db.Model):
name='Administrator').first().id name='Administrator').first().id
self.password = self.get_hashed_password( self.password = self.get_hashed_password(
self.plain_text_password) if self.plain_text_password else '*' self.plain_text_password) if hasattr(self, "plain_text_password") else '*'
if self.password and self.password != '*': if self.password and self.password != '*':
self.password = self.password.decode("utf-8") self.password = self.password.decode("utf-8")
@ -459,7 +459,7 @@ class User(db.Model):
user.email = self.email user.email = self.email
# store new password hash (only if changed) # store new password hash (only if changed)
if self.plain_text_password: if hasattr(self, "plain_text_password"):
user.password = self.get_hashed_password( user.password = self.get_hashed_password(
self.plain_text_password).decode("utf-8") self.plain_text_password).decode("utf-8")
@ -478,7 +478,7 @@ class User(db.Model):
user.lastname = self.lastname if self.lastname else user.lastname user.lastname = self.lastname if self.lastname else user.lastname
user.password = self.get_hashed_password( user.password = self.get_hashed_password(
self.plain_text_password).decode( self.plain_text_password).decode(
"utf-8") if self.plain_text_password else user.password "utf-8") if hasattr(self, "plain_text_password") else user.password
if self.email: if self.email:
# Can not update to a new email that # Can not update to a new email that