Esempio n. 1
0
def oauth_register(request, backend):
    '''
    注册和登录时都不应该是登录后的状态
    '''
    context = {'next': request.session.get('next', '')}
    if request.user.is_authenticated():
        return render_to_response('xuetangx/oauth/oauth_login_success.html', context)
    return auth(request, backend)
Esempio n. 2
0
def oauth_register(request, backend):
    """
    注册和登录时都不应该是登录后的状态
    """
    context = {"next": request.session.get("next", "")}
    if request.user.is_authenticated():
        return render_to_response("oauth/oauth_login_success.html", context)
    return auth(request, backend)
Esempio n. 3
0
def oauth_register(request, backend):
    '''
    注册和登录时都不应该是登录后的状态
    '''
    context = {'next': request.session.get('next', '')}
    if request.user.is_authenticated():
        return render_to_response('xuetangx/oauth/oauth_login_success.html',
                                  context)
    return auth(request, backend)
Esempio n. 4
0
def social_auth_begin(request, backend):
    """ wrap social-auth function """
    try:
        if request.user.is_authenticated():
            messages.error(request, 'You are already signed in.')
            return redirect('profile')
        return auth(request, backend)
    except Exception as e:
        messages.error(request, e.message or e.msg)
        return redirect('signin')
Esempio n. 5
0
def signin_social(request, backend):
    real_ip = request.META.get('REMOTE_ADDR')
    if real_ip and BlacklistedIP.objects.filter(ip=real_ip).exists():
        return HttpResponseRedirect(reverse('profile:public:signup'))

    request.session.set_test_cookie()
    # Set redirect to previous URL unless it's already set in session.
    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME,
                                      request.META.get('HTTP_REFERER', ''))
    if redirect_to and not request.session.get(REDIRECT_FIELD_NAME):
        request.session[REDIRECT_FIELD_NAME] = redirect_to
        request.session['newuser-next'] = redirect_to

    from social_auth import views as sa_views
    return sa_views.auth(request, backend)
Esempio n. 6
0
def steam_login(request):
    """
        This view is a wrapper to social_auths auth
        It is required, because social_auth just throws ValueError and gets user to 500 error
        after every unexpected action. This view handles exceptions in human friendly way.
        See https://convore.com/django-social-auth/best-way-to-handle-exceptions/
    """
    from social_auth.views import auth

    try:
        # if everything is ok, then original view gets returned, no problem
        return auth(request, 'steam')
    except ValueError, error:
        # in case of errors, let's show a special page that will explain what happened
        return HttpResponseRedirect(reverse('steam-is-down'))
Esempio n. 7
0
def signin_social(request, backend):
    real_ip = request.META.get('REMOTE_ADDR')
    if real_ip and BlacklistedIP.objects.filter(ip=real_ip).exists():
        return HttpResponseRedirect(reverse('profile:public:signup'))

    request.session.set_test_cookie()
    # Set redirect to previous URL unless it's already set in session.
    redirect_to = request.REQUEST.get(
        REDIRECT_FIELD_NAME, request.META.get('HTTP_REFERER', ''))
    if redirect_to and not request.session.get(REDIRECT_FIELD_NAME):
        request.session[REDIRECT_FIELD_NAME] = redirect_to
        request.session['newuser-next'] = redirect_to

    from social_auth import views as sa_views
    return sa_views.auth(request, backend)
Esempio n. 8
0
def social_auth_login(request, backend):
    """
        This view is a wrapper to social_auths auth
        It is required, because social_auth just throws ValueError and gets user to 500 error
        after every unexpected action. This view handles exceptions in human friendly way.
        See https://convore.com/django-social-auth/best-way-to-handle-exceptions/
    """
    from social_auth.views import auth

    try:
        # if everything is ok, then original view gets returned, no problem
        return auth(request, backend)
    except ValueError, error:
        # in case of errors, let's show a special page that will explain what happened
        return render_to_response('users/login_error.html',
            locals(),
            context_instance=RequestContext(request))
Esempio n. 9
0
def social_auth_login(request, backend):
    """
        This view is a wrapper to social_auths auth
        It is required, because social_auth just throws ValueError and gets user to 500 error
        after every unexpected action. This view handles exceptions in human friendly way.
        See https://convore.com/django-social-auth/best-way-to-handle-exceptions/
    """
    from social_auth.views import auth

    try:
        # if everything is ok, then original view gets returned, no problem
        return auth(request, backend)
    except ValueError as error:
        # in case of errors, let's show a special page that will explain what happened
        return render_to_response('users/login_error.html',
                                  locals(),
                                  context_instance=RequestContext(request))
Esempio n. 10
0
def login_pinterest(request):
    if request.GET.get('next'):
        request.session['pinterest_next'] = request.GET.get('next')

    from social_auth.views import auth
    return auth(request, 'pinterest')
Esempio n. 11
0
def oauth_bind(request, backend):
    """
    绑定时需要时登录状态
    """
    return auth(request, backend)
Esempio n. 12
0
def login_facebook(request):
    if request.GET.get('next'):
        request.session['facebook_next'] = request.GET.get('next')

    from social_auth.views import auth
    return auth(request, 'facebook')
Esempio n. 13
0
def oauth_bind(request, backend):
    '''
    绑定时需要时登录状态
    '''
    return auth(request, backend)
Esempio n. 14
0
def auth_register(request, backend):
    request.session['new_username'] = request.POST['username'] or SOCIAL_AUTH_DEFAULT_USERNAME
    return auth(request, backend)
Esempio n. 15
0
def login_twitter(request):
    if request.GET.get('next'):
        request.session['twitter_next'] = request.GET.get('next')

    from social_auth.views import auth
    return auth(request, 'twitter')
Esempio n. 16
0
def login_facebook(request):
    if request.GET.get('next'):
        request.session['facebook_next'] = request.GET.get('next')

    from social_auth.views import auth
    return auth(request, 'facebook')
Esempio n. 17
0
def oauth_bind(request, backend):
    '''
    绑定时需要时登录状态
    '''
    return auth(request, backend)
Esempio n. 18
0
def login_instagram(request):
    if request.GET.get('next'):
        request.session['instagram_next'] = request.GET.get('next')

    from social_auth.views import auth
    return auth(request, 'instagram')