Skip to content

Instantly share code, notes, and snippets.

@CaptainYarb
Created May 8, 2018 16:45
Show Gist options
  • Save CaptainYarb/56787f5ebe68a5b8abfeb20264459bee to your computer and use it in GitHub Desktop.
Save CaptainYarb/56787f5ebe68a5b8abfeb20264459bee to your computer and use it in GitHub Desktop.
Ringcaptcha Angular Directive
app.directive('verification', function($interval, $timeout){
return {
scope: {
submit: '='
},
restrict: 'E',
template: '<div id="verificationPhone"></div>',
link: function($scope){
let widget = null;
let setup = function(){
if(!window.RingCaptcha){ return; }
widget = new window.RingCaptcha.Widget('#verificationPhone', "oqe5u8o4iceqy3ako2am", {
type: 'dual',
events: {
ready: function(){
// set number
let number = _.get(ngInjected, 'billing.client.numbers[0].number', '');
if(number){
$(this).find('.phone-input').val(number);
}
},
verified: function(){
let ele = $(this);
$timeout(function(){
// timeout is required to ensure these fields are properly set on the dom
let data = {
session_id: ele.find('input[name=ringcaptcha_session_id]').val(),
token: ele.find('input[name=ringcaptcha_pin_code]').val(),
number: ele.find('input[name=ringcaptcha_phone_number]').val()
};
if($scope.success && typeof($scope.success) === 'function'){
return $scope.success(data);
}
console.log('verified callback', data);
}, 100);
}
}
}).setup();
};
var doSetup = $interval(function(){
if(widget){
return $interval.cancel(doSetup);
}
setup();
}, 100);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment