1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-03 00:51:11 +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')
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
# and query. So route all requests through a single Session object which holds this state.
@ -199,12 +203,10 @@ class Session:
raise VerificationRequired()
r = self.session.post(URL_CONFIRM, data = {'code' : code}, timeout=timeout)
r.raise_for_status()
# verification doesn't actually return a yes/no, so log in again to determine state
try:
self.login()
self.save() # Save cookies now for use by command-line app
except:
pass
if r.url == URL_CONFIRM: # redirects away on success
raise VerificationRequired()
self.save() # Save cookies now for use by command-line app
self.login()
def query(self):
if self.state == Session.STATE_NONE: