1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-07 10:53:26 +03:00

Tidy verification handling.

This commit is contained in:
Jonathan Harris 2016-01-19 20:22:38 +00:00
parent 4eefbd4ca9
commit 7cedb01b19

View File

@ -133,7 +133,11 @@ class CredentialsError(Exception):
return unicode(self).encode('utf-8') return unicode(self).encode('utf-8')
class VerificationRequired(Exception): class VerificationRequired(Exception):
pass def __unicode__(self):
return _('Error: Verification failed')
def __str__(self):
return unicode(self).encode('utf-8')
# Server companion.orerve.net uses a session cookie ("CompanionApp") to tie together login, verification # Server companion.orerve.net uses a session cookie ("CompanionApp") to tie together login, verification
# and query. So route all requests through a single Session object which holds this state. # and query. So route all requests through a single Session object which holds this state.
@ -199,12 +203,10 @@ class Session:
raise VerificationRequired() raise VerificationRequired()
r = self.session.post(URL_CONFIRM, data = {'code' : code}, timeout=timeout) r = self.session.post(URL_CONFIRM, data = {'code' : code}, timeout=timeout)
r.raise_for_status() r.raise_for_status()
# verification doesn't actually return a yes/no, so log in again to determine state if r.url == URL_CONFIRM: # redirects away on success
try: raise VerificationRequired()
self.login()
self.save() # Save cookies now for use by command-line app self.save() # Save cookies now for use by command-line app
except: self.login()
pass
def query(self): def query(self):
if self.state == Session.STATE_NONE: if self.state == Session.STATE_NONE: