예제 #1
0
    def mutate(cls, context, info, **input):
        if cls.has_permission(User, info, input):
            try:
                with transaction.atomic():
                    edit_user_input = input.get('input', {})

                    user_input = edit_user_input
                    profile_input = edit_user_input.pop('profile', None)
                    auth_input = edit_user_input.pop(
                        'auth', None)  # TODO: implmenet auth

                    user = get_object(User, user_input.get('id'), User())
                    profile = UserProfile.objects.get_or_create(user=user)

                    import pdb
                    pdb.set_trace()

                    if user:
                        password = edit_user_input.pop('password')
                        if password: user_instance.set_password(password)

                        user = update_or_create(user, user_input)
                    if profile_instance:
                        profile = update_or_create(profile, profile_input)

                    return UserPayload(user=user)
            except ValidationError as e:
                return UserPayload(errors=get_field_errors(e))
            except DatabaseError as e:
                return UserPayload(errors=get_field_errors(e))
예제 #2
0
    def mutate(cls, context, info, **input):
        try:
            authenticate_user_input = input.get('input', {})
            provider = authenticate_user_input.get('provider')
            code = authenticate_user_input.get('code')
            request = info.context

            request.auth_data = authenticate_user_input

            decorate_request(request, provider)

            manual_redirect_uri = request.auth_data.pop('redirect_uri', None)

            request.backend.redirect_uri = settings.REST_SOCIAL_OAUTH_ABSOLUTE_REDIRECT_URI
            request.backend.REDIRECT_STATE = False
            request.backend.STATE_PARAMETER = False

            user = request.backend.auth_complete()

            # NOTE: will raise exception unless is_active == True; always false initially
            # if user is None or not user.is_active:
            #     raise ValidationError('No active account found with given credentials.')
            # else:
            #     login(request, user)
            if user is not None: login(request, user)

            return AuthPayload(user=user)
        except ValidationError as e:
            return AuthPayload(errors=get_field_errors(e))
예제 #3
0
    def mutate(cls, context, info, **input):
        if cls.has_permission(context, info, input):
            try:
                register_user_input = input.get('input', {})

                user = User.objects.create_user(**register_user_input)
                return UserPayload(user=user)
            except ValidationError as e:
                return UserPayload(errors=get_field_errors(e))
예제 #4
0
    def mutate(cls, context, info, **input):
        login_user_input = input.get('input', {})
        usernameOrEmail = login_user_input.get('usernameOrEmail')
        password = login_user_input.get('password')

        try:
            user = User.objects.get_or_none(Q(username__iexact=usernameOrEmail) | Q(email__iexact=usernameOrEmail))

            if user is None:
                raise ValidationError({'usernameOrEmail': 'Please enter a valid Username or Email.'})

            # TODO: generic error not configured
            if not user.is_active:
                raise PermissionError('No active account found with given credentials')

            if user.check_password(password):
                login(info.context, user, backend='django.contrib.auth.backends.ModelBackend')
                return AuthPayload(user=user)
            else:
                raise ValidationError({'password': '******'})

        except ValidationError as e:
            return AuthPayload(errors=get_field_errors(e))