diff --git a/plexpy/users.py b/plexpy/users.py index 38ac9ce6..9ef40ecb 100644 --- a/plexpy/users.py +++ b/plexpy/users.py @@ -306,7 +306,7 @@ class Users(object): except Exception as e: logger.warn(u"PlexPy Users :: Unable to execute database query for set_config: %s." % e) - def get_details(self, user_id=None, user=None): + def get_details(self, user_id=None, user=None, email=None): from plexpy import plextv default_return = {'user_id': 0, @@ -322,10 +322,10 @@ class Users(object): 'allow_guest': 0 } - if not user_id and not user: + if not user_id and not user and not email: return default_return - def get_user_details(user_id=user_id, user=user): + def get_user_details(user_id=user_id, user=user, email=email): monitor_db = database.MonitorDatabase() try: @@ -341,6 +341,12 @@ class Users(object): 'FROM users ' \ 'WHERE username = ? ' result = monitor_db.select(query, args=[user]) + elif email: + 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, deleted_user, allow_guest ' \ + 'FROM users ' \ + 'WHERE email = ? ' + result = monitor_db.select(query, args=[email]) else: result = [] except Exception as e: diff --git a/plexpy/webauth.py b/plexpy/webauth.py index 9c2adf82..c22911cc 100644 --- a/plexpy/webauth.py +++ b/plexpy/webauth.py @@ -18,10 +18,11 @@ # Form based authentication for CherryPy. Requires the # Session tool to be loaded. -import cherrypy from cgi import escape -from hashing_passwords import check_hash +import cherrypy from datetime import datetime, timedelta +from hashing_passwords import check_hash +import re import plexpy from plexpy import logger @@ -33,7 +34,7 @@ SESSION_KEY = '_cp_username' def check_credentials(username, password): """Verifies credentials for username and password. - Returns None on success or a string describing the error on failure""" + Returns True and the user group on success or False and no user group""" if plexpy.CONFIG.HTTP_HASHED_PASSWORD and \ username == plexpy.CONFIG.HTTP_USERNAME and check_hash(password, plexpy.CONFIG.HTTP_PASSWORD): @@ -146,7 +147,10 @@ class AuthController(object): if vaild_login: if user_group == 'guest': - user_details = Users().get_details(user=username) + if re.match(r"[^@]+@[^@]+\.[^@]+", username): + user_details = Users().get_details(email=username) + else: + user_details = Users().get_details(user=username) user_id = user_details['user_id'] user_tokens = Users().get_tokens(user_id=user_details['user_id']) @@ -173,7 +177,7 @@ class AuthController(object): else: logger.debug(u"Invalid login attempt from '%s'." % username) - return self.get_loginform(username, u"Incorrect username or password.") + return self.get_loginform(username, u"Incorrect username/email or password.") @cherrypy.expose def logout(self): @@ -183,7 +187,7 @@ class AuthController(object): _session = cherrypy.session.get(SESSION_KEY) cherrypy.session[SESSION_KEY] = None - if _session['user']: + if _session and _session['user']: cherrypy.request.login = None self.on_logout(_session['user']) raise cherrypy.HTTPRedirect("login") \ No newline at end of file