Пример #1
0
def linkedin_authenticate(request):  
	
	liparser = LIProfile()
	# verify that oauth_verifier was returned
	if request.GET.getlist("oauth_verifier"):
		access_token, linkedin_user_info = liparser.authenticate(request.session['request_token'],request.GET['oauth_verifier'])
	# check for official LI error
	elif request.GET.getlist("oauth_problem"):
		# fetch error
		li_error = request.GET.getlist('oauth_problem')[0]
		# user refused access
		if li_error == 'user_refused':
			return HttpResponseRedirect('/account/refused')
	
	# check if user is already logged on
	request.session['linkedin_user_info'] = linkedin_user_info
	request.session['access_token'] = access_token

	if request.user.is_authenticated():
		# if logged in, link accounts and return
		print ("@ accounts/authenticate, request.user.is_authenticated = true")
		return HttpResponseRedirect('/account/link')

	request.session['_auth_user_backend'] = 'prosperime.accounts.backends.LinkedinBackend'
	
	user = authenticate(acct_id=linkedin_user_info['id'])
	# print user
	# print linkedin_user_info['id']
	if user is not None:
		

		auth_login(request,user)
		if 'next' in request.session:
			return HttpResponseRedirect(request.session['next'])
		else:
			return HttpResponseRedirect('/')
	else:
		# store information in a cookie
		request.session['linkedin_user_info'] = linkedin_user_info
		request.session['access_token'] = access_token

	# check to see if user is currently logged in
	if request.user.is_authenticated():
		# if loged in, link accounts and return
		return HttpResponseRedirect('/account/link')
	else:
		# if not logged in, ask to finish user registration process
		return HttpResponseRedirect('/account/finish')