Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Customer register mutation

Pacu274149a470621
diff --git a/saleor/graphql/account/mutations.py b/saleor/graphql/account/mutations.py
index bb267d5fa5..99c97dbfce 100644
--- a/saleor/graphql/account/mutations.py
+++ b/saleor/graphql/account/mutations.py
@@ -34,6 +34,29 @@ BILLING_ADDRESS_FIELD = 'default_billing_address'
SHIPPING_ADDRESS_FIELD = 'default_shipping_address'
+class CustomerRegisterInput(graphene.InputObjectType):
+ email = graphene.String(
+ description='The unique email address of the user.', required=True)
+ password = graphene.String(description='Password', required=True)
+
+
+class CustomerRegister(ModelMutation):
+ class Arguments:
+ input = CustomerRegisterInput(
+ description='Fields required to create a user.', required=True)
+
+ class Meta:
+ description = 'Register a new user.'
+ exclude = ['password']
+ model = models.User
+
+ @classmethod
+ def save(cls, info, user, cleaned_input):
+ password = cleaned_input['password']
+ user.set_password(password)
+ user.save()
+
+
class UserInput(graphene.InputObjectType):
email = graphene.String(
description='The unique email address of the user.')
@@ -111,7 +134,6 @@ class CustomerCreate(ModelMutation):
billing_address = cls.construct_address(
BILLING_ADDRESS_FIELD, billing_address_input, instance, errors)
cleaned_input[BILLING_ADDRESS_FIELD] = billing_address
-
return cleaned_input
@classmethod
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.py
index e3e1b69a0d..013424481f 100644
--- a/saleor/graphql/api.py
+++ b/saleor/graphql/api.py
@@ -4,8 +4,9 @@ from graphene_django.filter import DjangoFilterConnectionField
from graphql_jwt.decorators import login_required, permission_required
from .account.mutations import (
- CustomerCreate, CustomerUpdate, PasswordReset, SetPassword, StaffCreate,
- StaffDelete, StaffUpdate, AddressCreate, AddressUpdate, AddressDelete)
+ CustomerCreate, CustomerUpdate, CustomerRegister, PasswordReset,
+ SetPassword, StaffCreate, StaffDelete, StaffUpdate, AddressCreate,
+ AddressUpdate, AddressDelete)
from .account.types import AddressValidationData, AddressValidationInput, User
from .account.resolvers import (
resolve_address_validator, resolve_customers, resolve_staff_users)
@@ -287,6 +288,7 @@ class Mutations(graphene.ObjectType):
customer_create = CustomerCreate.Field()
customer_update = CustomerUpdate.Field()
+ customer_register = CustomerRegister.Field()
staff_create = StaffCreate.Field()
staff_update = StaffUpdate.Field()