瀏覽代碼

[desktop] Add a login_splash_html configuration option for custom login messages

Enrico Berti 10 年之前
父節點
當前提交
20b8e46

+ 4 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -205,6 +205,10 @@
     # e.g. <H2>Test Lab A2 Hue Services</H2>
     ## banner_top_html=
 
+    # Login splash HTML code
+    # e.g. WARNING: You are required to have authorisation before you proceed
+    ## login_splash_html=
+
   # Configuration options for user authentication into the web application
   # ------------------------------------------------------------------------
   [[auth]]

+ 4 - 0
desktop/core/src/desktop/conf.py

@@ -609,6 +609,10 @@ CUSTOM = ConfigSection(
                    help=_("Top banner HTML code. This code will be placed in the navigation bar "
                         "so that it will reside at the top of the page in a fixed position. " +
                         "One common value is `<img src=\"http://www.example.com/example.gif\" />`")),
+    LOGIN_SPLASH_HTML=Config("login_splash_html",
+                   default="",
+                   help=_("The login splash HTML code. This code will be placed in the login page, "
+                        "useful for security warning messages.")),
 ))
 
 AUTH = ConfigSection(

+ 18 - 12
desktop/core/src/desktop/templates/login.mako

@@ -202,16 +202,16 @@ ${ commonheader("Welcome to Hue", "login", user, "50px") | n,unicode }
           <div class="alert alert-block">
             ${_('Since this is your first time logging in, pick any username and password. Be sure to remember these, as')}
             <strong>${_('they will become your Hue superuser credentials.')}</strong>
-            % if is_password_policy_enabled():
+            %if is_password_policy_enabled():
 	      <p>${get_password_hint()}</p>
-            % endif
+            %endif
           </div>
         %endif
 
         <div class="input-prepend
-          % if backend_names == ['OAuthBackend']:
+          %if backend_names == ['OAuthBackend']:
             hide
-          % endif
+          %endif
         ">
           <span class="add-on"><i class="fa fa-user"></i></span>
           ${ form['username'] | n,unicode }
@@ -220,9 +220,9 @@ ${ commonheader("Welcome to Hue", "login", user, "50px") | n,unicode }
         ${ form['username'].errors | n,unicode }
 
         <div class="input-prepend
-          % if 'AllowAllBackend' in backend_names or backend_names == ['OAuthBackend']:
+          %if 'AllowAllBackend' in backend_names or backend_names == ['OAuthBackend']:
             hide
-          % endif
+          %endif
         ">
           <span class="add-on"><i class="fa fa-lock"></i></span>
           ${ form['password'] | n,unicode }
@@ -239,11 +239,11 @@ ${ commonheader("Welcome to Hue", "login", user, "50px") | n,unicode }
         %if login_errors and not form['username'].errors and not form['password'].errors:
           <div class="alert alert-error" style="text-align: center">
             <strong><i class="fa fa-exclamation-triangle"></i> ${_('Error!')}</strong>
-            % if form.errors:
+            %if form.errors:
               % for error in form.errors:
                ${ form.errors[error]|unicode,n }
               % endfor
-            % endif
+            %endif
           </div>
         %endif
         <hr/>
@@ -254,7 +254,13 @@ ${ commonheader("Welcome to Hue", "login", user, "50px") | n,unicode }
         %endif
         <input type="hidden" name="next" value="${next}"/>
       </form>
+
+    </div>
+    %if conf.CUSTOM.LOGIN_SPLASH_HTML.get():
+    <div class="alert alert-info" id="login-splash">
+      ${ conf.CUSTOM.LOGIN_SPLASH_HTML.get() | n,unicode }
     </div>
+    %endif
   </div>
 </div>
 
@@ -273,17 +279,17 @@ ${ commonheader("Welcome to Hue", "login", user, "50px") | n,unicode }
       }, 1000);
     });
 
-    % if 'AllowAllBackend' in backend_names:
+    %if 'AllowAllBackend' in backend_names:
       $('#id_password').val('password');
-    % endif
+    %endif
 
-    % if backend_names == ['OAuthBackend']:
+    %if backend_names == ['OAuthBackend']:
       $("input").css({"display": "block", "margin-left": "auto", "margin-right": "auto"});
       $("input").bind('click', function () {
         window.location.replace('/login/oauth/');
         return false;
       });
-    % endif
+    %endif
 
     $("ul.errorlist").each(function () {
       $(this).prev().addClass("error");

+ 6 - 3
desktop/core/src/desktop/tests.py

@@ -622,15 +622,18 @@ def test_last_access_time():
 
 
 def test_ui_customizations():
-  custom_banner = 'test ui customization'
+  custom_message = 'test ui customization'
   reset = (
-    desktop.conf.CUSTOM.BANNER_TOP_HTML.set_for_testing(custom_banner),
+    desktop.conf.CUSTOM.BANNER_TOP_HTML.set_for_testing(custom_message),
+    desktop.conf.CUSTOM.LOGIN_SPLASH_HTML.set_for_testing(custom_message),
   )
 
   try:
     c = make_logged_in_client()
+    resp = c.get('/accounts/login/', follow=False)
+    assert_true(custom_message in resp.content, resp)
     resp = c.get('/about', follow=True)
-    assert_true(custom_banner in resp.content, resp)
+    assert_true(custom_message in resp.content, resp)
   finally:
     for old_conf in reset:
       old_conf()