Skip to content

Commit

Permalink
Fix xenforo login
Browse files Browse the repository at this point in the history
  • Loading branch information
kemayo committed May 15, 2024
1 parent 7dc6543 commit ef9309e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions sites/xenforo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime
import re
import logging
import requests_cache
from bs4 import BeautifulSoup

from . import register, Site, SiteException, SiteSpecificOption, Section, Chapter
Expand Down Expand Up @@ -60,13 +61,19 @@ def siteurl(self, path):
return f'https://{self.domain}/{path}'

def login(self, login_details):
# Todo: handle non-https?
post = {
'login': login_details[0],
'password': login_details[1],
}
self.session.post(self.siteurl('login/login'), data=post)
logger.info("Logged in as %s", login_details[0])
with requests_cache.disabled():
login = self.session.get(self.siteurl('login/'))
soup = BeautifulSoup(login.text, 'html5lib')
post, action, method = self._form_data(soup.find(class_='p-body-content'))
post['login'] = login_details[0]
post['password'] = login_details[1]
# I feel the session *should* handle this cookies bit for me. But
# it doesn't. And I don't know why.
self.session.post(
self._join_url(login.url, action),
data=post, cookies=login.cookies
)
logger.info("Logged in as %s", login_details[0])

def extract(self, url):
soup = self._soup(url)
Expand Down

0 comments on commit ef9309e

Please sign in to comment.