當前位置: 首頁>>代碼示例>>Python>>正文


Python Account.access_token方法代碼示例

本文整理匯總了Python中accounts.models.Account.access_token方法的典型用法代碼示例。如果您正苦於以下問題:Python Account.access_token方法的具體用法?Python Account.access_token怎麽用?Python Account.access_token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在accounts.models.Account的用法示例。


在下文中一共展示了Account.access_token方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: finish_login

# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import access_token [as 別名]
def finish_login(request):
	# TODO: redirect if not not authenticated through LinkedIn already
	
	# if request.POST:
	if request.method == "POST":
		# form submitted
		form = FinishAuthForm(request.POST)
		if form.is_valid():
			from accounts.models import Pref
			import accounts.emaillib as emaillib
			# grab cleaned values from form
			username = form.cleaned_data['username']
			email = form.cleaned_data['email']
			# location = form.cleaned_data['location']
			# headline = form.cleaned_data['headline']
			password = form.cleaned_data['password']

			# fetch LI data
			linkedin_user_info = request.session['linkedin_user_info']
			access_token = request.session['access_token']

			# check to see if dormant user already exists
			try: 
				print '@ accounts.finish -- checking for dormant user'
				user = User.objects.get(profile__status="dormant",account__uniq_id=linkedin_user_info['id'])
				existing = True
				user.profile.status = "active"
				user.profile.save()
				user.set_password(password)
				user.username = username
				user.is_active = True
				user.save()
				print "@ accounts.finish -- user already exists"
			except:
				print '@ accounts.finish -- new user'
				# create user
				user = User.objects.create_user(username,email,password)
				user.save()
				
				existing = False
				user.profile.status = "active"
				user.profile.save()
				print "@ accounts.finish -- created new user"
			# send welcome email
			welcome = emaillib.WelcomeEmail(user)
			welcome.send_email()
			# add email prefs
			if form.cleaned_data['notification']:
				pref = Pref(user=user,name="notification",value=1)
				pref.save()
			else:
				pref = Pref(user=user,name="notification",value=0)
				pref.save()
			# make sure using right backend
			request.session['_auth_user_backend'] = 'django.contrib.auth.backends.ModelBackend'
			# log user in
			user = authenticate(username=username,password=password)
			
			# make sure authentication worked
			if user is not None:
				print 'in to auth login'
				auth_login(request,user)
			else:
				# try logging in now with LinkedIn
				request.session['_auth_user_backend'] = 'prosperime.accounts.backends.LinkedinBackend'
				try:
					user = authenticate(acct_id=linkedin_user_info['id'])
					if user is not None:
						auth_login(request,user)	
				except:
					# somehow authentication failed, redirect with error message
					messages.error(request, 'Something went wrong. Please try again.')
					return render_to_response('accounts/finish_login.html',{'form':form},context_instance=RequestContext(request))



			# update user profile
			# user.profile.full_name = request.session['linkedin_user_info']['firstName'] + " " + request.session['linkedin_user_info']['lastName']		
			user.profile.first_name = linkedin_user_info['firstName']
			user.profile.last_name = linkedin_user_info['lastName']
			# user.profile.location = location
			# check to see if user provided a headline
			# if headline:
			# 	user.profile.headline = headline
			# else:
			user.profile.headline = linkedin_user_info['headline']
			user.profile.save()

			# add pofile picture
			# if 'pictureUrl' in linkedin_user_info:
			# 	# _add_profile_pic(user,linkedin_user_info['pictureUrl'])
			# 	li_parser = LIProfile()
			# 	li_parser.add_profile_pic(user,linkedin_user_info['pictureUrl'])

			if 'pictureUrls' in linkedin_user_info:
				li_parser = LIProfile()
				li_parser.add_profile_pic(user,linkedin_user_info['pictureUrls']['values'][0])


			if existing:
#.........這裏部分代碼省略.........
開發者ID:tchaymore,項目名稱:prosperime,代碼行數:103,代碼來源:views.py

示例2: finish_link

# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import access_token [as 別名]
def finish_link(request):
	# get info for creating an account
	linkedin_user_info = request.session['linkedin_user_info']
	access_token = request.session['access_token']

	# delete LI info from session
	del request.session['linkedin_user_info']
	del request.session['access_token']

	# add profile if it doesn't exit (for superadmin after reset)
	# try:
	# 	request.user.profile
	# except:
	# 	request.user.profile = Profile()
	# 	request.user.profile.first_name = linkedin_user_info['firstName']
	# 	request.user.profile.last_name = linkedin_user_info['lastName']
	# 	request.user.profile.headline = linkedin_user_info['headline']
	# 	request.user.profile.save()

	try:
		request.user.profile
	except:
		request.user.profile = Profile()

	request.user.profile.first_name = linkedin_user_info['firstName']
	request.user.profile.last_name = linkedin_user_info['lastName']
	request.user.profile.headline = linkedin_user_info['headline']
	request.user.profile.save()

	# create LinkedIn account
	acct = Account()
	acct.owner = request.user
	acct.access_token = access_token['oauth_token']
	acct.token_secret = access_token['oauth_token_secret']
	acct.service = 'linkedin'
	acct.expires_on = datetime.now() + timedelta(seconds=int(access_token['oauth_authorization_expires_in']))
	acct.uniq_id = linkedin_user_info['id']
	acct.save()

	# add pofile picture
	if 'pictureUrl' in linkedin_user_info:
		li_parser = LIProfile()
		li_parser.add_profile_pic(request.user,linkedin_user_info['pictureUrl'])
		# _add_profile_pic(request.user,linkedin_user_info['pictureUrl'])

	# finish processing LI profile
	profile_task = process_li_profile.delay(request.user.id,acct.id)

	# start processing connections
	connections_task = process_li_connections.delay(request.user.id,acct.id)

	# save task ids to session
	request.session['tasks'] = {
		'profile': profile_task.id,
		'connections': connections_task.id
	}

	messages.success(request, 'Your LinkedIn account has been successfully linked.')

	if 'next' not in request.session:
		return HttpResponseRedirect('/majors/')
	else:
		return HttpResponseRedirect(request.session['next'])
開發者ID:tchaymore,項目名稱:prosperime,代碼行數:65,代碼來源:views.py

示例3: finish_registration_old

# 需要導入模塊: from accounts.models import Account [as 別名]
# 或者: from accounts.models.Account import access_token [as 別名]
def finish_registration_old(request):

	import accounts.emaillib as emaillib
	# get linkedin info from session
	linkedin_user_info = request.session['linkedin_user_info']
	access_token = request.session['access_token']

	# check for dormant user
	try: 
		user = User.objects.get(profile__status="dormant",account__uniq_id=linkedin_user_info['id'])
		user.email=linkedin_user_info['emailAddress']
		logger.info("activated dormant user "+linkedin_user_info['emailAddress'])
		existing = True
	except:
		# create user
		user = User.objects.create_user(linkedin_user_info['emailAddress'],linkedin_user_info['emailAddress'])
		logger.info("created new user "+linkedin_user_info['emailAddress'])
		user.save()
		existing = False
		
	# set user properties
	password = User.objects.make_random_password()
	user.set_password(password)
	user.save()	
	# set profile status
	user.profile.status = "active"
	user.profile.first_name = linkedin_user_info['firstName']
	user.profile.last_name = linkedin_user_info['lastName']
	user.profile.save()
	user.username = linkedin_user_info['emailAddress']
	user.is_active = True
	user.save()	
	
	# send welcome email
	welcome = emaillib.WelcomeEmail(user)
	welcome.send_email()
	logger.info("sent welcome email to user: "+linkedin_user_info['emailAddress'])
	
	# check to see if user provided a headline
	if 'headline' in linkedin_user_info:
		user.profile.headline = linkedin_user_info['headline']
		user.profile.save()
	# check to see if user has a linkedin picture
	if 'pictureUrls' in linkedin_user_info:
		li_parser = LIProfile()
		li_parser.add_profile_pic(user,linkedin_user_info['pictureUrls']['values'][0])

	# update LI account
	if existing:
		# get existing LI account
		acct = Account.objects.get(owner=user,service="linkedin")
	else:
		# create LinkedIn account
		acct = Account()
	
	acct.owner = user
	acct.access_token = access_token['oauth_token']
	acct.token_secret = access_token['oauth_token_secret']
	acct.service = 'linkedin'
	acct.expires_on = datetime.now() + timedelta(seconds=int(access_token['oauth_authorization_expires_in']))
	acct.uniq_id = linkedin_user_info['id']
	acct.status = "active"
	acct.save()
		
	# finish processing LI profile
	profile_task = process_li_profile.delay(user.id,acct.id)

	# start processing connections
	connections_task = process_li_connections.delay(user.id,acct.id)

	# save task ids to session
	request.session['tasks'] = {
		'profile': profile_task.id,
		'connections': connections_task.id
	}

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

		if 'next' not in request.session:
			return HttpResponseRedirect('/majors/')
		else:
			return HttpResponseRedirect(request.session['next'])
開發者ID:tchaymore,項目名稱:prosperime,代碼行數:90,代碼來源:views.py


注:本文中的accounts.models.Account.access_token方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。