PageSourceSearch

https://signup.acorn.tv/js/CreateAccountController.js

js acorn.tv collected 2026-09-24 17:40:46 UTC 18,664 bytes, 507 lines download raw bytes

1SignupApp.controller('CreateAccountController', ['$scope', '$http', '$sce', '$filter', '$location', 'mp', 'createAccount', 'signup', 'captcha', CreateAccountController]);
2
3function CreateAccountController($scope, $http, $sce, $filter, $location, mp, createAccount, signup, captcha) {
4  var acornTVHomeLink = "";
5  var signinPage = "signin.jsp";
6  var locale = 'en'; // docCookies.getItem('ATVLocale') || 'en';
7  $scope.rokuSpecial = false;
8  $scope.costcoSpecial = false;
9  $scope.mp = mp;
10  $scope.createAccount = createAccount;
11  $scope.signup = signup;
12  $scope.captcha = captcha;
13  $scope.errorMessage = ''; //$sce.trustAsHtml(polyglot.t('OOPS'));//polyglot.t("ENTERED-INCORRECT");
14  $scope.termLink = (locale === 'es') ? 'https://www.amcnetworks.com/terminos-y-condiciones/' : 'https://www.amcnetworks.com/terms-of-use/';
15  $scope.privacyLink = (locale === 'es') ? 'https://www.amcnetworks.com/privacidad/' : 'https://www.amcnetworks.com/privacy-policy/';
16  $scope.cookieLink = (locale === 'es') ? 'https://www.amcnetworks.com/politicas-de-cookies/' : 'https://www.amcnetworks.com/cookies-2/';
17  $scope.customerID = ''
18  $scope.promoCode = '';
19  $scope.csrfToken = '';
20  $scope.captchaToken = '';
21  $scope.captchaVersion = 'v3';
22  $scope.isCaptchaV2 = false;
23  $scope.isCaptchaTested = false;
24
25  $scope.validateCreateAccount = function () { //remove manual invalids to try again.
26    $scope.promoCodeError = false;
27
28    if (isValidFormCreateAccount()) {
29      if ($scope.promoCode && $scope.promoType && $scope.promoType === "gift") {
30        $scope.captcha.onCaptchaTokenCreate($scope.isCaptchaTested, function (token) {
31          $scope.captchaToken = token;
32          $scope.captchaVersion = ($scope.isCaptchaTested) ? 'v2' : 'v3';
33          $scope.submitCreateAccount();
34        });
35      } else {
36        $scope.submitCreateAccount();
37      }
38    }
39  };
40
41  $scope.redirectToSignin = function ($event) {
42    $event.preventDefault();
43    var signinLink = '../signin.jsp';
44    if (location.search && location.search.length > 1) {
45      signinLink = signinLink + '?' + encodeQueryData(queryStringToObject());
46    }
47    location.href = signinLink;
48  }
49
50  $scope.setPolicy = function () {
51    $scope.Policy = !$scope.Policy;
52  };
53
54  $scope.setMktgoptin = function () {
55    $scope.Mktgoptin = !$scope.Mktgoptin;
56  };
57
58  var isValidFormCreateAccount = function () {
59    var validCreateAccount = true;
60
61    var keyError = Object.keys($scope.createForm.$error)[0];
62
63    if (keyError && $scope.createForm.$error[keyError] && $scope.createForm.$error[keyError].length) {
64      validCreateAccount = false;
65
66      errors = $scope.createForm.$error[keyError];
67
68      if (keyError === 'email' || (keyError == 'pattern' && errors[0].$name === 'Username')) {
69        $scope.errorMessage = $sce.trustAsHtml(polyglot.t('INVALID-EMAIL-ERROR'));
70      } else if (keyError == 'pattern') {
71        $scope.errorMessage = $sce.trustAsHtml(polyglot.t('INVALID-PASSWORD-ERROR'));
72      } else if (keyError == 'required') {
73        var message = polyglot.t('ATTRIBUTE-REQUIRED', { "attribute": errors[0].$name });
74        if (errors[0].$name === 'Username') {
75          message = polyglot.t("REQUIRED-EMAIL-ERROR");
76        } else if (errors[0].$name === 'Password') {
77          message = polyglot.t("REQUIRED-PASSWORD-ERROR");
78        } else if (errors[0].$name === 'Policy') {
79          message = polyglot.t("REQUIRED-POLICY-ERROR");
80        }
81
82        $scope.errorMessage = $sce.trustAsHtml(message);
83
84      } else {
85        $scope.errorMessage = $sce.trustAsHtml(polyglot.t('OOPS'));
86      }
87
88      $('html, body').animate({ scrollTop: 0 }, 'slow');
89    }
90
91    return validCreateAccount;
92  }
93
94
95
96  var setAcornHomeLinks = function () {
97    var currentURL = location.hostname;
98    if (currentURL.indexOf("signup") != -1) {
99      var subDomain = currentURL.split('.');
100      if (subDomain.length > 2) {
101        subDomain = subDomain[0];
102      }
103      acornTVHomeLink = currentURL.replace(subDomain + '.', '//');
104    }
105    $(".AcornAppLink").each(function () {
106      var $this = $(this);
107      var qsvalue = $this.data("qs");
108      $this.attr("href", acornTVHomeLink + qsvalue);
109    });
110  };
111
112  var setTermsAndPromoCheckboxes = function (country) {
113    // if (country === "US" || country === "CA") {
114    $scope.Policy = false;
115    $scope.Mktgoptin = true;
116    // }
117  }
118
119  // for Vizio /createaccount-ac/ page
120  function getCountries() {
121    var getCountries = $scope.signup.getPrices();
122    getCountries
123      .then(function (resp) {
124        var data = resp.data;
125
126        $scope.countryCode = data.Country;
127
128        setTermsAndPromoCheckboxes(data.Country);
129
130        if (data.StripePlans) {
131          var stripePlans = data.StripePlans;
132
133          // Set up default cost and text for the current country.
134          for (var i = 0; i < stripePlans.length; i++) {
135            var stripePlansDefault = stripePlans[i];
136            if (parseInt(stripePlansDefault.Term, 10) === 30) {
137              $scope.costText = "Watch free for 7 days. Just " + stripePlansDefault.SubscriptionAmount + " " + stripePlansDefault.CurrencyDesc + "/month after that. No commitment: cancel within 7 days to avoid payment.";
138              $scope.subscriptionAmount = stripePlansDefault.SubscriptionAmount;
139              $scope.currencyDesc = stripePlansDefault.CurrencyDesc;
140              $scope.currSymbol = stripePlansDefault.CurrSymbol;
141              $scope.vizioSubCost = stripePlansDefault.CurrSymbol + stripePlansDefault.SubscriptionAmount;
142              $scope.subCost = stripePlansDefault.SubscriptionAmount + " " + stripePlansDefault.CurrencyDesc + "/Month";
143              $scope.trialDays = stripePlansDefault.TrialDays;
144              $scope.billingcountryabbr = data.Country;
145              $scope.billingamount = $scope.subscriptionAmount;
146
147              break;
148            }
149          }
150
151          // Only show dropdown if we have other than USD currency.
152          if (stripePlansDefault.CurrencyDesc != "USD") {
153            $scope.showPricing = true;
154          }
155
156          var currencyData = [];
157          for (i = 0; i < stripePlans.length; i++) {
158            if (parseInt(stripePlans[i].Term, 10) == 30) {
159              var abbr = (stripePlans[i].CurrencyDesc == 'USD') ? 'US' : data.Country;
160              var amount = stripePlans[i].SubscriptionAmount;
161              var currency = stripePlans[i].CurrencyDesc;
162              var pricing = amount + " " + currency + "/Month";
163              currencyData.push({
164                'abbr': abbr,
165                'amount': amount,
166                'pricing': pricing,
167                'planid': stripePlans[i].PlanID,
168                'currency': currency
169              });
170            }
171          }
172          $scope.currencies = currencyData;
173          $scope.billingcountry = $scope.currencies[0];
174        }
175      })
176      .catch(function (data) {
177        // console.log(data);
178      });
179  }
180
181  function redirectToTrialSignup() {
182    var redirectURL;
183    var activationCode = queryStringToObject().activationCode;
184
185    if ($scope.rokuSpecial) {
186      redirectURL = '/trialsignup-r.html';
187    } else if ($scope.costcoSpecial) {
188      redirectURL = '/trialsignup-c.html';
189    } else if ($scope.promoSpecial) {
190      redirectURL = '/trialsignup-p.html';
191    } else if ($scope.operaSpecial) {
192      redirectURL = '/trialsignup-o.html';
193    } else if ($scope.tivoSpecial) {
194      redirectURL = '/trialsignup-t.html';
195    } else if ($scope.catalogSpecial) {
196      redirectURL = '/trialsignup-g.html';
197    } else if ($scope.bestbuySpecial) {
198      redirectURL = '/trialsignup-b.html';
199    } else if ($scope.nprSpecial) {
200      redirectURL = '/trialsignup-n.html';
201    } else if ($scope.fetchSpecial) {
202      redirectURL = '/trialsignup-f.html';
203    } else {
204      redirectURL = '/trialsignup.html';
205    }
206
207    if (activationCode) {
208      redirectURL += `?${encodeQueryData({ activationCode: activationCode })}`;
209    }
210
211    window.location.replace(redirectURL);
212  }
213
214  getCountries();
215
216  setAcornHomeLinks();
217
218  $scope.submitCreateAccount = function () {
219    $scope.buttonClicked = true;
220    var SignUpSplitScenario = "TRIAL_SIGNUP";
221    var source = queryStringToObject().source;
222
223    $scope.rokuSpecial = window.location.pathname.indexOf("-r") > -1;
224    $scope.costcoSpecial = window.location.pathname.indexOf("-c") > -1;
225    $scope.promoSpecial = window.location.pathname.indexOf("-p") > -1;
226    $scope.operaSpecial = window.location.pathname.indexOf("-o") > -1;
227    $scope.tivoSpecial = window.location.pathname.indexOf("-t") > -1;
228    $scope.catalogSpecial = window.location.pathname.indexOf("-g") > -1;
229    $scope.bestbuySpecial = window.location.pathname.indexOf("-b") > -1;
230    $scope.nprSpecial = window.location.pathname.indexOf("-n") > -1;
231    $scope.fetchSpecial = window.location.pathname.indexOf("-f") > -1;
232    var costcoIdx = window.location.pathname.indexOf("-c");
233    $scope.expire = window.location.pathname.indexOf("expire") > -1;
234
235    //console.log ("costco idx "+costcoIdx);
236
237    if (source == "roku") {
238      SignUpSplitScenario = "ROKU_TRIAL_SIGNUP";
239    } else if ($scope.rokuSpecial) {
240      SignUpSplitScenario = "ROKU60_TRIAL_SIGNUP";
241    } else if (costcoIdx > -1) {
242      SignUpSplitScenario = "COSTCO_TRIAL_SIGNUP";
243    } else if (source == "samsung") {
244      SignUpSplitScenario = "TIZEN_TRIAL_SIGNUP";
245    } else if (source == "vizio") {
246      SignUpSplitScenario = "VIZIO_TRIAL_SIGNUP";
247    } else if (source == "netgem") {
248      SignUpSplitScenario = "NETGEM_TRIAL_SIGNUP";
249    } else if (source == "tivo") {
250      SignUpSplitScenario = "TIVO_TRIAL_SIGNUP";
251    } else if ($scope.operaSpecial) {
252      SignUpSplitScenario = "OPERA_TRIAL_SIGNUP";
253    } else if ($scope.catalogSpecial) {
254      SignUpSplitScenario = "CATALOG_TRIAL_SIGNUP";
255    } else if ($scope.bestbuySpecial) {
256      SignUpSplitScenario = "BESTBUY_TRIAL_SIGNUP";
257    } else if ($scope.nprSpecial) {
258      SignUpSplitScenario = "NPR_TRIAL_SIGNUP";
259    } else if ($scope.fetchSpecial) {
260      SignUpSplitScenario = "FETCH_TRIAL_SIGNUP";
261    } else if ($scope.expire) {
262      SignUpSplitScenario = "";
263    }
264
265    console.log("SignUpSplitScenario: " + SignUpSplitScenario);
266
267    var CreateAccountJSONData = {
268      "App": {
269        "AppVersion": "Sign-Up-Website"
270      },
271      "Credentials": {
272        "Username": $scope.Username,
273        "Password": $scope.Password,
274        "ActivationCode": queryStringToObject().activationCode
275      },
276      "Request": {
277        "SplitScenario": SignUpSplitScenario,
278        "OperationalScenario": "CREATE_ACCOUNT"
279      },
280      "Account": {
281        "MarketingOptIn": !!$scope.Mktgoptin
282      },
283      "PromoCode": {
284        "Code": $scope.promoCode
285      }
286    };
287
288    // ?millicomId=595984251005&lineType=mobile&operationCode=PY&transactionId=621e103bffbca50006f99222&SKU=ACORNTV_MILLICOM_MONTHLY
289    if (
290      $location.search().millicomId &&
291      $location.search().lineType &&
292      $location.search().operationCode &&
293      $location.search().transactionId &&
294      $location.search().SKU
295    ) {
296      var millicom = {
297        "Millicom": {
298          "ExternalCustomerID": $location.search().millicomId,
299          "Country": $location.search().operationCode,
300          "Id": $location.search().transactionId,
301          "LineType": $location.search().lineType,
302          "Sku": $location.search().SKU
303        }
304      };
305
306      $.extend(CreateAccountJSONData, millicom);
307    }
308
309
310    if (!docCookies.enabled()) {
311      $('#enableCookiesModal').modal();
312    } else {
313      $http({
314        method: "POST",
315        data: JSON.stringify(CreateAccountJSONData),
316        url: "/initializeapp",
317        crossDomain: true,
318        responseType: "json",
319        withCredentials: true,
320        headers: {
321          "Content-Type": "application/json; charset=utf-8",
322        }
323      })
324        .success(function (data, status, headers, config, statusText, xhrStatus) {
325          if (typeof mParticle !== 'undefined') {
326            var promise = $scope.mp.identify(data);
327            promise.then(function () {
328              createAccountSuccess(data)
329            }, function (reason) {
330              alert('Failed: ' + reason);
331            });
332          } else {
333            createAccountSuccess(data);
334          }
335        })
336        .error(function (data, status, headers, config, statusText, xhrStatus) {
337          $scope.buttonClicked = false;
338          var error = data.error;
339          $(".control-group").show();
340          var signinPageLink = signinPage;
341          if (window.location.href.includes('/tigo') && window.location.search) {
342            signinPageLink += window.location.search
343          } else {
344            var activationCode = queryStringToObject().activationCode;
345            if (activationCode) {
346              signinPageLink += `?${encodeQueryData({ activationCode: activationCode })}`;
347            }
348          }
349          try {
350            var errorMessage = polyglot.t("ENTERED-INCORRECT");
351
352            if (error.indexOf("Multiple Registration Same Ip") > -1) {
353              errorMessage = polyglot.t("EXPIRED-TRIAL");
354            } else if (error.indexOf("Account already created") > -1) {
355              errorMessage = errorMessage.concat('<br>', polyglot.t("ACCOUNT-EXISTS"));
356            } else if (error.indexOf("PromotionCode") > -1) {
357              errorMessage = errorMessage.concat('<br>', polyglot.t("CHCK-PROMO-CODE"));
358            } else if (error.indexOf("the Promo Code you entered is no longer available") > -1) {
359              errorMessage = polyglot.t("EXPIRED-PROMO");
360            } else if (error.indexOf("Invalid Costco Promo Code") > -1) {
361              errorMessage = polyglot.t("EXPIRED-PROMO-COSTCO");
362            } else if (error.indexOf("Promo code is expired") > -1) {
363              errorMessage = polyglot.t("PROMOCODE-EXPIRED");
364            } else if (error.indexOf("Promo code not found") > -1) {
365              errorMessage = polyglot.t("PROMOCODE-NOT-FOUND");
366            } else if (error.indexOf("This email address is already registered") > -1) {
367              errorMessage = polyglot.t("ACCOUNT-EXISTS-WITH-LINK", { url: signinPageLink });
368            } else if (error.indexOf("null") > -1) {
369              if ($scope.createForm.promo_code.length > 0) {
370                errorMessage = errorMessage.concat('<br>', polyglot.t("CHCK-PROMO-CODE"));
371              } else {
372                errorMessage = polyglot.t("CHCK-BELOW-FIELDS");
373              }
374            } else {
375              errorMessage = polyglot.t("CHCK-HIGH-FIELDS").concat('<br>', error);
376            }
377
378            $scope.errorMessage = $sce.trustAsHtml(errorMessage);
379            $("html, body").animate({
380              scrollTop: 0
381            }, "slow");
382          } catch (e) {
383            //console.log("e: " + e);
384          }
385        });
386    }
387  };
388
389  $scope.submitTrialSignup = function () {
390    $scope.promoSpecial = window.location.pathname.indexOf("-p") > -1;
391
392    TrialSignUpJSONData = {
393      "BillingAddress": {
394        "Country": $scope.countryCode
395      },
396      "PromoCode": {
397        "Code": $scope.promoCode
398      },
399      "ActivationCode": {
400        "Code": queryStringToObject().activationCode
401      },
402      "csrf_token": $scope.csrfToken,
403      "captcha_token": $scope.captchaToken,
404      "captcha_version": $scope.captchaVersion,
405    };
406
407    if (!docCookies.enabled()) {
408      $('#enableCookiesModal').modal();
409    } else {
410      $.ajax({
411        type: "POST",
412        data: JSON.stringify(TrialSignUpJSONData),
413        contentType: "application/json; charset=utf-8",
414        url: "/createtrial",
415        dataType: "json",
416        xhrFields: {
417          withCredentials: true
418        },
419        crossDomain: true,
420        success: function (json) {
421          switch (json.RecommendedAction.Type) {
422            case 'SigninPage':
423              if (docCookies.enabled()) {
424                docCookies.setItem('fname', json.fname);
425                docCookies.setItem('lname', json.lname);
426                docCookies.setItem('email', json.email);
427                docCookies.setItem('cid', json.customerID);
428              }
429
430              window.location.replace("/confirmation.jsp");
431              break;
432            default:
433              window.location.replace("/confirmation.jsp");
434          }
435        },
436        error: function (xhr, status, errorThrown) {
437          $scope.buttonClicked = false;
438          formTrialSignupPosted = false;
439
440          alertMsg = $.parseJSON(xhr.responseText);
441
442          if ($.isPlainObject(alertMsg.error)) {
443            $scope.errorMessage = $sce.trustAsHtml(alertMsg.error);
444          } else {
445            if (alertMsg.error.indexOf('unable to process this transaction') >= 0) {
446              $scope.errorMessage = polyglot.t('ERR-PROCESS-REQUEST');
447            }
448            if (alertMsg.error.toLowerCase().indexOf('captcha') >= 0) {
449              $scope.isCaptchaTested = true;
450              $scope.isCaptchaV2 = true;
451            }
452          }
453        },
454        complete: function (xhr, status) {
455          // Do Nothing for now.
456        }
457      });
458    }
459
460  }
461
462  function setPreAuth(data) {
463    // var customer_id = 'tomtom-123456789';
464    var customer = data.Customer;
465    var customerID = customer.CustomerID;
466
467    $scope.csrfToken = angular.element('meta[name="csrf-token"]').attr('content');
468    console.log(customerID, $scope.csrfToken);
469    $scope.captcha.setPreAuth($scope.csrfToken, customerID, $scope.submitTrialSignup)
470  }
471
472  function createAccountSuccess(data) {
473    if ($scope.promoCode && $scope.promoType && $scope.promoType === "gift") {
474      setPreAuth(data);
475    } else {
476      switch (data.RecommendedAction.Type) {
477        case "HomePage":
478          window.location.replace(acornTVHomeLink);
479          break;
480        case "BillingAddress":
481        case "TrialSignup":
482          redirectToTrialSignup();
483          break;
484        case "DeviceAuthorization":
485          window.location.replace("/deviceauthorization.html");
486          break;
487        case "ExpiredSignup":
488          var storeURL = window.location.hostname.replace('signup', 'store');
489          window.location.replace(storeURL + '/#membership');
490          break;
491        default:
492          $scope.buttonClicked = false;
493          $(".alert-info").remove();
494          $scope.errorMessage = $sce.trustAsHtml(
495            [
496              polyglot.t("PROBLEM-SIGNUP"),
497              polyglot.t("PREVIEW-ACRN-HERE", { url: acornTVURL() }),
498              polyglot.t("FURTHER-ASSISTANCE", { url: contactUsURL() })
499            ], join('<br>')
500          );
501          $("html, body").animate({
502            scrollTop: 0
503          }, "slow");
504      }
505    }
506  }
507}

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.