Coverage for client/parts/auth.py : 87%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# -*- coding: utf-8 -*-
2from __future__ import annotations
4# -- stdlib --
5from typing import TYPE_CHECKING
7# -- third party --
8# -- own --
9from utils.events import EventHub
10import wire
12# -- typing --
13if TYPE_CHECKING:
14 from client.core import Core # noqa: F401
17# -- code --
18class Auth(object):
19 def __init__(self, core: Core):
20 self.core = core
21 self.uid = 0
23 D = core.events.server_command
24 D[wire.AuthSuccess] += self._auth_success
25 D[wire.AuthError] += self._auth_error
27 def _auth_success(self, ev: wire.AuthSuccess) -> EventHub.StopPropagation:
28 core = self.core
29 self.uid = ev.uid
30 core.events.auth_success.emit(ev.uid)
31 return EventHub.STOP_PROPAGATION
33 def _auth_error(self, ev: wire.AuthError) -> EventHub.StopPropagation:
34 core = self.core
35 core.events.auth_error.emit(ev.reason)
36 return EventHub.STOP_PROPAGATION
38 # ----- Public Methods -----
39 def login(self, token: str) -> None:
40 core = self.core
41 core.server.write(wire.Auth(token=token))