Skip to content

Commit

Permalink
Google Sign-On with new libraries (#5777)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saparbek-Nagashibekov authored and bradymiller committed Oct 12, 2022
1 parent 6cd8198 commit 3bd4b97
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions templates/login/login_core.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
<head>
{% if displayGoogleSignin %}
<meta name="google-signin-client_id" content="{{ googleSigninClientID|attr }}">
<script src="https://accounts.google.com/gsi/client" async defer></script>
<div id="g_id_onload"
data-client_id="{{ googleSigninClientID|attr }}"
data-callback="onSignInSuccess" data-auto_prompt="false">
</div>
{% endif %}

<title>{{ title|text }} {{ "Login"|xlt }}</title>
{% block head %}{% endblock %}
<script src="{{ webroot|attr }}/interface/product_registration/product_registration_service.js?v={{ assetVersion|attr }}"></script>
Expand Down Expand Up @@ -103,7 +109,8 @@
</div>
{% endif %}

<div class="form-group d-flex justify-content-end">
<div class="form-group d-flex " style="justify-content: space-between !important;" >
{% if displayGoogleSignin %} <div class="g_id_signin" data-type="standard" ></div> {% endif %}
<button id="login-button" class="btn btn-primary" type="submit" onclick="transmit_form(this)">{{ "Login"|xlt }}</button>
</div>

Expand Down Expand Up @@ -203,23 +210,22 @@
// Click-handler for signin button
function do_google_signin() {
google_signin = true;
google_signin = true;
}
// When Google sign-in successful, sign in to the app, but only
// if the button was clicked (otherwise we would automatically login)
function onSignInSuccess(googleUser) {
if (google_signin === true) {
const auth_response = googleUser.getAuthResponse();
const id_token = auth_response.id_token;
const id_token = googleUser.credential;
$('.login-failure').hide();
$('#used-google-signin').val(true);
$('#google-signin-token').val(id_token);
$('#google-signout').show();
$('#standard-auth-username, #standard-auth-password').hide();
var element = document.getElementById('login-button');
transmit_form(element);
}
}
function onSignInFailure(error) {
Expand Down Expand Up @@ -250,18 +256,5 @@
});
}
$.getScript('https://apis.google.com/js/platform.js', function (data, textStatus, jqxh) {
// When the auth2 library is loaded, log out so the user has to sign into google
gapi.load('auth2', function () {
gapi.auth2.init().then(function () {
signOut();
});
});
// Render the "Sign in with Google" button
renderButton();
}).fail(function (jqxhr, settings, exception) {
$('#google-signin-service-unreachable-alert').show();
});
</script>
{% endif %}

0 comments on commit 3bd4b97

Please sign in to comment.