Skip to content

Commit

Permalink
fix: update auth logic
Browse files Browse the repository at this point in the history
  • Loading branch information
JingBh committed Feb 25, 2024
1 parent 3ccdec7 commit b538e5b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions bjut_tech/auth/jwglxt.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def check(self) -> bool:
return response.status_code == 200

def authenticate(self):
if self.check():
# also for setting initial session cookie
return

self._get_key()
pub_key = rsa.PublicKey(int(self.key[0], 16), int(self.key[1], 16))
password_encrypted = rsa.encrypt(self.password.encode('utf-8'), pub_key)
Expand Down
10 changes: 5 additions & 5 deletions bjut_tech/auth/libziyuan.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def authenticate(self, session: Optional[Client] = None) -> Client:
if session is None:
session = self._new_session()

saved_cookies = self.persistence.load(self.persistence_key)
if saved_cookies is not None:
session.cookies.update(saved_cookies)

if self.check(session):
print('[libziyuan] authenticated session reused')
return session

saved_cookies = self.persistence.load(self.persistence_key)
if saved_cookies is not None:
session.cookies.update(saved_cookies)
if self.check(session):
print('[libziyuan] authenticated session reused')
return session
self.persistence.delete(self.persistence_key)

response = session.get('https://libziyuan.bjut.edu.cn/por/login_auth.csp', params={
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "bjut-tech"
version = "0.2.1"
version = "0.2.2"
description = "The bjut.tech Python package for some common stuff."
readme = "README.md"
dependencies = [
Expand Down

0 comments on commit b538e5b

Please sign in to comment.