Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add helper function to retireve user from credentials
Maciej Korycinski50626737bd65
diff --git a/saleor/graphql/account/mutations/jwt.py b/saleor/graphql/account/mutations/jwt.pyindex b986709a7d..914f9dc96a 100644--- a/saleor/graphql/account/mutations/jwt.py+++ b/saleor/graphql/account/mutations/jwt.py@@ -1,3 +1,5 @@+from typing import Optional+import grapheneimport jwtfrom django.core.exceptions import ValidationError@@ -69,10 +71,21 @@ class CreateToken(BaseMutation):)user = graphene.Field(User, description="A user instance.")+ @classmethod+ def _retrieve_user_from_credentials(cls, email, password) -> Optional[models.User]:+ user = models.User.objects.filter(email=email).first()+ if not user:+ return None+ if not user.is_active:+ return None+ if not user.check_password(password):+ return None+ return user+@classmethoddef get_user(cls, info, data):- user = models.User.objects.filter(email=data["email"]).first()- if not user or not user.is_active or not user.check_password(data["password"]):+ user = cls._retrieve_user_from_credentials(data["email"], data["password"])+ if not user:raise ValidationError({"email": ValidationError(