Hide keyboard shortcuts

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 

3 

4# -- stdlib -- 

5from typing import TYPE_CHECKING 

6 

7# -- third party -- 

8# -- own -- 

9from utils.events import EventHub 

10import wire 

11 

12# -- typing -- 

13if TYPE_CHECKING: 

14 from client.core import Core # noqa: F401 

15 

16 

17# -- code -- 

18class Auth(object): 

19 def __init__(self, core: Core): 

20 self.core = core 

21 self.uid = 0 

22 

23 D = core.events.server_command 

24 D[wire.AuthSuccess] += self._auth_success 

25 D[wire.AuthError] += self._auth_error 

26 

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 

32 

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 

37 

38 # ----- Public Methods ----- 

39 def login(self, token: str) -> None: 

40 core = self.core 

41 core.server.write(wire.Auth(token=token))