Example #1
0
def facebook_login(request, template='socialregistration/facebook.html',
    extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'):
    """
    View to handle the Facebook login
    """

    if request.facebook.uid is None:
        extra_context.update(dict(error=FB_ERROR))
        return render_to_response(template, extra_context,
            context_instance=RequestContext(request))

    user = authenticate(uid=request.facebook.uid)

    if user is None:
        if request.REQUEST.get("login", None):
            messages.add_message(request, messages.ERROR,
                ugettext("Your Facebook Account is not linked with a calology account.")
            )
            return HttpResponseRedirect(reverse('acct_login'))
        else:
            request.session['socialregistration_user'] = User()
            request.session['socialregistration_profile'] = FacebookProfile(uid=request.facebook.uid)
            request.session['socialregistration_client'] = request.facebook
            request.session['next'] = _get_next(request)
            return HttpResponseRedirect(reverse('socialregistration_setup'))

    if not user.is_active:
        return render_to_response(account_inactive_template, extra_context,
            context_instance=RequestContext(request))

    _login(request, user, FacebookProfile.objects.get(user = user), request.facebook)

    return HttpResponseRedirect(_get_next(request))
Example #2
0
def gfc_callback(request,
    template_name='gfc/callback.html', extra_context=None):
    context = {}
    context.update(extra_context or {})

    st = request.COOKIES.get('fcauth' + settings.GOOGLE_SITE_ID, False)
    if not st:
        context['error'] = 'nocookie'
        return shortcuts.render_to_response(template_name, context,
            context_instance=template.RequestContext(request))

    uid = st[st.find('~')+1:st.rfind('~')]

    user = auth.authenticate(uid=uid)

    container = gfc.my_opensocial_container(request)
    req = opensocial.FetchPersonRequest(uid, ['@all'])
    result = container.send_request(req)

    if user is None:
        user = User(
            first_name=result['displayName'],
            last_name=result['displayName']
        )
        profile = GfcProfile(uid=uid, url=result['urls'][0]['value'], user=user)
        request.session['socialregistration_user'] = user
        request.session['socialregistration_profile'] = profile
        return http.HttpResponseRedirect(urlresolvers.reverse('socialregistration_setup'))

    if not user.is_active:
        return shortcuts.render_to_response(account_inactive_template, context,
            context_instance=RequestContext(request))

    auth.login(request, user)

    return http.HttpResponseRedirect(_get_next(request))