# Path: secondary_implementations/python/modules/AbstractModule.py
# class AbstractModule:
# 	__metaclass__ = ABCMeta
# 
# 	def user_agent(self):
# 		agents = ['Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 '
# 							'(KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36',
# 							'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) '
# 							'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 '
# 							'Safari/537.36']
# 		return random.choice(agents)
# 
# 	def try_login(self, uname, password):
# 		return False


import requests
from lxml import html
from .AbstractModule import AbstractModule
# vim: ts=2 sw=2 noexpandtab

class LinkedinModule(AbstractModule):
	def try_login(self, uname, password):
		headers = {'user-agent': AbstractModule().user_agent()}
		resp = requests.get('https://www.linkedin.com', headers=headers)

		tree = html.fromstring(resp.content)
		payload = tree.forms[0].fields
		payload = {k : v for k, v in payload.items()}
		payload['session_key'] = uname
		payload['session_password'] = password
		loginResp = requests.post(
			'https://www.linkedin.com/uas/login-submit', data=payload,
			headers=headers, cookies=resp.cookies, allow_redirects=False)

		return loginResp.status_code == 302


# Path: secondary_implementations/python/modules/AbstractModule.py
# class AbstractModule:
# 	__metaclass__ = ABCMeta
# 
# 	def user_agent(self):
# 		agents = ['Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 '
# 							'(KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36',
# 							'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) '
# 							'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 '
# 							'Safari/537.36']
# 		return random.choice(agents)
# 
# 	def try_login(self, uname, password):
# 		return False


# Path: secondary_implementations/python/modules/LinkedinModule.py
import requests
from lxml import html
from .AbstractModule import AbstractModule

# vim: ts=2 sw=2 noexpandtab

class LinkedinModule(AbstractModule):
	def try_login(self, uname, password):
		headers = {'user-agent': AbstractModule().user_agent()}
		resp = requests.get('https://www.linkedin.com', headers=headers)

		tree = html.fromstring(resp.content)
		payload = tree.forms[0].fields
		payload = {k : v for k, v in payload.items()}
		payload['session_key'] = uname
		payload['session_password'] = password
		loginResp = requests.post(
			'https://www.linkedin.com/uas/login-submit', data=payload,
			headers=headers, cookies=resp.cookies, allow_redirects=False)

		return loginResp.status_code == 302


linkedin = LinkedinModule()