mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-08 14:10:52 -07:00
Allow logging in with email address
This commit is contained in:
parent
5d7ba8cf14
commit
d462ebe8e5
2 changed files with 19 additions and 9 deletions
|
@ -306,7 +306,7 @@ class Users(object):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn(u"PlexPy Users :: Unable to execute database query for set_config: %s." % 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
|
from plexpy import plextv
|
||||||
|
|
||||||
default_return = {'user_id': 0,
|
default_return = {'user_id': 0,
|
||||||
|
@ -322,10 +322,10 @@ class Users(object):
|
||||||
'allow_guest': 0
|
'allow_guest': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if not user_id and not user:
|
if not user_id and not user and not email:
|
||||||
return default_return
|
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()
|
monitor_db = database.MonitorDatabase()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -341,6 +341,12 @@ class Users(object):
|
||||||
'FROM users ' \
|
'FROM users ' \
|
||||||
'WHERE username = ? '
|
'WHERE username = ? '
|
||||||
result = monitor_db.select(query, args=[user])
|
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:
|
else:
|
||||||
result = []
|
result = []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -18,10 +18,11 @@
|
||||||
# Form based authentication for CherryPy. Requires the
|
# Form based authentication for CherryPy. Requires the
|
||||||
# Session tool to be loaded.
|
# Session tool to be loaded.
|
||||||
|
|
||||||
import cherrypy
|
|
||||||
from cgi import escape
|
from cgi import escape
|
||||||
from hashing_passwords import check_hash
|
import cherrypy
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from hashing_passwords import check_hash
|
||||||
|
import re
|
||||||
|
|
||||||
import plexpy
|
import plexpy
|
||||||
from plexpy import logger
|
from plexpy import logger
|
||||||
|
@ -33,7 +34,7 @@ SESSION_KEY = '_cp_username'
|
||||||
|
|
||||||
def check_credentials(username, password):
|
def check_credentials(username, password):
|
||||||
"""Verifies credentials for username and 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 \
|
if plexpy.CONFIG.HTTP_HASHED_PASSWORD and \
|
||||||
username == plexpy.CONFIG.HTTP_USERNAME and check_hash(password, plexpy.CONFIG.HTTP_PASSWORD):
|
username == plexpy.CONFIG.HTTP_USERNAME and check_hash(password, plexpy.CONFIG.HTTP_PASSWORD):
|
||||||
|
@ -146,6 +147,9 @@ class AuthController(object):
|
||||||
|
|
||||||
if vaild_login:
|
if vaild_login:
|
||||||
if user_group == 'guest':
|
if user_group == 'guest':
|
||||||
|
if re.match(r"[^@]+@[^@]+\.[^@]+", username):
|
||||||
|
user_details = Users().get_details(email=username)
|
||||||
|
else:
|
||||||
user_details = Users().get_details(user=username)
|
user_details = Users().get_details(user=username)
|
||||||
user_id = user_details['user_id']
|
user_id = user_details['user_id']
|
||||||
|
|
||||||
|
@ -173,7 +177,7 @@ class AuthController(object):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.debug(u"Invalid login attempt from '%s'." % username)
|
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
|
@cherrypy.expose
|
||||||
def logout(self):
|
def logout(self):
|
||||||
|
@ -183,7 +187,7 @@ class AuthController(object):
|
||||||
_session = cherrypy.session.get(SESSION_KEY)
|
_session = cherrypy.session.get(SESSION_KEY)
|
||||||
cherrypy.session[SESSION_KEY] = None
|
cherrypy.session[SESSION_KEY] = None
|
||||||
|
|
||||||
if _session['user']:
|
if _session and _session['user']:
|
||||||
cherrypy.request.login = None
|
cherrypy.request.login = None
|
||||||
self.on_logout(_session['user'])
|
self.on_logout(_session['user'])
|
||||||
raise cherrypy.HTTPRedirect("login")
|
raise cherrypy.HTTPRedirect("login")
|
Loading…
Add table
Add a link
Reference in a new issue