Skip to content

Commit

Permalink
Improved Tesla Login handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ngardiner committed Oct 22, 2019
1 parent f480bc8 commit fe47295
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/TWCManager/Control/HTTPControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def do_GET(self):
global master
url = urllib.parse.urlparse(self.path)

if (url.path == '/'):
if (url.path == '/' or
url.path == '/apiacct/True' or
url.path == '/apiacct/False'):
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
Expand All @@ -181,9 +183,15 @@ def do_GET(self):
page += "<table border='0' padding='0' margin='0'><tr>"
page += "<td valign='top'>"

if (not master.teslaLoginAskLater):
if (url.path == '/apiacct/False'):
page += "<font color='red'><b>Failed to log in to Tesla Account. Please check username and password and try again.</b></font>"

if (not master.teslaLoginAskLater and url.path != '/apiacct/True'):
page += self.request_teslalogin()

if (url.path == '/apiacct/True'):
page += "<b>Thank you, successfully fetched Tesla API token."

page += self.show_status()

page += "</table>"
Expand Down Expand Up @@ -243,15 +251,17 @@ def process_teslalogin(self):
master.teslaLoginAskLater = True

if (not master.teslaLoginAskLater):
# Process the information submitted
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
# Connect to Tesla API

master.carapi.setCarApiLastErrorTime(0)
ret = master.carapi.car_api_available(self.fields['email'][0],self.fields['password'][0])
page = str(ret)

self.wfile.write(page.encode("utf-8"))
# Redirect to an index page with output based on the return state of
# the function
self.send_response(302)
self.send_header('Location', '/apiacct/' + str(ret))
self.end_headers()
self.wfile.write(''.encode("utf-8"))
return
else:
# User has asked to skip Tesla Account submission for this session
Expand Down

0 comments on commit fe47295

Please sign in to comment.