Ejemplo n.º 1
0
def linkedin(request):
    """
    Actually setup/login an account relating to a linkedin user after the oauth 
    process is finished successfully
    """
    client = OAuthLinkedin(
        request,
        settings.LINKEDIN_CONSUMER_KEY,
        settings.LINKEDIN_CONSUMER_SECRET_KEY,
        settings.LINKEDIN_REQUEST_TOKEN_URL,
    )

    user_info = client.get_user_info()

    user = authenticate(uid=user_info["id"], soc_type=ST_LINKEDIN)

    if user is None:
        profile = SocialProfile(
            uid=user_info["id"],
            username=user_info["screen_name"],
            avatar=user_info["profile_image_url"],
            soc_type=ST_LINKEDIN,
        )
        user = User()
        request.session["socialregistration_profile"] = profile
        request.session["socialregistration_user"] = user
        request.session["next"] = _get_next(request)
        return HttpResponseRedirect(reverse("socialregistration_setup"))

    login(request, user)
    request.user.message_set.create(message=_("You have succesfully been logged in with your linkedin account"))

    return HttpResponseRedirect(_get_next(request))
Ejemplo n.º 2
0
def linkedin(request):
    """
    Actually setup/login an account relating to a linkedin user after the oauth
    process is finished successfully
    """
    client = OAuthLinkedin(
        request, settings.LINKEDIN_CONSUMER_KEY,
        settings.LINKEDIN_CONSUMER_SECRET_KEY,
        settings.LINKEDIN_REQUEST_TOKEN_URL,
    )

    # Perhaps the user typed in this url, or logged out from this page after
    # successfully linking accounts.
    if not client.get_access_token_or_none():
        return HttpResponseRedirect(_get_next(request))

    user_info = client.get_user_info()

    if request.user.is_authenticated():
        # Handling already logged in users connecting their accounts
        try:
            profile = LinkedinProfile.objects.get(linkedin_id=user_info['id'])
        except LinkedinProfile.DoesNotExist: # There can only be one profile!
            profile = LinkedinProfile.objects.create(user=request.user,
                                                     linkedin_id=user_info['id'],
                                                     username=user_info['screen_name'])

        return successful_account_link(request, profile)

    user = authenticate(linkedin_id=user_info['id'])

    if user is None:
        profile = LinkedinProfile(linkedin_id=user_info['id'],
                               username=user_info['screen_name'],
                               )
        user = User()
        request.session['socialregistration_profile'] = profile
        request.session['socialregistration_user'] = user
        request.session['next'] = _get_next(request)
        return HttpResponseRedirect(reverse('socialregistration_setup'))

    login(request, user)
    request.user.message_set.create(message=_('You have succesfully been logged in with your linkedin account'))

    return HttpResponseRedirect(_get_next(request))
Ejemplo n.º 3
0
def linkedin(request):
    """
    Actually setup/login an account relating to a linkedin user after the oauth 
    process is finished successfully
    """
    client = OAuthLinkedin(
        request, settings.LINKEDIN_CONSUMER_KEY,
        settings.LINKEDIN_CONSUMER_SECRET_KEY,
        settings.LINKEDIN_REQUEST_TOKEN_URL,
    )
    
    user_info = client.get_user_info()

    user = authenticate(uid=user_info['id'], soc_type = ST_LINKEDIN)

    if user is None:
        
        if user_info['screen_name'].index('pub'):
            user_info['screen_name'] = user_info['alt_screen_name'].lower()
        else:
            user_info['screen_name'] = user_info['screen_name'].split('/').pop()
        profile = SocialProfile(uid=user_info['id'],
                    username=user_info['screen_name'],
                    avatar=user_info['profile_image_url'],
                    soc_type = ST_LINKEDIN)
        user = User(first_name=user_info['first_name'],
                    last_name=user_info['last_name'])
        request.session['socialregistration_profile'] = profile
        request.session['socialregistration_user'] = user
        request.session['next'] = _get_next(request)
        return HttpResponseRedirect(reverse('socialregistration_setup'))

    login(request, user)
    request.user.message_set.create(message=_('You have succesfully been logged in with your linkedin account'))
    
    return HttpResponseRedirect(_get_next(request))