47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import graphene
|
|
from django.conf import settings
|
|
from django.contrib.auth import authenticate, login
|
|
from graphene import relay
|
|
from users.models import User
|
|
# from users.user_signup_login_handler import handle_user_and_verify_products, UNKNOWN_ERROR, EMAIL_NOT_VERIFIED
|
|
|
|
|
|
class BetaLogin(relay.ClientIDMutation):
|
|
class Input:
|
|
username_input = graphene.String()
|
|
password_input = graphene.String()
|
|
|
|
success = graphene.Boolean()
|
|
message = graphene.String()
|
|
|
|
@classmethod
|
|
def mutate_and_get_payload(cls, root, info, **kwargs):
|
|
if settings.ALLOW_BETA_LOGIN:
|
|
password = kwargs.get('password_input')
|
|
username = kwargs.get('username_input')
|
|
|
|
if username:
|
|
username = username.lower().strip()
|
|
|
|
# Login with email
|
|
if '@' in username:
|
|
user = User.objects.get(email=username)
|
|
if user:
|
|
username = user.username
|
|
|
|
user = authenticate(username=username, password=password)
|
|
if user is None:
|
|
raise Exception('invalid_credentials')
|
|
login(info.context, user)
|
|
|
|
return cls(success=True, message='')
|
|
|
|
raise Exception('not_implemented')
|
|
|
|
|
|
class UserMutations:
|
|
beta_login = BetaLogin.Field()
|
|
|
|
|
|
|