Make sure to check server token on login
This commit is contained in:
@@ -26,18 +26,21 @@ def user_login(username=None, password=None):
|
|||||||
|
|
||||||
# Try to login to Plex.tv to check if the user has a vaild account
|
# Try to login to Plex.tv to check if the user has a vaild account
|
||||||
plex_tv = plextv.PlexTV(username=username, password=password)
|
plex_tv = plextv.PlexTV(username=username, password=password)
|
||||||
user = plex_tv.get_token()
|
plex_user = plex_tv.get_token()
|
||||||
if user:
|
if plex_user:
|
||||||
user_token = user['auth_token']
|
user_token = plex_user['auth_token']
|
||||||
user_id = user['user_id']
|
user_id = plex_user['user_id']
|
||||||
|
|
||||||
# Retrieve user token from the database and check against the Plex.tv token.
|
# Retrieve user token from the database and check against the Plex.tv token.
|
||||||
# Also Make sure 'allow_guest' access is enabled for the user.
|
# Also Make sure 'allow_guest' access is enabled for the user.
|
||||||
# The user tokens should match if it is the same PlexPy install.
|
# The user tokens should match if it is the same PlexPy install.
|
||||||
tokens = user_data.get_tokens(user_id=user_id)
|
tokens = user_data.get_tokens(user_id=user_id)
|
||||||
if tokens and tokens['allow_guest'] and user_token == tokens['user_token']:
|
if not tokens:
|
||||||
# Successful login
|
# The user is not in the database
|
||||||
return True
|
return None
|
||||||
|
elif not tokens['allow_guest'] or not user_token == tokens['user_token']:
|
||||||
|
# Guest access is disabled, or user tokens don't match
|
||||||
|
return None
|
||||||
|
|
||||||
# Otherwise it is a new user or token is no longer valid.
|
# Otherwise it is a new user or token is no longer valid.
|
||||||
# Check if the user is in the database, not deleted, and 'allow_guest' access.
|
# Check if the user is in the database, not deleted, and 'allow_guest' access.
|
||||||
|
Reference in New Issue
Block a user