From: Calin Crisan Date: Mon, 12 Jan 2015 18:31:25 +0000 (+0200) Subject: various login issue fixes X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=b028762426956285412141207ae658aeb50b97cc;p=motioneye-debian various login issue fixes --- diff --git a/doc/todo.txt b/doc/todo.txt deleted file mode 100644 index 40b04fe..0000000 --- a/doc/todo.txt +++ /dev/null @@ -1 +0,0 @@ --> implement custom camera frame sizes diff --git a/src/handlers.py b/src/handlers.py index 9af89f3..ea773e0 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -83,10 +83,10 @@ class BaseHandler(RequestHandler): signature == utils.compute_signature(self.request.method, self.request.uri, self.request.body, main_config.get('@normal_password'))): return 'normal' - - elif username: + + elif username and username != '_': logging.error('authentication failed for user %(user)s' % {'user': username}) - + return None def _handle_request_exception(self, exception): @@ -113,6 +113,7 @@ class BaseHandler(RequestHandler): user = self.current_user if (user is None) or (user != 'admin' and (admin or _admin)): self.set_header('Content-Type', 'application/json') + return self.finish_json({'error': 'unauthorized', 'prompt': prompt}) return func(self, *args, **kwargs) diff --git a/static/css/main.css b/static/css/main.css index c7adb83..946e5ec 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -444,6 +444,7 @@ tr.hidden { table.login-dialog { margin: auto; + font-size: 22px; /* always bigger, regardless of screen size */ } table.add-camera-dialog { @@ -726,6 +727,11 @@ div.media-dialog-delete-all-button:ACTIVE { background-color: #B03427; } +td.login-dialog-error { + color: red; + display: none; +} + /* camera frames */ diff --git a/static/js/main.js b/static/js/main.js index 12c4d9e..4a5a51a 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -216,10 +216,15 @@ function ajax(method, url, data, callback, error) { ajax(method, origUrl, origData, callback, error); }); } + + window._loginRetry = true; } - else if (callback) { - $('body').toggleClass('admin', isAdmin()); - callback(data); + else { + delete window._loginRetry; + if (callback) { + $('body').toggleClass('admin', isAdmin()); + callback(data); + } } }, contentType: json ? 'application/json' : null, @@ -392,13 +397,13 @@ function setCookie(name, value, days) { if (days) { date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); - expires = '; expires=' + date.toGMTString(); + expires = 'expires=' + date.toGMTString(); } else { expires = ''; } - document.cookie = name + '=' + value + expires + '; path=/'; + document.cookie = name + '=' + value + '; ' + expires + '; path=/'; } function remCookie(name) { @@ -414,7 +419,7 @@ function showErrorMessage(message) { } function doLogout() { - remCookie('username'); + setCookie('username', '_'); window.location.reload(true); } @@ -1695,6 +1700,12 @@ function fetchCurrentConfig(onFetch) { updateConfigUi(); } + else { /* normal user */ + if (!cameras.length) { + /* normal user with no cameras doesn't make too much sense - force login */ + doLogout(); + } + } var mainLoadingProgressImg = $('img.main-loading-progress'); if (mainLoadingProgressImg.length) { @@ -1882,6 +1893,9 @@ function runLoginDialog(retry) { var form = $('
' + + '' + + '' + + '' + '' + '' + '' + @@ -1895,19 +1909,19 @@ function runLoginDialog(retry) { var usernameEntry = form.find('#usernameEntry'); var passwordEntry = form.find('#passwordEntry'); + var errorTd = form.find('td.login-dialog-error'); + + if (window._loginRetry) { + errorTd.css('display', 'table-cell'); + errorTd.html('Invalid credentials.'); + } var params = { title: 'Login', content: form, buttons: [ {caption: 'Cancel', isCancel: true, click: function () { - setTimeout(function () { - tempFrame.remove(); - }, 5000); - - if (retry) { - retry(); - } + tempFrame.remove(); }}, {caption: 'Login', isDefault: true, click: function () { window.username = usernameEntry.val();