diff --git a/data/interfaces/default/edit_user.html b/data/interfaces/default/edit_user.html
index 8d5626ca..1ba3f645 100644
--- a/data/interfaces/default/edit_user.html
+++ b/data/interfaces/default/edit_user.html
@@ -20,6 +20,7 @@ is_allow_sync Returns bool value for whether the user has sync rights.
is_restricted Returns bool value for whether the user account is restricted.
do_notify Returns bool value for whether to send notifications for the user.
keep_history Returns bool value for whether to keep history for the user.
+allow_guest Returns bool value for whether to allow guest access for the user.
DOCUMENTATION :: END
%doc>
@@ -67,6 +68,12 @@ DOCUMENTATION :: END
Uncheck this if you do not want to keep any history on this user's activity.
+
+
+ Allow Guest Access
+
+
Uncheck this if you do not want to allow this user to login to PlexPy.
+
% if data['user_id']:
Purge
@@ -108,12 +115,16 @@ DOCUMENTATION :: END
var custom_thumb = $("#custom_avatar_url").val();
var do_notify = 0;
var keep_history = 0;
+ var allow_guest = 0;
if ($("#do_notify").is(":checked")) {
do_notify = 1;
}
if ($("#keep_history").is(":checked")) {
keep_history = 1;
}
+ if ($("#allow_guest").is(":checked")) {
+ allow_guest = 1;
+ }
$.ajax({
url: 'edit_user',
@@ -122,7 +133,8 @@ DOCUMENTATION :: END
friendly_name: friendly_name,
custom_thumb: custom_thumb,
do_notify: do_notify,
- keep_history: keep_history
+ keep_history: keep_history,
+ allow_guest: allow_guest
},
cache: false,
async: true,
diff --git a/data/interfaces/default/js/tables/users.js b/data/interfaces/default/js/tables/users.js
index acbf4d3b..2a5b7717 100644
--- a/data/interfaces/default/js/tables/users.js
+++ b/data/interfaces/default/js/tables/users.js
@@ -45,6 +45,7 @@ users_list_table_options = {
' Purge    ' +
'  ' +
'  ' +
+ '  ' +
'
');
},
"width": "7%",
@@ -300,12 +301,16 @@ $('#users_list_table').on('change', 'td.edit-control > .edit-user-toggles > inpu
var do_notify = 0;
var keep_history = 0;
+ var allow_guest = 0;
if ($('#do_notify-' + rowData['user_id']).is(':checked')) {
do_notify = 1;
}
if ($('#keep_history-' + rowData['user_id']).is(':checked')) {
keep_history = 1;
}
+ if ($('#allow_guest-' + rowData['user_id']).is(':checked')) {
+ allow_guest = 1;
+ }
friendly_name = tr.find('td.edit-user-control > .edit-user-name > input').val();
@@ -316,6 +321,7 @@ $('#users_list_table').on('change', 'td.edit-control > .edit-user-toggles > inpu
friendly_name: friendly_name,
do_notify: do_notify,
keep_history: keep_history,
+ allow_guest: allow_guest,
thumb: rowData['user_thumb']
},
cache: false,
diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html
index 880229de..892c120b 100644
--- a/data/interfaces/default/settings.html
+++ b/data/interfaces/default/settings.html
@@ -520,6 +520,16 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
data-parsley-errors-container="#http_hash_password_error" data-parsley-error-message="Cannot un-hash password, please set a new password." data-parsley-no-focus required>
+
+
+
+ Allow Guest Access to PlexPy
+
+
Allow shared users to login to PlexPy using their Plex.tv account.
+
+
diff --git a/plexpy/config.py b/plexpy/config.py
index 14b413a6..49ca6f67 100644
--- a/plexpy/config.py
+++ b/plexpy/config.py
@@ -13,6 +13,7 @@ def bool_int(value):
return int(bool(value))
_CONFIG_DEFINITIONS = {
+ 'ALLOW_GUEST_ACCESS': (int, 'General', 0),
'DATE_FORMAT': (str, 'General', 'YYYY-MM-DD'),
'GROUPING_GLOBAL_HISTORY': (int, 'PlexWatch', 0),
'GROUPING_USER_HISTORY': (int, 'PlexWatch', 0),
diff --git a/plexpy/users.py b/plexpy/users.py
index 1ce4d443..e3f28092 100644
--- a/plexpy/users.py
+++ b/plexpy/users.py
@@ -39,9 +39,10 @@ def user_login(username=None, password=None):
return True
# Otherwise it is a new user or token is no longer valid.
- # Check if the user is in the database.
+ # Check if the user is in the database, not deleted, and 'allow_guest' access.
user_details = user_data.get_details(user_id=user_id)
- if user_details['allow_guest'] and user_id == str(user_details['user_id']):
+ if user_id == str(user_details['user_id']) and \
+ not user_details['deleted_user'] and user_details['allow_guest']:
# The user is in the database, so try to retrieve a new server token.
# If a server token is returned, then the user is a vaild friend
@@ -53,21 +54,26 @@ def user_login(username=None, password=None):
monitor_db = database.MonitorDatabase()
try:
logger.debug(u"PlexPy Users :: Regestering tokens for user '%s' in the database." % username)
- monitor_db.action('UPDATE users SET user_token = ?, server_token = ? WHERE user_id = ?',
- [user_token, server_token, user_id])
- # Successful login
- return True
+ result = monitor_db.action('UPDATE users SET user_token = ?, server_token = ? WHERE user_id = ?',
+ [user_token, server_token, user_id])
+
+ if result:
+ # Successful login
+ return True
+ else:
+ logger.warn(u"PlexPy Users :: Unable to register user '%s' in database." % username)
+ return None
except Exception as e:
logger.warn(u"PlexPy Users :: Unable to register user '%s' in database: %s." % (username, e))
return None
else:
- logger.warn(u"PlexPy Users :: Unable to retrieve Plex.tv server token.")
+ logger.warn(u"PlexPy Users :: Unable to retrieve Plex.tv server token for user '%s'." % username)
return None
else:
logger.warn(u"PlexPy Users :: Unable to register user '%s'. User not in the database." % username)
return None
else:
- logger.warn(u"PlexPy Users :: Unable to retrieve Plex.tv user token.")
+ logger.warn(u"PlexPy Users :: Unable to retrieve Plex.tv user token for user '%s'." % username)
return None
return None
@@ -341,13 +347,13 @@ class Users(object):
try:
if str(user_id).isdigit():
query = 'SELECT user_id, username, friendly_name, thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
- 'email, is_home_user, is_allow_sync, is_restricted, do_notify, keep_history, allow_guest ' \
+ 'email, is_home_user, is_allow_sync, is_restricted, do_notify, keep_history, deleted_user, allow_guest ' \
'FROM users ' \
'WHERE user_id = ? '
result = monitor_db.select(query, args=[user_id])
elif user:
query = 'SELECT user_id, username, friendly_name, thumb AS user_thumb, custom_avatar_url AS custom_thumb, ' \
- 'email, is_home_user, is_allow_sync, is_restricted, do_notify, keep_history, allow_guest ' \
+ 'email, is_home_user, is_allow_sync, is_restricted, do_notify, keep_history, deleted_user, allow_guest ' \
'FROM users ' \
'WHERE username = ? '
result = monitor_db.select(query, args=[user])
@@ -382,6 +388,7 @@ class Users(object):
'is_restricted': item['is_restricted'],
'do_notify': item['do_notify'],
'keep_history': item['keep_history'],
+ 'deleted_user': item['deleted_user'],
'allow_guest': item['allow_guest']
}
return user_details
@@ -637,7 +644,8 @@ class Users(object):
if user_id:
try:
monitor_db = database.MonitorDatabase()
- query = 'SELECT allow_guest, user_token, server_token FROM users WHERE user_id = ?'
+ query = 'SELECT allow_guest, user_token, server_token FROM users ' \
+ 'WHERE user_id = ? AND deleted_user = 0'
result = monitor_db.select_single(query, args=[user_id])
if result:
tokens = {'allow_guest': result['allow_guest'],
diff --git a/plexpy/webauth.py b/plexpy/webauth.py
index 94427c35..aaf15eda 100644
--- a/plexpy/webauth.py
+++ b/plexpy/webauth.py
@@ -39,7 +39,7 @@ def check_credentials(username, password):
return True, u'admin'
elif username == plexpy.CONFIG.HTTP_USERNAME and password == plexpy.CONFIG.HTTP_PASSWORD:
return True, u'admin'
- elif user_login(username, password):
+ elif plexpy.CONFIG.ALLOW_GUEST_ACCESS and user_login(username, password):
return True, u'guest'
else:
return False, None
diff --git a/plexpy/webserve.py b/plexpy/webserve.py
index 0c293ce3..1d732aa8 100644
--- a/plexpy/webserve.py
+++ b/plexpy/webserve.py
@@ -671,6 +671,7 @@ class WebInterface(object):
custom_thumb = kwargs.get('custom_thumb', '')
do_notify = kwargs.get('do_notify', 0)
keep_history = kwargs.get('keep_history', 0)
+ allow_guest = kwargs.get('allow_guest', 0)
user_data = users.Users()
if user_id:
@@ -679,7 +680,8 @@ class WebInterface(object):
friendly_name=friendly_name,
custom_thumb=custom_thumb,
do_notify=do_notify,
- keep_history=keep_history)
+ keep_history=keep_history,
+ allow_guest=allow_guest)
status_message = "Successfully updated user."
return status_message
except:
@@ -1257,6 +1259,7 @@ class WebInterface(object):
http_password = ''
config = {
+ "allow_guest_access": checked(plexpy.CONFIG.ALLOW_GUEST_ACCESS),
"http_hash_password": checked(plexpy.CONFIG.HTTP_HASH_PASSWORD),
"http_hashed_password": plexpy.CONFIG.HTTP_HASHED_PASSWORD,
"http_host": plexpy.CONFIG.HTTP_HOST,
@@ -1384,7 +1387,8 @@ class WebInterface(object):
"refresh_libraries_on_startup", "refresh_users_on_startup",
"ip_logging_enable", "movie_logging_enable", "tv_logging_enable", "music_logging_enable",
"notify_consecutive", "notify_upload_posters", "notify_recently_added", "notify_recently_added_grandparent",
- "monitor_pms_updates", "monitor_remote_access", "get_file_sizes", "log_blacklist", "http_hash_password"
+ "monitor_pms_updates", "monitor_remote_access", "get_file_sizes", "log_blacklist", "http_hash_password",
+ "allow_guest_access"
]
for checked_config in checked_configs:
if checked_config not in kwargs: