Changeset 7530


Ignore:
Timestamp:
Nov 26, 2018, 12:40:55 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2131: Add support for installing multiple authentication managers

The most recently used login form should now be remembered and automatically loaded the next time.

Location:
trunk/www
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/login.js

    r7529 r7530  
    3333  login.initPage = function()
    3434  {
     35    // If there is no requested login form, we try to use the last one that was used
     36    var requestedForm = Data.get(document.body, 'requested-form');
     37    if (!requestedForm)
     38    {
     39      var lastLoginForm = login.getLastLoginForm();
     40      var selectedLoginForm = Data.get(document.body, 'login-form');
     41      if (lastLoginForm && lastLoginForm != selectedLoginForm)
     42      {
     43        login.switchLoginForm(lastLoginForm);
     44        return;
     45      }
     46    }
     47   
    3548    // Information links
    3649    Buttons.addClickHandler('aboutServer', login.showAbout);
     
    4457    Buttons.addClickHandler('close', App.closeWindow);
    4558   
    46     Events.addEventHandler('loginForm', 'change', login.switchLoginForm);
     59    Events.addEventHandler('loginForm', 'change', login.loginFormOnChange);
    4760   
    4861    var extraField = Doc.element('extraField');
     
    7083  }
    7184 
    72   login.switchLoginForm = function(event)
    73   {
    74     // TODO -- will not work when login form is in a different jsp
     85 
     86  login.loginFormOnChange = function(event)
     87  {
     88    login.switchLoginForm(event.currentTarget.value);
     89  }
     90 
     91  login.switchLoginForm = function(loginForm)
     92  {
    7593    var url = 'main.jsp?ID='+App.getSessionId();
    76     url += '&loginForm='+event.currentTarget.value;
     94    url += '&loginForm='+encodeURIComponent(loginForm);
    7795    location.replace(url);
    7896  }
     
    141159    return lastLogin;
    142160  }
     161 
     162 
     163  /*
     164    Save the last login form. If local storage is available we use that,
     165    otherwise we simply save it on the top frameset.
     166  */
     167  login.saveLastLoginForm = function(lastLoginForm)
     168  {
     169    var storage = App.localStorage();
     170    if (storage)
     171    {
     172      App.setLocal('last-login-form', lastLoginForm);
     173    }
     174    else
     175    {
     176      App.topWindow().lastLoginForm = lastLoginForm;
     177    }
     178  }
     179 
     180  /**
     181    Get the last used login form. If local storage is available we
     182    use that, otherwise we use the top frameset.
     183   */
     184  login.getLastLoginForm = function()
     185  {
     186    var lastLoginForm;
     187    var storage = App.localStorage();
     188    if (storage)
     189    {
     190      lastLoginForm = App.getLocal('last-login-form');
     191    }
     192    if (!lastLoginForm)
     193    {
     194      lastLoginForm = App.topWindow().lastLoginForm;
     195    }
     196    return lastLoginForm;
     197  }
     198
    143199 
    144200  /**
     
    202258    }
    203259   
    204     alert(frm.loginForm.value);
    205    
    206260    // On the impersonate form, check that a user has been selected
    207261    if (frm.user_id && !frm.user_id.value)
     
    216270      Login.saveLastLogin(frm.login.value);
    217271    }
    218     // TODO -- save the login form
     272    if (frm.loginForm)
     273    {
     274      Login.saveLastLoginForm(frm.loginForm.value);
     275    }
    219276   
    220277    // Check 'remain on page' and 'redirect' options
     
    246303      var frm2 = Forms.cloneAsHidden(frm);
    247304      document.body.appendChild(frm2);
    248       alert(frm2.loginForm.value);
    249305      frm2.submit();
    250306      document.body.removeChild(frm2);
  • trunk/www/login.jsp

    r7529 r7530  
    6161  String message = null;
    6262  String login = request.getParameter("login");
     63  String loginForm = Values.getStringOrNull(request.getParameter("loginForm"));
    6364   
    6465  if ("Login".equals(cmd) || cmd == null)
     
    6768    String deviceToken = Values.getStringOrNull(request.getParameter("deviceToken"));
    6869    String extraValue = Values.getStringOrNull(request.getParameter("extraField"));
    69     String loginForm = Values.getStringOrNull(request.getParameter("loginForm"));
    7070    try
    7171    {
     
    233233    if (errorMessage != null)
    234234    {
    235       response.sendRedirect(root+"main.jsp?ID="+ID+"&login="+HTML.urlEncode(login)+"&error="+HTML.urlEncode(errorMessage));
     235      response.sendRedirect(root+"main.jsp?ID="+ID+"&login="+HTML.urlEncode(login)+"&loginForm="+HTML.encodeTags(loginForm)+"&error="+HTML.urlEncode(errorMessage));
    236236    }
    237237    else
  • trunk/www/main.jsp

    r7529 r7530  
    116116    bean.setPasswordField(FieldInfo.DEFAULT_PASSWORD);
    117117    loginAction = bean;
     118    selectedLoginForm = "password";
    118119  }
    119120
     
    127128    <ext:stylesheets context="<%=jspContext%>" />
    128129  </base:head>
    129   <base:body style="padding-top: 5em;" data-login-form="<%=Values.getString(selectedLoginForm)%>">
     130  <base:body style="padding-top: 5em;" data-login-form="<%=HTML.encodeTags(selectedLoginForm)%>" data-requested-form="<%=HTML.encodeTags(requestedLoginForm) %>">
    130131    <form name="login" action="login.jsp" method="post">
    131132    <input type="hidden" name="ID" value="<%=ID%>">
Note: See TracChangeset for help on using the changeset viewer.