PageSourceSearch

https://app.wegodoo.com/Scripts/Firebase/GoogleFbAuthentication.js

js wegodoo.com collected 2026-10-07 14:47:59 UTC 21,812 bytes, 486 lines download raw bytes

1// WGD-Analytics: helper for Apple sign_up. The SERVER (response.IsNewUser) is the single source of
2// truth for "new WeGoDoo user" — it checks our own DB and returns true exactly once, on the request
3// that creates the account, so it is inherently deduped.
4//
5// We intentionally do NOT also require Apple's event.detail.user (first-consent), and we do NOT keep a
6// localStorage guard. Both are keyed to Apple/browser state that is NOT reset when a WeGoDoo account is
7// deleted: Apple only sends the user object on first consent per Apple ID, so after a delete + re-signup
8// it sends nothing and the localStorage key still exists — a real new signup would be silently dropped.
9// Trust the authoritative server signal instead.
10function WGDMaybeLogAppleSignUp(appleEvent, serverIsNewUser) {
11    try {
12        if (!window.WGDAnalytics) return;
13        if (serverIsNewUser !== true) return;
14        WGDAnalytics.logEvent('sign_up', { method: 'apple' });
15        // H57 E3: Meta Pixel CompleteRegistration — apple first-login.
16        try {
17            if (typeof CallFbPixel === 'function') {
18                CallFbPixel('CompleteRegistration', { content_name: 'apple', status: true });
19            }
20        } catch (ePx) { /* silent */ }
21    } catch (e) {
22        console.warn('[WGDAnalytics] apple sign_up failed:', e && e.message);
23    }
24}
25
26// WGD-Analytics: helper for social sign_up (Google / Facebook). The SERVER (response.IsNewUser) is the
27// single source of truth for "new WeGoDoo user": it checks our own DB and returns true exactly once —
28// on the request that actually creates the account — so it is inherently deduped, and it correctly
29// handles the "old email account, first Google login" case (returns false -> no fire).
30//
31// We intentionally do NOT also require Firebase's additionalUserInfo.isNewUser, and we do NOT keep a
32// localStorage guard. Both are keyed to Firebase/browser state that is NOT reset when a WeGoDoo account
33// is deleted (or a Google grant revoked): the Firebase Auth user record lives on, so a genuine re-signup
34// reports isNewUser=false, and the localStorage key (keyed to the stable Firebase uid) still exists — so
35// a real new signup would be silently dropped. Trust the authoritative server signal instead.
36function WGDMaybeLogSocialSignUp(firebaseResult, methodLabel, serverIsNewUser) {
37    try {
38        if (!window.WGDAnalytics) return;
39        if (serverIsNewUser !== true) return;
40        WGDAnalytics.logEvent('sign_up', { method: methodLabel });
41        // H57 E3: Meta Pixel CompleteRegistration — social first-login.
42        // Normalize 'gmail' → 'google' to match mobile spec (intro.dart:1478).
43        try {
44            if (typeof CallFbPixel === 'function') {
45                var pxProvider = (methodLabel === 'gmail') ? 'google' : methodLabel;
46                CallFbPixel('CompleteRegistration', { content_name: pxProvider, status: true });
47            }
48        } catch (ePx) { /* silent */ }
49    } catch (e) {
50        console.warn('[WGDAnalytics] social sign_up failed:', e && e.message);
51    }
52}
53
54function GoogleSignin() {
55
56    var provider = new firebase.auth.GoogleAuthProvider();
57    provider.addScope('email');
58    provider.addScope('profile');
59    provider.setCustomParameters({
60        prompt: 'select_account',
61    });
62    firebase.auth().languageCode = 'en';
63    firebase.auth().signInWithPopup(provider).then(function (result) {
64
65        if (result.user) {
66            result.user.getIdToken().then(function (idToken) {
67
68                $.ajax({
69                    type: "POST",
70                    url: "/Login/GoogleSignIn",
71                    data: {
72                        Token: idToken,
73                        ltdplan: (window.ltdPlanParam || '')
74                    },
75                    success: function (response) {
76                        console.log(response);
77                        var redirect = "/Home/Index";
78                        if (response.success == "true") {
79                            // WGD-Analytics: server confirmed the account; fire sign_up only if server says this request created a new WeGoDoo user.
80                            WGDMaybeLogSocialSignUp(result, 'gmail', response.IsNewUser === true);
81                            window.location.href = redirect;
82                        }
83                        else if (response.success == "Redirect") {
84                            // Issue #6: a brand-new Google user is redirected into onboarding (not the
85                            // success=="true" branch above), so fire sign_up here too — before navigating —
86                            // gated by the server's authoritative IsNewUser. Without this, Google signups
87                            // that route through onboarding are never tracked.
88                            WGDMaybeLogSocialSignUp(result, 'gmail', response.IsNewUser === true);
89                            window.location.href = response.Redirecturl;
90                        } else { window.location.href = redirect; }
91
92
93                    },
94                    error: function (da) {
95                        console.log(da);
96                    }
97                });
98            });
99        }
100        //setTimeout(function () {
101        //    if (result.credential) {
102        //        var token = result.credential.accessToken;
103        //        var secret = result.credential.secret;
104        //        SaveGoogleSignin(result.user);
105        //    }
106        //}, 1000);
107    }).catch(function (error) {
108        var errorCode = error.code;
109        var errorMessage = error.message;
110        if (errorCode === 'auth/account-exists-with-different-credential') {
111            alert('You have already signed up with a different auth provider for that email.');
112        } else {
113            console.error(error);
114        }
115
116        $('#divGoogle').css('background-color', 'white');
117        $('.divGoogleText').css('color', '#344054');
118        $('.imgGoogle').css('filter', '');
119    });
120}
121
122SaveGoogleSignin = function (user) {
123    if (user) {
124        var providerData = user.providerData;
125        var obj = {
126            Name: providerData[0].displayName,
127            Email: providerData[0].email,
128            SocialLoginId: providerData[0].uid,
129            Photo: providerData[0].photoURL
130        };
131        $.ajax({
132            type: "POST",
133            url: "/Login/GoogleSignIn",
134            data: JSON.stringify(obj),
135            contentType: 'application/json; charset=utf-8',
136            success: function (response) {
137                console.log(response);
138                var redirect = "/Home/Index";
139                if (response.success == "true") {
140                    window.location.href = redirect;
141                }
142                else if (response.success == "Redirect") {
143                    window.location.href = response.Redirecturl;
144                } else { window.location.href = redirect; }
145
146
147            },
148            error: function (da) {
149                console.log(da);
150            }
151        });
152    }
153}, function (error) {
154    console.log(error);
155};
156
157function FacebookSignin() {
158
159    var provider = new firebase.auth.FacebookAuthProvider();
160    provider.addScope('public_profile');
161    provider.addScope('email');
162    provider.setCustomParameters({
163        display: 'popup'
164    });
165
166    firebase.auth().signInWithPopup(provider).then(function (result) {
167
168        if (result.user) {
169
170            var providerData = result.user.providerData;
171            var obj = {
172                Name: providerData[0].displayName,
173                Email: providerData[0].email,
174                SocialLoginId: providerData[0].uid,
175                Photo: providerData[0].photoURL
176            };
177
178            result.user.getIdToken().then(function (idToken) {
179
180                $.ajax({
181                    type: "POST",
182                    url: "/Login/FacebookSignIn",
183                    data: {
184                        Token: idToken,
185                        ltdplan: (window.ltdPlanParam || '')
186                    },
187                    success: function (response) {
188                        var redirect = "/Home/Index";
189                        if (response.success == "true") {
190                            // WGD-Analytics: server confirmed the account; fire sign_up only if server says this request created a new WeGoDoo user.
191                            WGDMaybeLogSocialSignUp(result, 'facebook', response.IsNewUser === true);
192                            window.location.href = redirect;
193                        } else if (response.success == "Please verify your Email..!!") {
194                            swal({ title: "alert!", html: true, text: decodeEntities("Please verify your Email..!!") });
195                        }
196                        else if (response.success == "Redirect") {
197                            // Issue #6: a brand-new Facebook user is redirected into onboarding (not the
198                            // success=="true" branch above), so fire sign_up here too — before navigating —
199                            // gated by the server's authoritative IsNewUser.
200                            WGDMaybeLogSocialSignUp(result, 'facebook', response.IsNewUser === true);
201                            window.location.href = response.Redirecturl;
202                        } else if (response.success == "Email") {
203                            $('#emailAskModal2').find('#ModelName2').val(obj.Name);
204                            $('#emailAskModal2').find('#ModelSocialLoginId2').val(obj.SocialLoginId);
205                            $('#emailAskModal2').find('#ModelPhoto2').val(obj.Photo);
206                            $('#emailAskModal2').find('#EmailAddress2').val("");
207                            /*$('#emailAskModal2').modal("show");*/
208                            $('#alreadyAccountAskModal').modal("show");
209                            $(document).find('#emailAskModal2').find('#EmailError').html('');
210                            $(document).find('#emailAskModal2').find('#EmailError').hide();
211                        }
212                        else { window.location.href = redirect; }
213                    },
214                    error: function (xmlHttpRequest, errorText, thrownError) {
215                        console.log(errorText);
216                    }
217                });
218
219            });
220        }
221        //var token = result.credential.accessToken;
222        //var user = result.user;
223        //var user_data = result.user.providerData[0];
224        //var currentUid = user_data.uid;
225
226        //setTimeout(function () {
227        //    SaveFBSignin(result.user);
228        //}, 1000);
229    }).catch(function (error) {
230        var errorCode = error.code;
231        var errorMessage = error.message;
232        if (errorCode === 'auth/account-exists-with-different-credential') {
233            alert('You have already signed up with a different auth provider for that email.');
234        } else {
235            console.log(error);
236        }
237
238        $('#divFacebook').css('background-color', 'white');
239        $('.divFacebookText').css('color', '#344054');
240        $('.imgFacebook').css('filter', '');
241    });
242}
243
244SaveFBSignin = function (user) {
245    if (user) {
246        var providerData = user.providerData;
247        var obj = {
248            Name: providerData[0].displayName,
249            Email: providerData[0].email,
250            SocialLoginId: providerData[0].uid,
251            Photo: providerData[0].photoURL,
252            Mobile: providerData[0].phoneNumber
253        };
254        obj.Email = (obj.Email == undefined || obj.Email == null) ? "" : obj.Email;
255        if (obj.Email.trim() == "") {
256            $.ajax({
257                type: "POST",
258                url: "/Login/FacebookSignIn",
259                data: JSON.stringify(obj),
260                contentType: 'application/json; charset=utf-8',
261                success: function (response) {
262                    var redirect = "/Home/Index";
263                    if (response.success == "true") {
264                        window.location.href = redirect;
265                    } else if (response.success == "Please verify your Email..!!") {
266                        swal({ title: "alert!", html: true, text: decodeEntities("Please verify your Email..!!") });
267                    }
268                    else if (response.success == "Redirect") {
269                        window.location.href = response.Redirecturl;
270                    } else if (response.success == "Email") {
271                        $('#emailAskModal2').find('#ModelName2').val(obj.Name);
272                        $('#emailAskModal2').find('#ModelSocialLoginId2').val(obj.SocialLoginId);
273                        $('#emailAskModal2').find('#ModelPhoto2').val(obj.Photo);
274                        $('#emailAskModal2').find('#EmailAddress2').val("");
275                        $('#emailAskModal2').modal("show");
276                        $(document).find('#emailAskModal2').find('#EmailError').html('');
277                        $(document).find('#emailAskModal2').find('#EmailError').hide();
278                    }
279                    else { window.location.href = redirect; }
280                },
281                error: function (xmlHttpRequest, errorText, thrownError) {
282                    console.log(errorText);
283                }
284            });
285
286        } else {
287            $.ajax({
288                type: "POST",
289                url: "/Login/FacebookSignIn",
290                data: JSON.stringify(obj),
291                contentType: 'application/json; charset=utf-8',
292                success: function (response) {
293                    var redirect = "/Home/Index";
294                    if (response.success == "true") {
295                        window.location.href = redirect;
296                    }
297                    else if (response.success == "Redirect") {
298                        window.location.href = response.Redirecturl;
299                    }
300                    else { window.location.href = redirect; }
301
302                    //if (response.success == "true") {
303                    //    window.location.href = "/Home/Index";
304                    //} 
305                },
306                error: function (xmlHttpRequest, errorText, thrownError) {
307                    console.log(errorText);
308                }
309            });
310        }
311    }
312}, function (error) {
313    console.log(error);
314};
315
316//function GoogleSignOut() {
317//    firebase.auth().signOut().then(function () {
318//        window.location = "https://mail.google.com/mail/u/0/?logout&hl=en";
319//    }, function (error) {
320//        console.log('Signout Failed')
321//        swal({
322//            type: 'error',
323//            title: 'Error',
324//            text: error.text,
325//        });
326//    });
327//}
328
329//function FacebookSignout() {
330//    FB.logout(function (response) {
331//        console.log('FB Signout successfull!')
332//    });
333//}
334
335function trapModelEvents() {
336    $('#emailAskModal').on('show.bs.modal',
337        function (event) {
338            $('#EmailAddress').val('');
339            $('#EmailError1').hide();
340        });
341
342    $('#EmailAddress').blur(function () { checkEmail(); });
343}
344
345function VerifyEmail() {
346    if (checkEmail()) {
347        var obj = {
348            Name: $('#emailAskModal').find('#ModelName').val(),
349            Email: $('#emailAskModal').find('#EmailAddress').val(),
350            SocialLoginId: $('#emailAskModal').find('#ModelSocialLoginId').val(),
351            Photo: $('#emailAskModal').find('#ModelPhoto').val()
352        };
353        $.ajax({
354            type: "POST",
355            url: "/Login/FacebookMobileSignIn",
356            data: JSON.stringify(obj),
357            contentType: 'application/json; charset=utf-8',
358            success: function (response) {
359                if (response.success == "true") {
360                    $("#btnClose").trigger('click');
361                    window.location.href = "/Home/Index";
362                } else if (response.success == "false") {
363                    $('#emailAskModal').find("#btnClose").trigger('click');
364                    swal({ title: "Success!", html: true, text: decodeEntities(response.message) });
365                } else {
366                    $('#emailAskModal').find('#EmailError1').html(response.message);
367                    $('#emailAskModal').find('#EmailError1').show();
368                }
369            },
370            error: function (xmlHttpRequest, errorText, thrownError) {
371                console.log(errorText);
372            }
373        });
374    }
375}
376
377function VerifyFbEmail() {
378    if (checkEmail2()) {
379        var obj = {
380            Name: $('#emailAskModal2').find('#ModelName2').val(),
381            Email: $('#emailAskModal2').find('#EmailAddress2').val(),
382            SocialLoginId: $('#emailAskModal2').find('#ModelSocialLoginId2').val(),
383            Photo: $('#emailAskModal2').find('#ModelPhoto2').val(),
384            IsExist: $('#emailAskModal2').find('#IsExist').val()
385        };
386
387        $.ajax({
388            type: "POST",
389            url: "/Login/FacebookMobileSignIn",
390            data: JSON.stringify(obj),
391            contentType: 'application/json; charset=utf-8',
392            success: function (response) {
393                if (response.success == "true") {
394                    $('#emailAskModal2').find("#btnClose").trigger('click');
395                    window.location.href = "/Home/Index";
396                } else if (response.success == "false") {
397                    $('#emailAskModal2').find("#btnClose").trigger('click');
398                    swal({
399                        title: "Please verify your email", html: true, text: decodeEntities("To help you log in via Facebook in the future, we need your email address for verification." +
400                            "This is because your Facebook account is associated with a mobile number.Kindly provide your email to proceed.")
401                    });
402                } else if (response.success == "Not valid") {
403                    // Redesigned "email already registered" dialog (matches mobile Dialog 2).
404                    // Hide the email prompt first, then show the exists dialog once it is fully
405                    // hidden, so Bootstrap doesn't leave a stacked backdrop behind.
406                    $('#emailAskModal2').one('hidden.bs.modal', function () {
407                        $('#fbEmailExistsModal').modal('show');
408                    });
409                    $('#emailAskModal2').modal('hide');
410                } else {
411                    $('#emailAskModal2').find("#btnClose").trigger('click');
412                    swal({ title: "alert!", html: true, text: decodeEntities(response.message) });
413                }
414            },
415            error: function (xmlHttpRequest, errorText, thrownError) {
416                console.log(errorText);
417            }
418        });
419    }
420}
421
422function checkEmail() {
423    var myemail = $.trim($('#emailAskModal').find('#EmailAddress2').val());
424    if (myemail.length != 0) {
425        var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
426        if (!emailPattern.test(myemail)) {
427            $(document).find('#emailAskModal').find('#EmailError1').html('Please enter valid Email');
428            $(document).find('#emailAskModal').find('#EmailError1').show();
429            return false;
430        }
431        else {
432            $(document).find('#emailAskModal').find('#EmailError1').html('');
433            $(document).find('#emailAskModal').find('#EmailError1').hide();
434            return true;
435        }
436    }
437    else {
438        $(document).find('#emailAskModal').find('#EmailError1').html('Email is Required');
439        $(document).find('#emailAskModal').find('#EmailError1').show();
440        return false;
441    }
442}
443
444function checkEmail2() {
445    var $field = $('#emailAskModal2').find('#wgdFbField2');
446    var $err = $('#emailAskModal2').find('#EmailError');
447    var myemail = $.trim($('#emailAskModal2').find('#EmailAddress2').val());
448    if (myemail.length != 0) {
449        var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
450        if (!emailPattern.test(myemail)) {
451            $err.html('Please enter a valid email address.').show();
452            $field.addClass('is-invalid');
453            return false;
454        }
455        else {
456            $err.html('').hide();
457            $field.removeClass('is-invalid');
458            return true;
459        }
460    }
461    else {
462        $err.html('Please enter your email address.').show();
463        $field.addClass('is-invalid');
464        return false;
465    }
466}
467
468// Redesigned "email already registered" dialog — "Try another email" reopens the email
469// prompt with a cleared field (matches mobile Dialog 2 behavior). Delegated so it works
470// on both Login and Signup pages that include this script.
471$(document).on('click', '#btnFbTryAnotherEmail', function () {
472    $('#fbEmailExistsModal').one('hidden.bs.modal', function () {
473        var $modal = $('#emailAskModal2');
474        $modal.find('#EmailAddress2').val('');
475        $modal.find('#EmailError').html('').hide();
476        $modal.find('#wgdFbField2').removeClass('is-invalid');
477        $modal.modal('show');
478    });
479    $('#fbEmailExistsModal').modal('hide');
480});
481
482// Clear any stale validation state each time the email prompt opens.
483$(document).on('show.bs.modal', '#emailAskModal2', function () {
484    $(this).find('#EmailError').html('').hide();
485    $(this).find('#wgdFbField2').removeClass('is-invalid');
486});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.