]> www.vanbest.org Git - motioneye-debian/commitdiff
various login issue fixes
authorCalin Crisan <ccrisan@gmail.com>
Mon, 12 Jan 2015 18:31:25 +0000 (20:31 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Mon, 12 Jan 2015 18:31:25 +0000 (20:31 +0200)
doc/todo.txt [deleted file]
src/handlers.py
static/css/main.css
static/js/main.js

diff --git a/doc/todo.txt b/doc/todo.txt
deleted file mode 100644 (file)
index 40b04fe..0000000
+++ /dev/null
@@ -1 +0,0 @@
--> implement custom camera frame sizes
index 9af89f32fb7423bcd7d0d4eade997a697bb52c22..ea773e072105081d1d1c37d1d977b009e38e3e3c 100644 (file)
@@ -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)
index c7adb83a49bef65c8b2edebb2d8d0789a2f8e2d4..946e5ec40d1939cffc8ec2fa0bb3d5e4abe02edf 100644 (file)
@@ -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 */
 
index 12c4d9efbba94bdc54ca4a48dc356eb7a5809bc6..4a5a51a6db4df34dd98844730fe6dde52b27b321 100644 (file)
@@ -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 = 
             $('<form action="' + baseUri + 'login/" target="temp" method="POST"><table class="login-dialog">' +
+                '<tr>' +
+                    '<td class="login-dialog-error" colspan="100"></td>' +
+                '</tr>' +
                 '<tr>' +
                     '<td class="dialog-item-label"><span class="dialog-item-label">Username</span></td>' +
                     '<td class="dialog-item-value"><input type="text" name="username" class="styled" id="usernameEntry"></td>' +
@@ -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();