Changeset 37627 for main


Ignore:
Timestamp:
2023-04-08T17:42:27+12:00 (13 months ago)
Author:
davidb
Message:

Moving login support with Google sign-in to 'shared-templates.xs'. This is so both login.xsl and authen.xsl can make use of the shared template that implements this.

Location:
main/trunk/greenstone3/web/interfaces/default/transform
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/transform/pages/authen.xsl

    r36027 r37627  
    5757                <!-- ********** -->
    5858                <xsl:when test="/page/pageResponse/authenticationNode/service/@operation = 'Login'">
    59                  
     59
     60                        <xsl:call-template name="loginForm">
     61                      <xsl:with-param name="action-url">
     62                        <xsl:value-of select="$library_name"/>
     63                        <xsl:text>/admin/</xsl:text>
     64                        <xsl:value-of select="/page/pageRequest/paramList/param[@name = 's1.authpage']/@value" />
     65                      </xsl:with-param>
     66                    </xsl:call-template>
     67                    <!--
    6068                    <form method="POST" action="{$library_name}/admin/{/page/pageRequest/paramList/param[@name = 's1.authpage']/@value}">
    6169                        <table id="loginTable">
     
    7280                        </xsl:text>
    7381                    </script>
     82-->
    7483                </xsl:when>
    7584
  • main/trunk/greenstone3/web/interfaces/default/transform/pages/login.xsl

    r37549 r37627  
    7171        <br/>
    7272        </xsl:if>
     73        <xsl:call-template name="loginForm">
     74                  <xsl:with-param name="action-url" select="/page/pageRequest/paramList/param[@name = 'redirectURL']/@value" />
     75                </xsl:call-template>
     76        <!--
    7377        <form method="POST"
    7478              id="login-form"
     
    108112                  <td colspan="2">
    109113                    <gsf:variable name="serlvetProtocol"><xsl:value-of select="/page/pageResponse/interfaceOptions/option[@name='servlet_protocol']/@value"/></gsf:variable>
    110                     <!--<gsf:variable name="baseURL"><xsl:value-of select="/page/pageRequest/@baseURL"/></gsf:variable>-->
     114                    < ! - - <gsf:variable name="baseURL"><xsl:value-of select="/page/pageRequest/@baseURL"/></gsf:variable> - - >
    111115                    <gsf:variable name="redirectURL"><xsl:value-of select="/page/pageRequest/paramList/param[@name = 'redirectURL']/@value"/></gsf:variable>
    112116                    <gsf:div id="g_id_onload"
     
    116120                    <xsl:call-template name="generateGoogleIdentityLoginURL">
    117121                      <xsl:with-param name="servletProtocol" select="$servletProtocol"></xsl:with-param>
    118                       <!--<xsl:with-param name="baseURL"         select="$baseURL"></xsl:with-param>-->
     122                      < ! - -<xsl:with-param name="baseURL"         select="$baseURL"></xsl:with-param> - - >
    119123                                          <xsl:with-param name="baseURL"         select="$base-href"></xsl:with-param>
    120124                      <xsl:with-param name="redirectURL"     select="$redirectURL"></xsl:with-param>
     
    192196            </xsl:text>
    193197        </script>
     198        -->
    194199    </xsl:template>
    195200</xsl:stylesheet>
  • main/trunk/greenstone3/web/interfaces/default/transform/shared-templates.xsl

    r35811 r37627  
    44    xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
    55    xmlns:gslib="http://www.greenstone.org/skinning"
     6    xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat"
    67    extension-element-prefixes="java util"
    78    exclude-result-prefixes="java util">
     
    190191  </xsl:template>
    191192
     193  <xsl:template name="loginForm">
     194    <xsl:param name="action-url"></xsl:param>
     195
     196    <form method="POST" id="login-form" action="{$action-url}">
     197
     198      <table id="loginTable">
     199    <tr>
     200      <td colspan="2">
     201        <input type="text" name="username" style="width:95%;" autocomplete="username">
     202          <xsl:attribute name="placeholder">
     203        <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'authen.username')"/>
     204          </xsl:attribute>
     205        </input>
     206      </td>
     207    </tr>
     208    <tr>
     209      <td colspan="2">
     210        <input type="password" name="password" style="width:95%;" autocomplete="current-password">
     211          <xsl:attribute name="placeholder">
     212        <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'authen.password')"/>
     213          </xsl:attribute>
     214        </input>
     215      </td>
     216    </tr>
     217    <tr>
     218      <td colspan="2">
     219        <input name="googleidentity-signin" type="hidden" value="0" />
     220        <input type="submit" class="gsloginform"><xsl:attribute name="value"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'login_b')"/></xsl:attribute></input>
     221      </td>
     222    </tr>
     223    <xsl:if test="$googlesignin_client_id">
     224      <tr>
     225        <td colspan="2">
     226          <div class="hr-with-text">or</div>
     227        </td>
     228      </tr>
     229      <tr>
     230        <td colspan="2">
     231          <gsf:variable name="serlvetProtocol"><xsl:value-of select="/page/pageResponse/interfaceOptions/option[@name='servlet_protocol']/@value"/></gsf:variable>
     232          <gsf:div id="g_id_onload"
     233               data-client_id="{$googlesignin_client_id}"
     234               data-ux_mode="redirect">
     235        <xsl:attribute name="data-login_uri">
     236          <xsl:call-template name="generateGoogleIdentityLoginURL">
     237            <xsl:with-param name="servletProtocol" select="$servletProtocol"></xsl:with-param>
     238            <!--<xsl:with-param name="baseURL"         select="$baseURL"></xsl:with-param>-->
     239                    <xsl:with-param name="baseURL"         select="$base-href"></xsl:with-param>
     240            <!--<xsl:with-param name="redirectURL"     select="$redirectURL"></xsl:with-param> -->
     241            <xsl:with-param name="redirectURL"     select="$action-url"></xsl:with-param>
     242          </xsl:call-template>
     243         
     244        </xsl:attribute>
     245       
     246       
     247          </gsf:div>
     248         
     249          <gsf:div class="g_id_signin" data-type="standard"/>
     250         
     251        </td>
     252      </tr>
     253    </xsl:if>
     254   
     255      </table>
     256    </form>
     257
     258    <gsf:variable name="googleSigninClientId"><xsl:value-of select="/page/pageResponse/interfaceOptions/option[@name = 'googlesignin_client_id']/@value"/></gsf:variable>
     259
     260    <gsf:script>
     261
     262      function decodeJwtResponse(jwt) {
     263        // Split the JWT into its three parts
     264        var parts = jwt.split('.');
     265
     266        // Decode the header and payload parts using base64
     267        var header = JSON.parse(atob(parts[0]));
     268        var payload = JSON.parse(atob(parts[1]));
     269
     270        return payload;
     271           
     272      }
     273           
     274      function googleSigninHandleCredentialResponseUNUSED(response)
     275      {
     276        console.log("onGoogleSignin() called");
     277
     278        const responsePayload = decodeJwtResponse(response.credential);
     279
     280        console.log("ID: " + responsePayload.sub);
     281        console.log('Full Name: ' + responsePayload.name);
     282        console.log('Given Name: ' + responsePayload.given_name);
     283        console.log('Family Name: ' + responsePayload.family_name);
     284        console.log("Image URL: " + responsePayload.picture);
     285        console.log("Email: " + responsePayload.email);
     286        console.log("Email verified: " + responsePayload.email_verified);
     287
     288
     289         var google_fullname = responsePayload.name;
     290         console.log('Google-authenicated login as: ' + google_fullname);
     291
     292      }
     293
     294      $(document).ready(function() {
     295          $("#loginTable input[name=\"username\"]").focus();
     296      }
     297    </gsf:script>
     298
     299    <!--
     300    <script type="text/javascript">
     301      <xsl:text disable-output-escaping="yes">
     302      {
     303          $("#loginTable input[name=\"username\"]").focus();
     304      }
     305      </xsl:text>
     306    </script>
     307    -->
     308   
     309    </xsl:template>
     310 
    192311</xsl:stylesheet>
Note: See TracChangeset for help on using the changeset viewer.