Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Auth Func #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions pyscp/wikidot.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ class Wiki(pyscp.core.Wiki):
def __init__(self, site):
super().__init__(site)
self.req = InsistentRequest()
self.cookies = 'wikidot_token7=123456;'

def __repr__(self):
return '{}.{}({})'.format(
Expand Down Expand Up @@ -446,13 +447,34 @@ def _list_pages_parsed(self, **kwargs):

def auth(self, username, password):
"""Login to wikidot with the given username/password pair."""
return self.req.post(
'https://www.wikidot.com/default--flow/login__LoginPopupScreen',
login = self.req.post(
"https://www.wikidot.com/default--flow/login__LoginPopupScreen",
data=dict(
login=username,
password=password,
action='Login2Action',
event='login'))
login=username, password=password, action="Login2Action", event="login"
),
)
if self.custom_domain == True:
cd = self.req.get(self.site)
soup = bs4.BeautifulSoup(cd.text, "html.parser")
s = soup.find_all("script")

for i in s:
if (
"http://www.wikidot.com/default__flow/login__CustomDomainScript"
in str(i)
):
siteid = i.get("src")
redirect = self.req.get(siteid, headers=login.cookies.get_dict())
redir_url = re.findall(
r"var redir_url = '\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))';",
redirect.text,
)[0]
auth = self.req.get(redir_url)
for i in auth.cookies.get_dict():
self.cookies += f"{i}={auth.cookies.get_dict()[i]};"
return

self.cookies += f'WIKIDOT_SESSION_ID={login.cookies["WIKIDOT_SESSION_ID"]};'

def list_categories(self):
"""Return forum categories."""
Expand Down