MCPcopy
hub / github.com/legendary-gl/legendary / _login

Method _login

legendary/core.py:183–250  ·  view source on GitHub ↗

Attempts logging in with existing credentials. raises ValueError if no existing credentials or InvalidCredentialsError if the API return an error

(self, lock, force_refresh=False)

Source from the content-addressed store, hash-verified

181 return False
182
183 def _login(self, lock, force_refresh=False) -> bool:
184 """
185 Attempts logging in with existing credentials.
186
187 raises ValueError if no existing credentials or InvalidCredentialsError if the API return an error
188 """
189 if not lock.data:
190 raise ValueError('No saved credentials')
191 elif self.logged_in and lock.data['expires_at']:
192 dt_exp = datetime.fromisoformat(lock.data['expires_at'][:-1])
193 dt_now = datetime.utcnow()
194 td = dt_now - dt_exp
195
196 # if session still has at least 10 minutes left we can re-use it.
197 if dt_exp > dt_now and abs(td.total_seconds()) > 600:
198 return True
199 else:
200 self.logged_in = False
201
202 # run update check
203 if self.update_check_enabled():
204 try:
205 self.check_for_updates()
206 except Exception as e:
207 self.log.warning(f'Checking for Legendary updates failed: {e!r}')
208 else:
209 self.apply_lgd_config()
210
211 # check for overlay updates
212 if self.is_overlay_installed():
213 try:
214 self.check_for_overlay_updates()
215 except Exception as e:
216 self.log.warning(f'Checking for EOS Overlay updates failed: {e!r}')
217
218 if lock.data['expires_at'] and not force_refresh:
219 dt_exp = datetime.fromisoformat(lock.data['expires_at'][:-1])
220 dt_now = datetime.utcnow()
221 td = dt_now - dt_exp
222
223 # if session still has at least 10 minutes left we can re-use it.
224 if dt_exp > dt_now and abs(td.total_seconds()) > 600:
225 self.log.info('Trying to re-use existing login session...')
226 try:
227 self.egs.resume_session(lock.data)
228 self.logged_in = True
229 return True
230 except InvalidCredentialsError as e:
231 self.log.warning(f'Resuming failed due to invalid credentials: {e!r}')
232 except Exception as e:
233 self.log.warning(f'Resuming failed for unknown reason: {e!r}')
234 # If verify fails just continue the normal authentication process
235 self.log.info('Falling back to using refresh token...')
236
237 try:
238 self.log.info('Logging in...')
239 userdata = self.egs.start_session(lock.data['refresh_token'])
240 except InvalidCredentialsError:

Callers 1

loginMethod · 0.95

Calls 9

update_check_enabledMethod · 0.95
check_for_updatesMethod · 0.95
apply_lgd_configMethod · 0.95
is_overlay_installedMethod · 0.95
infoMethod · 0.80
resume_sessionMethod · 0.80
start_sessionMethod · 0.80
clearMethod · 0.80

Tested by

no test coverage detected