skillbox/server/users/mutations_public.py

37 lines
1020 B
Python

import graphene
from django.conf import settings
from django.contrib.auth import authenticate, login
from graphene import relay
# 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')
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()