예제 #1
0
def create_user(request, ulogin_response):
    """
    Creates user
    """
    # Custom behaviour
    if s.CREATE_USER_CALLBACK is not None:
        callback = import_by_path(s.CREATE_USER_CALLBACK)

        if callable(callback):
            return callback(request=request, ulogin_response=ulogin_response)

        raise ImproperlyConfigured(
            "The ULOGIN_CREATE_USER_CALLBACK isn't a callable")

    # Default behavior
    User = get_user_model()

    return User.objects.create_user(
        username=uuid.uuid4().hex[:30],
        password=get_random_string(10, '0123456789abcdefghijklmnopqrstuvwxyz'),
        email='')
예제 #2
0
def create_user(request, ulogin_response):
    """
    This function creates a new "user" instance based on response
    we got from ULOGIN.

    You can invent your own behavior and make django-ulogin to use
    it by specifing it in your Django's project settings module:


    # settings.py
    # ... a bunch of other settings
    ULOGIN_CREATE_USER_CALLBACK = 'my_app.utils.my_own_ulogin_create_user'

    Note, the function should accept two arguments named "request"
    and "ulogin_response"


    """
    # Custom behaviour
    if s.CREATE_USER_CALLBACK is not None:
        callback = import_by_path(s.CREATE_USER_CALLBACK)

        if callable(callback):
            return callback(request=request,
                            ulogin_response=ulogin_response)

        raise ImproperlyConfigured(
            "The ULOGIN_CREATE_USER_CALLBACK isn't a callable"
        )

    # Default behavior
    User = get_user_model()

    return User.objects.create_user(
        username=uuid.uuid4().hex[:30],
        password=get_random_string(10, '0123456789abcdefghijklmnopqrstuvwxyz'),
        email=''
    )
예제 #3
0
def create_user(request, ulogin_response):
    """
    Creates user
    """
    # Custom behaviour
    if s.CREATE_USER_CALLBACK is not None:
        callback = import_by_path(s.CREATE_USER_CALLBACK)

        if callable(callback):
            return callback(request=request,
                            ulogin_response=ulogin_response)

        raise ImproperlyConfigured(
            "The ULOGIN_CREATE_USER_CALLBACK isn't a callable"
        )

    # Default behavior
    User = get_user_model()

    return User.objects.create_user(
        username=uuid.uuid4().hex[:30],
        password=get_random_string(10, '0123456789abcdefghijklmnopqrstuvwxyz'),
        email=''
    )
예제 #4
0
from django_ulogin.utils import import_by_path
import requests
import json
import logging
import sys


logger = logging.getLogger('django_ulogin.views')


def get_user(request):
    return getattr(request, settings.REQUEST_USER)


if settings.LOGIN_CALLBACK:
    login = import_by_path(settings.LOGIN_CALLBACK)
else:
    from django.contrib.auth import login


class CsrfExemptMixin(object):
    """
    A mixin that provides a way to exempt view class out of CSRF validation
    """
    @method_decorator(csrf_exempt)
    def dispatch(self, request, *args, **kwargs):
        return super(CsrfExemptMixin, self).dispatch(request, *args, **kwargs)


class LoginRequiredMixin(object):
    """
예제 #5
0
from django_ulogin.utils import import_by_path
from django.contrib.auth import logout
import requests
import json
import logging
import sys

logger = logging.getLogger('django_ulogin.views')


def get_user(request):
    return getattr(request, settings.REQUEST_USER)


if settings.LOGIN_CALLBACK:
    login = import_by_path(settings.LOGIN_CALLBACK)
else:
    from django.contrib.auth import login


class CsrfExemptMixin(object):
    """
    A mixin that provides a way to exempt view class out of CSRF validation
    """
    @method_decorator(csrf_exempt)
    def dispatch(self, request, *args, **kwargs):
        return super(CsrfExemptMixin, self).dispatch(request, *args, **kwargs)


class LoginRequiredMixin(object):
    """