1
當用戶未連接時,我們是否可以禁用自動驗證?Google登錄:禁用自動驗證
換句話說,我希望用戶只有在點擊按鈕時才能連接。
這裏是我的代碼:
<script src="https://apis.google.com/js/platform.js?onload=onLoadGoogle" async defer></script>
<script>
function onLoadGoogle() {
gapi.load('auth2', function() {
gapi.auth2.init();
});
}
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
// The ID token you need to pass to your backend:
var id_token = googleUser.getAuthResponse().id_token;
if (gapi.auth2.getAuthInstance().isSignedIn.get()) {
$.ajax({
type: 'POST',
url: $('#yBaseUrl').val() + '/ControllerAuthentification/getMailAllCompte',
data: {
mail: profile.getEmail()
},
dataType: "json",
success: function (data) {
if (data == 1) {
window.location.href = "index.php/ControllerAccueil";
},
error: function (e) {
if (e.responseText == "") {
toastr.info("Vous n'êtes pas inscrit par ce compte google!!", 'Notification');
}
console.log(e.responseText);
}
});
}
}
;
</script>
這裏的問題是,在onSignIn連接的功能已經被製成,因此總是
gapi.auth2.getAuthInstance().isSignedIn.get()
返回true