Fix login check, close #446
Facebook changed something internally, so that the redirected url is no longer always "/home.php", but instead sometimes just "/"
This commit is contained in:
@@ -24,6 +24,12 @@ def session_factory(user_agent=None):
|
|||||||
return session
|
return session
|
||||||
|
|
||||||
|
|
||||||
|
def is_home(url):
|
||||||
|
parts = _util.urlparse(url)
|
||||||
|
# Check the urls `/home.php` and `/`
|
||||||
|
return "home" in parts.path or "/" == parts.path
|
||||||
|
|
||||||
|
|
||||||
def _2fa_helper(session, code, r):
|
def _2fa_helper(session, code, r):
|
||||||
soup = find_input_fields(r.text)
|
soup = find_input_fields(r.text)
|
||||||
data = dict()
|
data = dict()
|
||||||
@@ -39,7 +45,7 @@ def _2fa_helper(session, code, r):
|
|||||||
|
|
||||||
r = session.post(url, data=data)
|
r = session.post(url, data=data)
|
||||||
|
|
||||||
if "home" in r.url:
|
if is_home(r.url):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
del data["approvals_code"]
|
del data["approvals_code"]
|
||||||
@@ -52,7 +58,7 @@ def _2fa_helper(session, code, r):
|
|||||||
# At this stage, we have dtsg, nh, name_action_selected, submit[Continue]
|
# At this stage, we have dtsg, nh, name_action_selected, submit[Continue]
|
||||||
r = session.post(url, data=data)
|
r = session.post(url, data=data)
|
||||||
|
|
||||||
if "home" in r.url:
|
if is_home(r.url):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
del data["name_action_selected"]
|
del data["name_action_selected"]
|
||||||
@@ -60,7 +66,7 @@ def _2fa_helper(session, code, r):
|
|||||||
# At this stage, we have dtsg, nh, submit[Continue]
|
# At this stage, we have dtsg, nh, submit[Continue]
|
||||||
r = session.post(url, data=data)
|
r = session.post(url, data=data)
|
||||||
|
|
||||||
if "home" in r.url:
|
if is_home(r.url):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
del data["submit[Continue]"]
|
del data["submit[Continue]"]
|
||||||
@@ -69,7 +75,7 @@ def _2fa_helper(session, code, r):
|
|||||||
# At this stage, we have dtsg, nh, submit[This was me]
|
# At this stage, we have dtsg, nh, submit[This was me]
|
||||||
r = session.post(url, data=data)
|
r = session.post(url, data=data)
|
||||||
|
|
||||||
if "home" in r.url:
|
if is_home(r.url):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
del data["submit[This was me]"]
|
del data["submit[This was me]"]
|
||||||
@@ -131,7 +137,7 @@ class State(object):
|
|||||||
if "save-device" in r.url:
|
if "save-device" in r.url:
|
||||||
r = session.get("https://m.facebook.com/login/save-device/cancel/")
|
r = session.get("https://m.facebook.com/login/save-device/cancel/")
|
||||||
|
|
||||||
if "home" in r.url:
|
if is_home(r.url):
|
||||||
return cls.from_session(session=session)
|
return cls.from_session(session=session)
|
||||||
else:
|
else:
|
||||||
raise _exception.FBchatUserError(
|
raise _exception.FBchatUserError(
|
||||||
@@ -143,7 +149,7 @@ class State(object):
|
|||||||
# Send a request to the login url, to see if we're directed to the home page
|
# Send a request to the login url, to see if we're directed to the home page
|
||||||
url = "https://m.facebook.com/login.php?login_attempt=1"
|
url = "https://m.facebook.com/login.php?login_attempt=1"
|
||||||
r = self._session.get(url, allow_redirects=False)
|
r = self._session.get(url, allow_redirects=False)
|
||||||
return "Location" in r.headers and "home" in r.headers["Location"]
|
return "Location" in r.headers and is_home(r.headers["Location"])
|
||||||
|
|
||||||
def logout(self):
|
def logout(self):
|
||||||
logout_h = self._logout_h
|
logout_h = self._logout_h
|
||||||
|
Reference in New Issue
Block a user