diff --git a/passbook/admin/templatetags/admin_reflection.py b/passbook/admin/templatetags/admin_reflection.py index 311b259e6..05c45fc2f 100644 --- a/passbook/admin/templatetags/admin_reflection.py +++ b/passbook/admin/templatetags/admin_reflection.py @@ -18,7 +18,7 @@ def get_links(model_instance): links = {} if not isinstance(model_instance, Model): - LOGGER.warning("Model %s is not instance of Model", model_instance) + LOGGER.warning("Model is not instance of Model", model_instance=model_instance) return links try: @@ -43,7 +43,7 @@ def get_htmls(context, model_instance): htmls = [] if not isinstance(model_instance, Model): - LOGGER.warning("Model %s is not instance of Model", model_instance) + LOGGER.warning("Model is not instance of Model", model_instance=model_instance) return htmls try: diff --git a/passbook/core/forms/authentication.py b/passbook/core/forms/authentication.py index 38c29b36d..19fa74cbf 100644 --- a/passbook/core/forms/authentication.py +++ b/passbook/core/forms/authentication.py @@ -70,7 +70,7 @@ class SignUpForm(forms.Form): """Check if username is used already""" username = self.cleaned_data.get("username") if User.objects.filter(username=username).exists(): - LOGGER.warning("Username %s already exists", username) + LOGGER.warning("username already exists", username=username) raise ValidationError(_("Username already exists")) return username @@ -79,7 +79,7 @@ class SignUpForm(forms.Form): email = self.cleaned_data.get("email") # Check if user exists already, error early if User.objects.filter(email=email).exists(): - LOGGER.debug("email %s exists in django", email) + LOGGER.debug("email already exists", email=email) raise ValidationError(_("Email already exists")) return email diff --git a/passbook/core/views/authentication.py b/passbook/core/views/authentication.py index 49dad3742..6ba55171f 100644 --- a/passbook/core/views/authentication.py +++ b/passbook/core/views/authentication.py @@ -156,26 +156,9 @@ class SignUpView(UserPassesTestMixin, FormView): for error in exc.messages: errors.append(error) return self.form_invalid(form) - # needs_confirmation = True - # if self._invitation and not self._invitation.needs_confirmation: - # needs_confirmation = False - # if needs_confirmation: - # nonce = Nonce.objects.create(user=self._user) - # LOGGER.debug(str(nonce.uuid)) - # # Send email to user - # send_email.delay(self._user.email, _('Confirm your account.'), - # 'email/account_confirm.html', { - # 'url': self.request.build_absolute_uri( - # reverse('passbook_core:auth-sign-up-confirm', kwargs={ - # 'nonce': nonce.uuid - # }) - # ) - # }) - # self._user.is_active = False - # self._user.save() self.consume_invitation() messages.success(self.request, _("Successfully signed up!")) - LOGGER.debug("Successfully signed up %s", form.cleaned_data.get("email")) + LOGGER.debug("Successfully signed up", email=form.cleaned_data.get("email")) return redirect(reverse("passbook_core:auth-login")) def consume_invitation(self): diff --git a/passbook/policies/hibp/models.py b/passbook/policies/hibp/models.py index 56b4cdbe8..5ff10c838 100644 --- a/passbook/policies/hibp/models.py +++ b/passbook/policies/hibp/models.py @@ -35,7 +35,7 @@ class HaveIBeenPwendPolicy(Policy): full_hash, count = line.split(":") if pw_hash[5:] == full_hash.lower(): final_count = int(count) - LOGGER.debug("Got count %d for hash %s", final_count, pw_hash[:5]) + LOGGER.debug("got hibp result", count=final_count, hash=pw_hash[:5]) if final_count > self.allowed_count: message = _( "Password exists on %(count)d online lists." % {"count": final_count} diff --git a/passbook/sources/oauth/clients.py b/passbook/sources/oauth/clients.py index da247bb46..ff9ed76a1 100644 --- a/passbook/sources/oauth/clients.py +++ b/passbook/sources/oauth/clients.py @@ -18,13 +18,13 @@ LOGGER = get_logger() class BaseOAuthClient: """Base OAuth Client""" - _session = None + _session: Session = None def __init__(self, source, token=""): # nosec self.source = source self.token = token self._session = Session() - self._session.headers.update({"User-Agent": "web:passbook:%s" % __version__}) + self._session.headers.update({"User-Agent": "passbook %s" % __version__}) def get_access_token(self, request, callback=None): "Fetch access token from callback request." @@ -36,7 +36,7 @@ class BaseOAuthClient: response = self.request("get", self.source.profile_url, token=raw_token) response.raise_for_status() except RequestException as exc: - LOGGER.warning("Unable to fetch user profile: %s", exc) + LOGGER.warning("Unable to fetch user profile", exc=exc) return None else: return response.json() or response.text @@ -51,7 +51,7 @@ class BaseOAuthClient: additional = parameters or {} args.update(additional) params = urlencode(args) - LOGGER.info("Redirect args: %s", args) + LOGGER.info("redirect args", **args) return "{0}?{1}".format(self.source.authorization_url, params) def parse_raw_token(self, raw_token): @@ -91,7 +91,7 @@ class OAuthClient(BaseOAuthClient): ) response.raise_for_status() except RequestException as exc: - LOGGER.warning("Unable to fetch access token: %s", exc) + LOGGER.warning("Unable to fetch access token", exc=exc) return None else: return response.text @@ -106,7 +106,7 @@ class OAuthClient(BaseOAuthClient): ) response.raise_for_status() except RequestException as exc: - LOGGER.warning("Unable to fetch request token: %s", exc) + LOGGER.warning("Unable to fetch request token", exc=exc) return None else: return response.text @@ -195,7 +195,7 @@ class OAuth2Client(BaseOAuthClient): ) response.raise_for_status() except RequestException as exc: - LOGGER.warning("Unable to fetch access token: %s", exc) + LOGGER.warning("Unable to fetch access token", exc=exc) return None else: return response.text diff --git a/passbook/sources/oauth/types/azure_ad.py b/passbook/sources/oauth/types/azure_ad.py index 1af72f40e..c1d480164 100644 --- a/passbook/sources/oauth/types/azure_ad.py +++ b/passbook/sources/oauth/types/azure_ad.py @@ -24,7 +24,7 @@ class AzureADOAuth2Client(OAuth2Client): response = self.request("get", self.source.profile_url, headers=headers) response.raise_for_status() except RequestException as exc: - LOGGER.warning("Unable to fetch user profile: %s", exc) + LOGGER.warning("Unable to fetch user profile", exc=exc) return None else: return response.json() or response.text diff --git a/passbook/sources/oauth/types/discord.py b/passbook/sources/oauth/types/discord.py index d775824cf..a7b26db46 100644 --- a/passbook/sources/oauth/types/discord.py +++ b/passbook/sources/oauth/types/discord.py @@ -40,7 +40,7 @@ class DiscordOAuth2Client(OAuth2Client): ) response.raise_for_status() except RequestException as exc: - LOGGER.warning("Unable to fetch user profile: %s", exc) + LOGGER.warning("Unable to fetch user profile", exc=exc) return None else: return response.json() or response.text diff --git a/passbook/sources/oauth/types/reddit.py b/passbook/sources/oauth/types/reddit.py index 830f6c3b9..8c9271883 100644 --- a/passbook/sources/oauth/types/reddit.py +++ b/passbook/sources/oauth/types/reddit.py @@ -49,7 +49,7 @@ class RedditOAuth2Client(OAuth2Client): ) response.raise_for_status() except RequestException as exc: - LOGGER.warning("Unable to fetch user profile: %s", exc) + LOGGER.warning("Unable to fetch user profile", exc=exc) return None else: return response.json() or response.text diff --git a/passbook/sources/oauth/types/twitter.py b/passbook/sources/oauth/types/twitter.py index 60d74a64c..a5aaa2801 100644 --- a/passbook/sources/oauth/types/twitter.py +++ b/passbook/sources/oauth/types/twitter.py @@ -22,7 +22,7 @@ class TwitterOAuthClient(OAuthClient): ) response.raise_for_status() except RequestException as exc: - LOGGER.warning("Unable to fetch user profile: %s", exc) + LOGGER.warning("Unable to fetch user profile", exc=exc) return None else: return response.json() or response.text diff --git a/passbook/sources/oauth/views/core.py b/passbook/sources/oauth/views/core.py index 73090555b..fded716a8 100644 --- a/passbook/sources/oauth/views/core.py +++ b/passbook/sources/oauth/views/core.py @@ -124,9 +124,9 @@ class OAuthCallback(OAuthClientMixin, View): source=self.source, identifier=identifier, request=request ) if user is None: - LOGGER.debug("Handling new user") + LOGGER.debug("Handling new user", source=self.source) return self.handle_new_user(self.source, connection, info) - LOGGER.debug("Handling existing user") + LOGGER.debug("Handling existing user", source=self.source) return self.handle_existing_user(self.source, user, connection, info) # pylint: disable=unused-argument @@ -179,7 +179,7 @@ class OAuthCallback(OAuthClientMixin, View): def handle_login_failure(self, source, reason): "Message user and redirect on error." - LOGGER.warning("Authentication Failure: %s", reason) + LOGGER.warning("Authentication Failure", reason=reason) messages.error(self.request, _("Authentication Failed.")) return redirect(self.get_error_redirect(source, reason))