Server-side http logic for adding account

This commit is contained in:
James Taylor 2018-12-26 02:21:20 -08:00
parent b4aa7cecbc
commit b321b5fc64
2 changed files with 15 additions and 1 deletions

View File

@ -23,11 +23,12 @@ def save_accounts():
def add_account(username, password, save): def add_account(username, password, save):
cookie_jar = http.cookiejar.LWPCookieJar() cookie_jar = http.cookiejar.LWPCookieJar()
_login(username, password, cookie_jar) condition = _login(username, password, cookie_jar)
accounts[username] = { accounts[username] = {
"save":save, "save":save,
"cookies":cookie_jar.as_lwp_str(ignore_discard=False, ignore_expires=False), "cookies":cookie_jar.as_lwp_str(ignore_discard=False, ignore_expires=False),
} }
return condition
def cookie_jar_from_lwp_str(lwp_str): def cookie_jar_from_lwp_str(lwp_str):
cookie_jar = http.cookiejar.LWPCookieJar() cookie_jar = http.cookiejar.LWPCookieJar()

View File

@ -116,6 +116,19 @@ def youtube(env, start_response):
start_response('303 See Other', (('Location', common.URL_ORIGIN + '/comments?ctoken=' + comments.make_comment_ctoken(video_id, sort=1)),) ) start_response('303 See Other', (('Location', common.URL_ORIGIN + '/comments?ctoken=' + comments.make_comment_ctoken(video_id, sort=1)),) )
return '' return ''
elif path == "/login":
if 'save' in fields and fields['save'][0] == "on":
save_account = True
else:
save_account = False
if accounts.add_account(fields['username'][0], fields['password'][0], save_account ):
start_response('200 OK', () )
return b'Account successfully added'
else:
start_response('200 OK', () )
return b'Failed to add account'
else: else:
start_response('404 Not Found', ()) start_response('404 Not Found', ())
return b'404 Not Found' return b'404 Not Found'