Fix auth_key not actually being saved

This would make the user have to login every time.
This commit is contained in:
Lonami Exo 2018-10-22 20:58:07 +02:00
parent 7dece209a0
commit 4562ba9ccf
2 changed files with 6 additions and 11 deletions

View File

@ -312,16 +312,11 @@ class TelegramBaseClient(abc.ABC):
self.session.server_address, self.session.port,
loop=self._loop, proxy=self._proxy
))
self.session.auth_key = self._sender.auth_key
await self._sender.send(self._init_with(
functions.help.GetConfigRequest()))
# AuthKey is a property, so re-setting it has side-effects.
# Since it's used as a reference and only its inner payload
# may have actually changed after connecting, we use the
# reference from the session file itself as its value.
self.session.auth_key = self.session.auth_key
self._updates_handle = self._loop.create_task(self._update_loop())
def is_connected(self):

View File

@ -68,8 +68,8 @@ class MTProtoSender:
self._recv_loop_handle = None
# Preserving the references of the AuthKey and state is important
self._auth_key = auth_key or AuthKey(None)
self._state = MTProtoState(self._auth_key)
self.auth_key = auth_key or AuthKey(None)
self._state = MTProtoState(self.auth_key)
# Outgoing messages are put in a queue and sent in a batch.
# Note that here we're also storing their ``_RequestState``.
@ -204,12 +204,12 @@ class MTProtoSender:
.format(self._retries))
__log__.debug('Connection success!')
if not self._auth_key:
if not self.auth_key:
plain = MTProtoPlainSender(self._connection)
for retry in range(1, self._retries + 1):
try:
__log__.debug('New auth_key attempt {}...'.format(retry))
self._auth_key.key, self._state.time_offset =\
self.auth_key.key, self._state.time_offset =\
await authenticator.do_authentication(plain)
break
@ -402,7 +402,7 @@ class MTProtoSender:
else:
__log__.warning('Invalid buffer %s', e)
self._auth_key.key = None
self.auth_key.key = None
self._start_reconnect()
return
except Exception: