Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Relogin - How to redirect current browser to login

    Hi there

    Please help - I'm using SmartClient Power Edition version 9.0. I also subscribed to support.
    I'm struggling to get relogin working.

    I have a NON SmartClient HTML login page - login.jsp.
    I also have a filter that will redirect the user to the login page when the session timedout.

    I did include the loginRequiredMarker.html text in my login.jsp page.
    So, when the session has timed out within my SmartClient app, the user does NOT gets redirected to the login.jsp, but instead a NEW window is opened for login.jsp.

    All I want is to redirect the existing browser session to the login.jsp. I'm OK if the transaction is lost. Let me just get this basic one in place.

    According to your help I get a clue to do this:
    http://www.smartclient.com/docs/9.0/a/b/c/go.html#group..relogin
    But, where do I put this code:
    window.location.replace(LOGIN_PAGE);

    Please help. I really tried to see if there's been other discussions about this.

    #2
    You would add this to your loginRequired implementation. But as the docs tell you, you really really don't want to do this (it's a terrible user experience). You should really just start on the correct implementation, which is typically quite straightforward.

    Comment


      #3
      Thanks. I assume the best way is to implement the example as per reloginFlow.js.
      What is unclear to me is where do I override the RPCManager class function as per reloginFlow.js?
      Should this be done in one place when the application loads?

      Comment


        #4
        Here's another question. I know my suggestion is ugly, but I urgently need to stop a non logged in user to continue while implementing a better solution.

        Basically, I tried to add the code as per your suggestion - but it does NOT work.
        I changed the last line from:

        if (isc && isc.RPCManager) isc.RPCManager.delayCall("handleLoginRequired", [window]);

        TO:

        if (isc && isc.RPCManager) window.location.replace("login.jsp");

        Please see my full Login.jsp code below:
        Code:
        <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
                 pageEncoding="ISO-8859-1" %>
        <!DOCTYPE html>
        <%@ page import="za.co.adminonline.utils.ServerConstants" %>
        <%@ page import="za.co.adminonline.utils.ServerUtils" %>
        <%@ taglib uri="isomorphic" prefix="isomorphic" %>
        
        <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-ZA" xml:lang="en">
        <head>
        
            <isomorphic:loadISC skin="IITS" cacheOnly="true"/>
        
            <%
                // Get the input URL params
                String cid = request.getParameter(ServerConstants.URL_PARAM_COMPANY_ID);
                String cdesc = request.getParameter(ServerConstants.URL_PARAM_COMPANY_DESCR);
        
                // If the user lands on the login page and is still logged in - forward to index page
                String svarStrLoginSuccessDt = (String) request.getSession().getAttribute(ServerConstants.HTTP_SESSION_VAR_SUCCESS_DT);
                if (svarStrLoginSuccessDt != null) {
        
                    // Make sure logged in user is not coming from a different company
                    String existingCid = (String) request.getSession().getAttribute(ServerConstants.HTTP_SESSION_VAR_COMPANY_ID);
                    if ((cid != null) && (cid.equals(existingCid) == true)) {
                      response.sendRedirect(ServerConstants.URL_HOME_PAGE_ADMIN);
                    }
                }
        
                // If the URL param does not exist, find it in the session
                if ((cid == null) || (cid.trim().length() == 0)) {
                    cid = (String) request.getSession().getAttribute(ServerConstants.HTTP_SESSION_VAR_COMPANY_ID);
                    cdesc = (String) request.getSession().getAttribute(ServerConstants.HTTP_SESSION_VAR_COMPANY_DESCR);
                }
        
                // Exit the page if these params are not there, it cannot function without these params
                if ((cid == null) || (cid.trim().length() == 0)) {
                    response.sendRedirect("adminonline.html");
                }
        
                // Extract previous login values or errors to display/pre-populate the login page
                String svarStrLoginErrorOverall = (String) request.getSession().getAttribute(ServerConstants.HTTP_SESSION_VAR_LOGIN_ERROR_OVERALL);
                if ((svarStrLoginErrorOverall == null) || (svarStrLoginErrorOverall.trim().length() == 0)) {
                    svarStrLoginErrorOverall = "";
                }
        
                String svarStrLoginErrorEmail = (String) request.getSession().getAttribute(ServerConstants.HTTP_SESSION_VAR_LOGIN_ERROR_EMAIL);
                if ((svarStrLoginErrorEmail == null) || (svarStrLoginErrorEmail.trim().length() == 0)) {
                    svarStrLoginErrorEmail = "";
                } else {
                    svarStrLoginErrorOverall += ServerConstants.LOGIN_FLD_CAP_EMAIL + ": " + svarStrLoginErrorEmail;
                }
        
                String svarStrLoginErrorPassword = (String) request.getSession().getAttribute(ServerConstants.HTTP_SESSION_VAR_LOGIN_ERROR_PWD);
                if ((svarStrLoginErrorPassword == null) || (svarStrLoginErrorPassword.trim().length() == 0)) {
                    svarStrLoginErrorPassword = "";
                } else {
                    svarStrLoginErrorOverall += ServerConstants.LOGIN_FLD_CAP_PASSWORD + ": " + svarStrLoginErrorPassword;
                }
        
                String svarStrLoginEmail = (String) request.getSession().getAttribute(ServerConstants.HTTP_SESSION_VAR_EMAIL);
                if ((svarStrLoginEmail == null) || (svarStrLoginEmail.trim().length() == 0)) {
                    svarStrLoginEmail = "";
                }
        
                request.getSession().setAttribute(ServerConstants.HTTP_SESSION_VAR_COMPANY_ID, cid);
                request.getSession().setAttribute(ServerConstants.HTTP_SESSION_VAR_COMPANY_DESCR, cdesc);
        
            %>
        
            <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
            <title><%=cdesc %> <%=ServerConstants.SYSTEM_NAME_POST %> </title>
        
            <link href="login/style.css<%=ServerConstants.ADMINONLINE_CACHE_STR %>" rel="stylesheet" type="text/css">
        
            <style type="text/css">
                body {
                    padding:0px;
                    margin:0px;
                    background-repeat: no-repeat;
                    background-color: #e9eaea;
                    background-image: url(images/login_bgr.jpg);
                }
            </style>
        
            <script type="text/javascript" src="login/jquery.min.js"></script>
            <script type="text/javascript" src="login/jquery.uniform.min.js"></script>
            <script type="text/javascript" src="login/script.js"></script>
        
            <script type="text/javascript"
                    src="<%=(String) request.getContextPath() + "/js/"%>CompanyFieldStates.js<%=ServerConstants.ADMINONLINE_CACHE_STR %>"></script>
            <script>
                <isomorphic:loadDS ID="company_field_rules" />
        
                var gvarObjCompanyFieldStates = new CompanyFieldStates();
                var gvarObjCompanyFieldStates.getCompanyFieldStates("<%=cid%>");
            </script>
        
        </head>
        <body>
            <div id="logo">
                <div id="box_logo">
                    <a href="#"><img src="images/logo<%=cid %>.png" border="0"></a>
                </div>
            </div>
          <div id="wrapper">
        
            <!-- Start Formoid form-->
            <form method="post" action="<%= response.encodeURL("AdminOnlineSecurity") %>" id="formoid" style="" title="" >
              <div><h2 class="title"><%= ServerConstants.LOGIN_HEADING %></h2></div>
                <div>
                    <span style="color: red; margin: 5px 0; line-height: 1em; font-size: 15px;"><%= svarStrLoginErrorOverall %></span>
                </div>
                <div>
                    <label class="title"><%= ServerConstants.LOGIN_FLD_CAP_EMAIL %></label>
                    <input id="<%= ServerConstants.LOGIN_FLD_ID_EMAIL %>" name="<%= ServerConstants.LOGIN_FLD_ID_EMAIL %>" type="text" size="35" maxlength="50" value="<%= svarStrLoginEmail %>" />
                </div>
                <div>
                    <label class="title"><%= ServerConstants.LOGIN_FLD_CAP_PASSWORD %></label>
                    <input id="<%= ServerConstants.LOGIN_FLD_ID_PASSWORD %>" type="password" name="<%= ServerConstants.LOGIN_FLD_ID_PASSWORD %>" size="35" maxlength="50" />
                </div>
                <div>
                    <input id="<%= ServerConstants.LOGIN_FLD_ID_COMPANY_ID %>" name="<%= ServerConstants.LOGIN_FLD_ID_COMPANY_ID %>" type="hidden" value="<%=cid %>"/>
                </div>
                <div>
                    <input id="<%= ServerConstants.LOGIN_FLD_ID_COMPANY_DESCR %>" name="<%= ServerConstants.LOGIN_FLD_ID_COMPANY_DESCR %>" type="hidden" value="<%=cdesc %>"/>
                </div>
                <div>
                    <input  type="submit" id="login-submit" name="login-submit" value="<%= ServerConstants.LOGIN_BTN_LOGIN %>" />
                </div>
                <div id="float">
                    <input type="button" id="login-register" name="login-register" value="<%= ServerConstants.LOGIN_BTN_REGISTER %>" onclick="window.location = 'register.jsp'" />
                </div>
                <div id="float">
                    <input type="button" id="forget-passwd" name="forget-passwd" value="<%= ServerConstants.LOGIN_BTN_FORGOT_PASSWORD %>" onclick="window.location = 'forgetPassword.jsp'" />
                </div>
                <div id="floathelp">
                    <input type="button" id="help" name="help" value="<%= ServerConstants.LOGIN_BTN_HELP %>" onclick="window.location = 'help.jsp'" />
                </div>
        
            </form>
        </div>
        
        <!-- Stop Formoid form-->
        <div id="footercont" class="clearfix">
            <p><%=ServerConstants.ADMINONLINE_FOOTER %></p>
        </div>
        
        <script type="text/javascript">
            var emailInput = document.getElementById("<%= ServerConstants.LOGIN_FLD_ID_EMAIL %>");
            if (emailInput != null) emailInput.focus();
        
        
        
        </script>
        
        <SCRIPT>//'"]]>>isc_loginRequired
            //
            // Embed this whole script block VERBATIM into your login page to enable
            // SmartClient RPC relogin.
            //=======
        
        
        
            if (!window.isc && document.domain && document.domain.indexOf(".") != -1
                    && !(new RegExp("^(\\d{1,3}\\.){3}\\d{1,3}$").test(document.domain)))
            {
        
                var set = false;
                while (document.domain.indexOf(".") != -1) {
                    try {
                        if (window.opener && window.opener.isc) break;
                        if (window.top.isc) break;
        
                        if (!set) { document.domain = document.domain; set = true; }
                        else { document.domain = document.domain.replace(/.*?\./, ''); }
                    } catch (e) {
                        try {
                            if (!set) { document.domain = document.domain; set = true }
                            else { document.domain = document.domain.replace(/.*?\./, ''); }
                        } catch (ee) {
                            break;
                        }
                    }
                }
            }
        
            var isc = top.isc ? top.isc : window.opener ? window.opener.isc : null;
            if (isc && isc.RPCManager) window.location.replace("login.jsp");
        
        </SCRIPT>
        
        </body>
        </html>

        Comment


          #5
          Notice how the snippet you've just edited says it must be embedded VERBATIM :)

          You aren't intended to edit this snippet, and there is no legitimate reason to do so..

          The correct way to handle relogin, by responding to the loginRequired event, is demonstrated in the reloginFlow.js file that the Relogin main document encourages you to look at. The specific part is:

          Code:
          isc.RPCManager.addClassMethods({
          
              loginRequired : function (transactionNum, rpcRequest, rpcResponse) {
              }
          });
          So if you want to proceed with your redirect you would place it in the loginRequired implementation above.

          Comment


            #6
            Thanks. I'm still not sure where exactly to put this code:
            Code:
                isc.RPCManager.addClassMethods({
                    loginRequired : function (transactionNum, rpcRequest, rpcResponse) {
                        window.location.replace("login.jsp");
                    }
                });
            I added it to the index.jsp page that loads the SmartClient app.
            But, it doesn't work?

            Comment


              #7
              Adding it to your SmartClient app is correct. Be sure to add it after you have loaded SmartClient. Other than that, we'll need some more information than "doesn't work" to help.

              Comment

              Working...
              X