/
app.js
120 lines (103 loc) · 3.85 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
// window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('sign-in-button', {
// 'size': 'invisible',
// 'callback': function(response) {
// // reCAPTCHA solved, allow signInWithPhoneNumber.
// onSignInSubmit();
// }
// });
// var recaptchaResponse = grecaptcha.getResponse(window.recaptchaWidgetId);
$('#verify_otp_model').hide()
$('#errorbox').hide()
// phone auth
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('getotp', {
'size': 'invisible',
'callback': function(response) {
// reCAPTCHA solved, allow signInWithPhoneNumber.
//onSignInSubmit();
}
});
// [END appVerifier]
recaptchaVerifier.render().then(function(widgetId) {
window.recaptchaWidgetId = widgetId;
// updateSignInButtonUI();
});
var aadhaar_no_phone_no = {
"7382537xxxxx": "915801xxxx",
"300000000000": "7276xxxxxx",
"<replace your aadhaar no here>": "<your phone number>",
}
function onSignInSubmit() {
window.signingIn = true;
$('#errorbox').hide();
// updateSignInButtonUI();
var phoneNumber = "+91" + aadhaar_no_phone_no[$('#aadhaar_no').val()];
//console.log(phoneNumber);
var d = new Date();
d.setTime(d.getTime() + (1*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = 'aadhaar' + "=" + $('#aadhaar_no').val() + ";" + expires + ";path=/";
$('#verifyc').text('Enter verification code send to '+phoneNumber)
var appVerifier = window.recaptchaVerifier;
firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)
.then(function (confirmationResult) {
// SMS sent. Prompt user to type the code from the message, then sign the
// user in with confirmationResult.confirm(code).
window.confirmationResult = confirmationResult;
window.signingIn = false;
// updateSignInButtonUI();
// $('.verification-code-form').show()
// $('#hidepf').hide()
$('#enter_aadhaarno').hide()
$('#verify_otp_model').show()
console.log('otp');
}).catch(function (error) {
// Error; SMS not sent
// $('.main_loader').hide()
//console.error('Error during signInWithPhoneNumber', error);
window.alert('error\n\n'+error);
window.signingIn = false;
//updateSignInFormUI();
//updateSignInButtonUI();
$('.verification-code-form').hide()
});
}
// Phone auth end //
$(verifyotp).click(function(){
var code = $('#verify_otp').val()
confirmationResult.confirm(code).then(function (result) {
// User signed in successfully.
var user = result.user;
window.verifyingCode = false;
//login success
console.log(user.uid);
var d = new Date();
d.setTime(d.getTime() + (1*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = 'show' + "=" + user.uid + ";" + expires + ";path=/";
window.location = '/info'
}).catch(function (error) {
// User couldn't sign in (bad verification code?)
console.error('Error while checking the verification code', error);
window.alert('Error while checking the verification code:\n\n'
+ error.code + '\n\n' + error.message);
window.verifyingCode = false;
$('#errorbox').show()
$('#error').text('Enter valid OTP')
});
});
$(getotp).click(function(){
if ($('#aadhaar_no').val()=="") {
$('#errorbox').show()
$('#error').text('Please Enter Aadhaar No')
}
else{
onSignInSubmit();
$('#errorbox').hide()
}
});