【发布时间】:2018-04-03 08:12:01
【问题描述】:
希望看到一个可行的示例。搜索了很多,似乎无法让它在本地工作。始终显示隐私条款徽标,用户必须与验证码进行交互。
这是我创建的codepen 以加快速度。
使用不可见的 reCAPTCHA
要使用不可见的 reCAPTCHA,请创建一个 RecaptchaVerifier 对象,并将 size 参数设置为不可见,并指定提交登录表单的按钮的 ID。
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('sign-in-button', {
'size': 'invisible',
'callback': function(response) {
// reCAPTCHA solved, allow signInWithPhoneNumber.
onSignInSubmit();
}
});
基本上我对 init 的看法是什么:
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('phone-sign-in-recaptcha', {
'size': 'invisible',
'callback': function(response) {
// reCAPTCHA solved - will proceed with submit function
console.log(response);
},
'expired-callback': function() {
// Reset reCAPTCHA?
}
});
<form name="mobile" novalidate>
<label class="item item-input">
<i class="icon placeholder-icon"></i>
<input type="tel" name="number" ng-model="$ctrl.user.mobile">
</label>
<button id="sign-in-button" ng-click="$ctrl.onSignInSubmit(user.mobile)"></button>
</form>
<div id="phone-sign-in-recaptcha"></div>
这是提交时调用的函数:
ctrl.onSignInSubmit = function() {
var phoneNumber = '+1' + ctrl.user.mobile;
var appVerifier = window.recaptchaVerifier;
firebase.auth()
.signInWithPhoneNumber(phoneNumber, appVerifier)
.then(function(confirmationResult) {
ctrl.hasCodeToVerify = true;
console.log('confirmationResult', confirmationResult);
window.confirmationResult = confirmationResult;
}).catch(function(error) {
console.log('error', error);
});
};
【问题讨论】:
标签: angularjs firebase firebase-authentication