Skip to content

Commit

Permalink
Automatically logout the user on invalid token
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsmile committed Mar 29, 2021
1 parent e60cb87 commit 2853de9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ But really, almost nothing is documented. And where there are guides and documen
* ~~Sort tracks after search~~ (sort of done)
* ~~Preserve Browser size~~
* ~~Logout Button~~
* Automatic Logout on wrong credentials
* ~~Automatic Logout on wrong credentials~~
* ~~Authentication with query token when HTTPMS gets a support for it~~
14 changes: 12 additions & 2 deletions httpms.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ def search_tracks_api(self, http_code, data):
tracks like the one returned from searching into the HTTPMS via its
REST API.
'''
if http_code == 401:
print('Authentication with the remote server is out of date')
self.force_logout()
return

if data is None:
print("No data in search_tracks_api callback")
return
Expand Down Expand Up @@ -298,8 +303,8 @@ def logout_clicked_cb(self, btn):
self.store_auth_data("", "")
self.logged_in = False
self.login_entry_address.set_text("")
self.builder.get_object("service_username").set_text("")
self.builder.get_object("service_password").set_text("")
self.login_entry_user.set_text("")
self.login_entry_pass.set_text("")

self.show_login_screen()

Expand All @@ -308,6 +313,11 @@ def logout_clicked_cb(self, btn):
db.entry_delete_by_type(entry_type)
db.commit()

def force_logout(self):
server_address = self.address_base
self.logout_clicked_cb(None)
self.login_entry_address.set_text(server_address)

def show_login_screen(self):
'''
Hides the browser and entry list view. In their place shows the
Expand Down

0 comments on commit 2853de9

Please sign in to comment.