Changeset 37391
- Timestamp:
- 2023-03-02T23:09:46+13:00 (3 weeks ago)
- Location:
- main/trunk/greenstone3/web/interfaces/default/transform
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/transform/layouts/header.xsl
r37266 r37391 113 113 function gslogout(logout_action_url) { 114 114 if (googlesignin_client_id != '') { 115 googleLogout(); 115 //googleLogout(); 116 console.log("Need to implement new Google Identiy Logout function?????"); 116 117 } 117 118 window.location = logout_action_url; … … 208 209 209 210 <xsl:template name="addGoogleSignOn"> 210 <meta name="google-signin-client_id" content="{$googlesignin_client_id}" /> 211 212 <script> 213 <xsl:text disable-output-escaping="yes"> 214 215 function googleSigninInit() { 216 gapi.load('auth2', function() { 217 var auth2 = gapi.auth2.init({ 218 client_id: googlesignin_client_id, 219 //scope: 'email' // don't need to top up 'profile' with 'email' as not used client side (email is retrieved via GS3 Servlet) 220 }) 221 .then(function() { 222 if (typeof optGoogleAuth2InitCallback === "function"){ 223 optGoogleAuth2InitCallback(); 224 } 225 }); 226 }); 227 } 228 229 function googleLogout() { 230 var auth2 = gapi.auth2.getAuthInstance(); 231 // Use 'disconnect()' rather than 'signOut()' as this does a deeper logout 232 // that revokes the user's "Google granted" permission. 233 // This makes it easier, when using the same browser, to login into Greenstone3 234 // using a differeng Google sign-in account 235 236 auth2.disconnect().then(function () { 237 console.log("Google-authenticated User signed out"); 238 }); 239 return false; 240 } 241 </xsl:text> 242 </script> 243 <script src="https://apis.google.com/js/platform.js?onload=googleSigninInit" async="async" defer="defer" ><xsl:text> </xsl:text></script> 211 <meta name="google-signin-client_id--DEPRECATED" content="{$googlesignin_client_id}" /> 212 <script src="https://accounts.google.com/gsi/client" async="async" defer="defer" ><xsl:text> </xsl:text></script> 244 213 245 214 </xsl:template> … … 486 455 else 487 456 { 488 menu = $("< UL>")457 menu = $("<ul>") 489 458 .css("position", "absolute") 490 459 .css("display", "block") … … 523 492 var editingLink = $("<a>") 524 493 .attr("href", "javascript:;"); 525 var editingButton = $("< LI>")494 var editingButton = $("<li>") 526 495 .addClass("ui-state-default") 527 496 .css("padding", "3px")</xsl:text> … … 558 527 .attr("href", logout_javascript_call); 559 528 560 var logoutButton = $("< LI>")529 var logoutButton = $("<li>") 561 530 .css("padding", "3px") 562 531 .html("</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'menu.logout')"/><xsl:text disable-output-escaping="yes">") … … 599 568 <xsl:value-of select="@value"/> 600 569 </xsl:if> 601 </xsl:for-each> 602 570 </xsl:for-each> 603 571 </xsl:template> 604 572 … … 609 577 <xsl:variable name="url" select="/page/pageRequest/@fullURL"/> 610 578 <xsl:variable name="beforeLogout" select="substring-before($url, '&amp;logout=')"/> 611 612 579 <xsl:variable name="tmpAfter" select="substring-after($url, '&amp;logout=')"/> 580 <xsl:variable name="afterLogout" select="substring-after($tmpAfter, '&amp;')"/> 613 581 <xsl:variable name="beforeHash" select="substring-before($url, '#')"/> 614 582 <xsl:variable name="afterHash" select="substring-after($url, '#')"/> -
main/trunk/greenstone3/web/interfaces/default/transform/pages/login.xsl
r35820 r37391 11 11 12 12 <!-- use the 'main' layout --> 13 <xsl:i ncludehref="layouts/main.xsl"/>13 <xsl:import href="layouts/main.xsl"/> 14 14 15 15 <!-- set page title --> … … 48 48 input.gsloginform[type=submit] { 49 49 float: right; 50 margin-right: 10px;50 margin-right: 3px; 51 51 margin-top: 5px; 52 52 width: 80px; … … 95 95 <tr> 96 96 <td colspan="2"> 97 <input name="googleidentity-signin" type="hidden" value="0" /> 97 98 <input type="submit" class="gsloginform"><xsl:attribute name="value"><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'login_b')"/></xsl:attribute></input> 98 99 </td> … … 106 107 <tr> 107 108 <td colspan="2"> 108 <input type="hidden" id="googlesignin_id_token" name="googlesignin_id_token"></input> 109 <gsf:div id="mygoogle-signin2" /> 109 <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> 111 <gsf:variable name="redirectURL"><xsl:value-of select="/page/pageRequest/paramList/param[@name = 'redirectURL']/@value"/></gsf:variable> 112 <gsf:div id="g_id_onload" 113 data-client_id="{$googlesignin_client_id}" 114 data-ux_mode="redirect" 115 data-login_uri="{$servletProtocol}:{$baseURL}{$redirectURL}&googleidentity-signin=1"> 116 </gsf:div> 117 <gsf:div class="g_id_signin" data-type="standard"/> 118 110 119 </td> 111 120 </tr> … … 114 123 </table> 115 124 </form> 116 125 117 126 <gsf:variable name="googleSigninClientId"><xsl:value-of select="/page/pageResponse/interfaceOptions/option[@name = 'googlesignin_client_id']/@value"/></gsf:variable> 118 127 119 128 <gsf:script> 120 121 function onGoogleSigninSuccess(googleUser) 129 130 function decodeJwtResponse(jwt) { 131 // Split the JWT into its three parts 132 var parts = jwt.split('.'); 133 134 // Decode the header and payload parts using base64 135 var header = JSON.parse(atob(parts[0])); 136 var payload = JSON.parse(atob(parts[1])); 137 138 // Return an object containing the decoded header and payload 139 //return { 140 // header: header, 141 // payload: payload 142 //}; 143 return payload; 144 145 } 146 147 function googleSigninHandleCredentialResponseUNUSED(response) 122 148 { 149 console.log("onGoogleSignin() called"); 123 150 124 var google_fullname = googleUser.getBasicProfile().getName(); 151 const responsePayload = decodeJwtResponse(response.credential); 152 153 console.log("ID: " + responsePayload.sub); 154 console.log('Full Name: ' + responsePayload.name); 155 console.log('Given Name: ' + responsePayload.given_name); 156 console.log('Family Name: ' + responsePayload.family_name); 157 console.log("Image URL: " + responsePayload.picture); 158 console.log("Email: " + responsePayload.email); 159 console.log("Email verified: " + responsePayload.email_verified); 160 161 162 var google_fullname = responsePayload.name; 125 163 console.log('Google-authenicated login as: ' + google_fullname); 126 164 127 var googlesignin_id_token = googleUser.getAuthResponse().id_token;128 // console.log('Google ID Token: ' + googlesignin_id_token);165 //var googlesignin_id_token = googleUser.getAuthResponse().id_token; 166 // //console.log('Google ID Token: ' + googlesignin_id_token); 129 167 130 $("#googlesignin_id_token").val(googlesignin_id_token); 131 $("#login-form").submit(); 132 } 168 // $("#googlesignin_id_token").val(googlesignin_id_token); 169 // $("#login-form").submit(); 133 170 134 function onGoogleSigninFailure(error) 135 { 136 console.error(error); 137 $("#googlesignin_id_token").val(""); 138 } 139 140 function renderButton() 141 { 142 var auth2 = gapi.auth2.getAuthInstance(); 143 if ((gs.variables.loginErrorMessage != "") && auth2.isSignedIn.get()) { 144 145 // IF a Greenstone-login error is being shown on the page (loginErrorMessage) 146 // AND Google logged-in (isSignedIn) 147 // => THEN need to trigger a Google-logout, otherwise the 148 // the block of code below automatically tiggers a login 149 // attempt (using the Google credentials), which (if allowed to 150 // happen) then sets up a endless loop of login attempts 151 googleLogout(); 152 } 153 154 gapi.signin2.render('mygoogle-signin2', { 155 'scope': 'profile email', 156 'width': 240, 157 'height': 50, 158 'longtitle': true, 159 'theme': 'dark', 160 'onsuccess': onGoogleSigninSuccess, 161 'onfailure': onGoogleSigninFailure 162 }); 163 } 164 165 function optGoogleAuth2InitCallback() { 166 if (gs.variables['googleSigninClientId']) { 167 // Only trigger the Google Signin button if a client-id has been set in servlet.xml 168 renderButton(); 169 } 171 170 172 } 171 173
Note:
See TracChangeset
for help on using the changeset viewer.