Skip to content

Commit

Permalink
Fix logging in
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-psi committed Mar 17, 2024
1 parent acd6fb9 commit 4e07d55
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions cogs/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from asyncio import TimeoutError
from http.cookiejar import LWPCookieJar, Cookie as HTTPCookie
from secrets import SystemRandom
from typing import TYPE_CHECKING, Optional

Expand Down Expand Up @@ -35,7 +36,9 @@ async def logout(self, ctx: Context, *, invalidate: bool = False):
"""
msg = "Successfully logged out."
if invalidate:
async with asuppress(InvalidTokenException), self.utils.chuninet(ctx) as client:
async with asuppress(InvalidTokenException), self.utils.chuninet(
ctx
) as client:
result = await client.logout()
if not result:
msg = (
Expand All @@ -52,14 +55,37 @@ async def _verify_and_login(self, id: int, clal: str) -> Optional[Exception]:
if clal.startswith("clal="):
clal = clal[5:]

async with ChuniNet(clal) as client:
cookie = HTTPCookie(
version=0,
name="clal",
value=clal,
port=None,
port_specified=False,
domain="lng-tgk-aime-gw.am-all.net",
domain_specified=True,
domain_initial_dot=False,
path="/common_auth",
path_specified=True,
secure=False,
expires=3856586927, # 2092-03-17 10:08:47Z
discard=False,
comment=None,
comment_url=None,
rest={},
)
jar = LWPCookieJar()
jar.set_cookie(cookie)

async with ChuniNet(jar) as client:
try:
await client.validate_cookie()
await client.authenticate()
except ChuniNetException as e:
return e

async with self.bot.begin_db_session() as session, session.begin():
await session.merge(Cookie(discord_id=id, cookie=clal))
await session.merge(
Cookie(discord_id=id, cookie=f"#LWP-Cookie-2.0\n{jar.as_lwp_str()}")
)
return None

@commands.hybrid_command("login")
Expand Down

0 comments on commit 4e07d55

Please sign in to comment.