Ejemplo n.º 1
0
def get_employee_profile(uuid):
	try:
		employee_profile = None
			
   		# Get the Employee
		employee = model_employee.Employee.get_by_key_name(uuid)
		if employee is None:
			logging.error('LinkedInGetSkillsController : get() : No Employee with UUID '+uuid+' found.')
			self.error(500)
			return
			
		# Recreate the API instance, then set the API access token/secret to be the stored Employee access token/secret
		api = get_linkedin_api(uuid)
		if api is False:
			return False
		api._access_token = employee.access_token
		api._access_token_secret = employee.access_token_secret
		
		# Get current User profile
		employee_profile = api.get_profile(fields=['id,public-profile-url,first-name,last-name,skills:(id,skill:(name),proficiency:(level,name),years:(id,name))'])
		logging.debug(employee_profile) 
		
		# Save the LinkedIn Skills list
	   	if employee_profile.skills is not None and len(employee_profile.skills) > 0:
			skill_keys = datastore.set_employee_skills(uuid, employee_profile.skills)
		
			# Save the OAuth Verifier and the Skills against the Employee
			datastore.set_employee(uuid, dict(skills=skill_keys))          
		return True
	except (Exception), e:
		raise e   
Ejemplo n.º 2
0
	def get(self, uuid):
		try:
			
			is_admin = users.is_current_user_admin()
			# NOTE: The URL will have a query string appended : "/oauth-response/EMPLOYEE_UUID?oauth_token=21903a3c-b69e-4c55-a7a7-425474a84bfd&oauth_verifier=17604"
			uuid = str(uuid)
			employee_profile = None
			
			# Get the Employee
			employee = model_employee.Employee.get_by_key_name(uuid)
			if employee is None:
				logging.error('LinkedInOAuthResponseController : get() : No Employee with UUID '+uuid+' found.')
				self.error(500)
				return
			
			# Recreate the API instance, then set the API request token/secret to be the stored Employee request token/secret
			api = utils.get_linkedin_api(uuid)
			api._request_token = employee.oauth_request_token
			api._request_token_secret = employee.oauth_request_token_secret
			
			# The OAuth Token should match the one we sent
			oauth_token = str(self.request.get('oauth_token'))
			
			# The Verifier is needed for future API calls for this Employee
			oauth_verifier = str(self.request.get('oauth_verifier'))
		                                         
			# Get Access Token
			result = api.access_token(verifier=oauth_verifier)
			if result == False:
				logging.error('LinkedInOAuthResponseController : get() : '+api.get_error())
				self.error(500)
				return
			
			# Get current User profile
			employee_profile = api.get_profile(fields=['id,first-name,last-name,skills:(id,skill:(name),proficiency:(level,name),years:(id,name)),picture-url'])
			logging.debug(employee_profile)
			
			# Save the LinkedIn Skills list
			skill_keys = list()
			if employee_profile.skills is not None and len(employee_profile.skills) > 0:
				skill_keys = datastore.set_employee_skills(uuid, employee_profile.skills)
			
			# Save the OAuth Verifier and the Skills against the Employee
			datastore.set_employee(uuid, dict(oauth_verifier=oauth_verifier, access_token=api._access_token, access_token_secret=api._access_token_secret, skills=skill_keys, picture_url=employee_profile.picture_url))
		    
			# Send the Employee to the OAuth Response view
			args = dict(env=os.environ, employee=employee, is_admin=is_admin)
			path = os.path.join(os.path.dirname(__file__),'../views/employees/oauth-response.html')
			self.response.out.write(template.render(path, args)) 
		except (Exception), e:
			logging.error('LinkedInOAuthResponseController : get() : caught exception')
			logging.error(e)
			self.error(500)