Skip to content

Commit

Permalink
Syntax cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimRG authored Apr 23, 2024
1 parent 2747da5 commit 09d0337
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions moonraker/components/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,10 @@ async def _handle_password_reset(self,
self.users[username]['password'] = new_hashed_pass
self._sync_user(username)
if (self.enable_totp):
self.totp_secrets[username] = {'secret': pyotp.random_base32(), 'is_activated': False}
self.totp_secrets[username] = {
'secret': pyotp.random_base32(),

Check warning on line 474 in moonraker/components/authorization.py

View workflow job for this annotation

GitHub Actions / lint-python-code

trailing whitespace
'is_activated': False
}
self.totp_secret_db.sync(self.totp_secrets)
return {
'username': username,
Expand Down Expand Up @@ -524,7 +527,10 @@ async def _login_jwt_user(
action = "user_logged_in"
create = False
if (self.enable_totp):
self.totp_secrets[username] = {'secret': pyotp.random_base32(), 'is_activated': False}
self.totp_secrets[username] = {
'secret': pyotp.random_base32(),
'is_activated': False
}
self.totp_secret_db.sync(self.totp_secrets)
else:
if username not in self.users:
Expand All @@ -543,15 +549,21 @@ async def _login_jwt_user(
if hashed_pass != user_info['password']:
raise self.server.error("Invalid Password")
if (self.enable_totp):
user_data_totp = self.totp_secrets.get(username, {'secret': '', 'is_activated': True})
user_data_totp = self.totp_secrets.get(username, {
'secret': '',
'is_activated': True
})
secret = user_data_totp['secret']
is_activated = user_data_totp['is_activated']
if secret == '':
raise self.server.error("User does not have a secret key set up.")
if pyotp.TOTP(secret).verify(totp_code) is False:
raise self.server.error("Invalid TOTP code")
if is_activated is False:
self.totp_secrets[username] = {'secret': secret, 'is_activated': True}
self.totp_secrets[username] = {
'secret': secret,
'is_activated': True
}
self.totp_secret_db.sync(self.totp_secrets)
jwt_secret_hex: Optional[str] = user_info.get('jwt_secret', None)
if jwt_secret_hex is None:
Expand Down

0 comments on commit 09d0337

Please sign in to comment.