From 2f8e768c5cb38c1a79f88a91b9cf09764c405ef2 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Sun, 1 May 2016 10:56:06 -0700 Subject: [PATCH] Add modal popup for admin login from menu --- data/interfaces/default/base.html | 50 +++++++++++++++++++++++++- data/interfaces/default/css/plexpy.css | 14 ++++++++ data/interfaces/default/login.html | 4 +-- plexpy/webauth.py | 11 +++--- 4 files changed, 72 insertions(+), 7 deletions(-) diff --git a/data/interfaces/default/base.html b/data/interfaces/default/base.html index 279c9b74..59f98e79 100644 --- a/data/interfaces/default/base.html +++ b/data/interfaces/default/base.html @@ -227,7 +227,7 @@ from plexpy.helpers import anon_url
  • Restart
  • Shutdown
  • % else: -
  • Admin Login
  • +
  • Admin Login
  • % endif % if _session['expiry']: @@ -241,6 +241,48 @@ from plexpy.helpers import anon_url +% if _session['user_group'] != 'admin': + +% endif + ${next.headerIncludes()}
    ${next.body()} @@ -322,6 +364,12 @@ ${next.headerIncludes()} }); } }); + + % if _session['user_group'] != 'admin': + $('#admin-login-modal').on('shown.bs.modal', function () { + $('#admin-login-modal #username').focus() + }) + % endif ${next.javascriptIncludes()} diff --git a/data/interfaces/default/css/plexpy.css b/data/interfaces/default/css/plexpy.css index 5f40abeb..c9d6477f 100644 --- a/data/interfaces/default/css/plexpy.css +++ b/data/interfaces/default/css/plexpy.css @@ -2908,4 +2908,18 @@ a.no-highlight:hover { margin-bottom: 0; font-weight: 400; cursor: pointer; +} +#admin-login-modal .form-group label { + font-weight: 400; + color: #999; +} +#admin-login-modal .remember-group { + float: left; + color: #999; +} +#admin-login-modal .remember-group .control-label { + display: inline; + margin-bottom: 0; + font-weight: 400; + cursor: pointer; } \ No newline at end of file diff --git a/data/interfaces/default/login.html b/data/interfaces/default/login.html index 5c1846b5..a535f0e4 100644 --- a/data/interfaces/default/login.html +++ b/data/interfaces/default/login.html @@ -31,13 +31,13 @@ ${msg}
    % endif -
    +
    -
    +
    diff --git a/plexpy/webauth.py b/plexpy/webauth.py index 394ee2ba..7c0a7221 100644 --- a/plexpy/webauth.py +++ b/plexpy/webauth.py @@ -98,7 +98,7 @@ def user_login(username=None, password=None): return None -def check_credentials(username, password): +def check_credentials(username, password, admin_login='0'): """Verifies credentials for username and password. Returns True and the user group on success or False and no user group""" @@ -107,7 +107,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 plexpy.CONFIG.ALLOW_GUEST_ACCESS and user_login(username, password): + elif not admin_login == '1' and plexpy.CONFIG.ALLOW_GUEST_ACCESS and user_login(username, password): return True, u'guest' else: return False, None @@ -202,14 +202,14 @@ class AuthController(object): raise cherrypy.HTTPRedirect("login") @cherrypy.expose - def login(self, username=None, password=None, remember_me='0'): + def login(self, username=None, password=None, remember_me='0', admin_login='0'): if not cherrypy.config.get('tools.sessions.on'): raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT) if username is None or password is None: return self.get_loginform() - (vaild_login, user_group) = check_credentials(username, password) + (vaild_login, user_group) = check_credentials(username, password, admin_login) if vaild_login: if user_group == 'guest': @@ -234,6 +234,9 @@ class AuthController(object): self.on_login(username) raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT) + elif admin_login == '1': + logger.debug(u"Invalid admin login attempt from '%s'." % username) + raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT) else: logger.debug(u"Invalid login attempt from '%s'." % username) return self.get_loginform(username, u"Incorrect username/email or password.")