Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimRG authored Apr 23, 2024
1 parent 4fc726b commit 2db9ab3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions moonraker/components/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ async def _handle_info_request(self, web_request: WebRequest) -> Dict[str, Any]:

async def _handle_getTOTP_request(self, web_request: WebRequest) -> Dict[str, Any]:
username: str = web_request.get_str('username')
(secret, is_activated) = self.totp_secrets.get(username)
(secret, is_activated) = self.totp_secrets.get(username, (None, None))
if not secret:
raise ValueError("User does not have a TOTP key set up.")
uri = pyotp.TOTP(secret).provisioning_uri(username, issuer_name="Moonraker")
Expand Down Expand Up @@ -468,7 +468,7 @@ async def _handle_password_reset(self,
self._sync_user(username)
if (self.enable_totp):
self.totp_secrets[username] = (pyotp.random_base32(), False)
self.totp_secret_db.sync()
self.totp_secret_db.sync(self.totp_secrets)
return {
'username': username,
'action': "user_password_reset"
Expand Down Expand Up @@ -522,7 +522,7 @@ async def _login_jwt_user(
create = False
if (self.enable_totp):
self.totp_secrets[username] = (pyotp.random_base32(), False)
self.totp_secret_db.sync()
self.totp_secret_db.sync(self.totp_secrets)
else:
if username not in self.users:
raise self.server.error(f"Unregistered User: {username}")
Expand All @@ -540,14 +540,14 @@ async def _login_jwt_user(
if hashed_pass != user_info['password']:
raise self.server.error("Invalid Password")
if (self.enable_totp):
(secret, is_activated) = self.totp_secrets.get(username)
(secret, is_activated) = self.totp_secrets.get(username, (None, None))
if not secret:
raise self.server.error("User does not have a secret key set up.")
if (pyotp.TOTP(secret).verify(totp_code) == False):
raise self.server.error("Invalid TOTP code")
if (is_activated == False):
self.totp_secrets[username] = (secret, True)
self.totp_secret_db.sync()
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:
private_key = Signer()
Expand Down

0 comments on commit 2db9ab3

Please sign in to comment.