PageSourceSearch

https://www.ccboiler.com/wp-content/plugins/servicetrade-service-p…de-portal-public-widget-login.js?ver=2.0.14

js ccboiler.com collected 2026-10-06 08:10:54 UTC 5,251 bytes, 165 lines download raw bytes

1(function( $ ) {
2	'use strict';
3
4  var buildUrl = function(path) {
5    return window.servicetradePortalConfig ? window.servicetradePortalConfig.apiRoot + path : path;
6  };
7
8  var showLoginForm = function() {
9    $('.servicetrade-widget-login-form-login').show();
10    $('.servicetrade-widget-login-form-signup').hide();
11    $('.servicetrade-widget-login-form-forgot-password').hide();
12  };
13
14  var showSignupForm = function() {
15    $('.servicetrade-widget-login-form-login').hide();
16    $('.servicetrade-widget-login-form-signup').show();
17    $('.servicetrade-widget-login-form-forgot-password').hide();
18  };
19
20  var showForgotPasswordForm = function() {
21    $('.servicetrade-widget-login-form-login').hide();
22    $('.servicetrade-widget-login-form-signup').hide();
23    $('.servicetrade-widget-login-form-forgot-password').show();
24  };
25
26  var onActionLogin = function(e){
27    e.preventDefault();
28    showLoginForm();
29  };
30
31  var onActionSignup = function(e){
32    e.preventDefault();
33    showSignupForm();
34  };
35
36  var onActionForgotPassword = function(e){
37    e.preventDefault();
38    showForgotPasswordForm();
39  };
40
41  var arrayToObject = function (unindexed_array){
42    var indexed_array = {};
43    $.map(unindexed_array, function(n, i){
44        indexed_array[n['name']] = n['value'];
45    });
46
47    return indexed_array;
48  }
49
50  /**
51   * Hides the three input forms.
52   */
53  var hideAllForms = function() {
54    $('form.servicetrade-widget-login-form-login').hide();
55    $('form.servicetrade-widget-login-form-signup').hide();
56    $('form.servicetrade-widget-login-form-forgot-password').hide();
57
58  };
59
60  var hideSuccessError = function() {
61    $('.servicetrade-success-container').hide();
62    $('.servicetrade-error-container').hide();
63  };
64
65  var showError = function(message) {
66    $('.servicetrade-success-container').hide();
67    $('.servicetrade-error-container').html("<p>" + message + "</p>").show();
68  };
69
70  var showSuccess = function(message) {
71    $('.servicetrade-error-container').hide();
72    $('.servicetrade-success-container').html("<p>" + message + "</p>").show();
73  };
74
75  var performAjax = function(url,formData, success,fail) {
76    $.ajax({
77      type        : 'POST',
78      data        : formData,
79      url: url,
80      dataType    : 'json',
81      encode          : true
82    })
83    .done(success)
84    .fail(fail);
85  };
86
87  /**
88   * Attempts to sign the client in.
89   * @param {Object} formData 
90   */
91  var performSignIn = function(formData) {
92    var fnSuccessSignIn = function(result) {
93      if(result.redirectUrl) {
94        window.location = result.redirectUrl;
95      }
96    };
97    var fnFailSignIn = function(error) {
98      showError("Failed to sign you in. Please check that your username/email and password are correct and that you have been given access to the portal.");
99    };
100
101    performAjax(buildUrl('user/login'), formData,fnSuccessSignIn,fnFailSignIn);
102  };
103
104  /**
105   * Attempts to request access for a new client
106   * @param {Object} formData 
107   */
108  var performRequestAccess = function(formData) {
109    var fnSuccessRequestAccess = function(result) {
110        showSuccess("You have successfully requested access and will receive a confirmation email shortly.");
111        hideAllForms();
112      };
113    var fnFailRequestAccess = function(error) {
114		 var errorMessage = error && error.responseJSON && error.responseJSON.message ? error.responseJSON.message + '.' : '';
115      showError("Could not request access. " + errorMessage);
116    };
117
118    performAjax(buildUrl('user/request-access'), formData,fnSuccessRequestAccess,fnFailRequestAccess);
119  };
120
121  /**
122   * Attempts to retrieve the password for a client
123   * @param {Object} formData 
124   */
125  var performForgotPassword = function(formData) {
126    var fnSuccessForgotPassword = function(result) {
127        showSuccess("Please check your email - you should receive password reset instructions shortly.");
128        hideAllForms();
129      };
130    var fnFailForgotPassword = function(error) {
131      showError("Could not send email: " + error.responseJSON.message);
132    };
133
134    performAjax(buildUrl('user/forgot-password'), formData,fnSuccessForgotPassword,fnFailForgotPassword);
135  };
136
137  var onSubmitForm = function(e) {
138    e.preventDefault();
139    hideSuccessError();
140    var formData = $(e.target).find(":input").serializeArray();
141    formData = arrayToObject(formData);
142    // console.log(formData); 
143    
144    var url = '';
145    switch(formData['action']) {
146      case 'servicetrade-widget-login-form-login':
147        return performSignIn(formData);
148      case 'servicetrade-widget-login-form-signup':
149        return performRequestAccess(formData);
150      case 'servicetrade-widget-login-form-forgot-password':
151        return performForgotPassword(formData);
152    }
153
154  }
155  
156  $(function() {
157    $('.servicetrade-widget-login-form-action-login').click(onActionLogin);
158    $('.servicetrade-widget-login-form-action-signup').click(onActionSignup);
159    $('.servicetrade-widget-login-form-action-forgot-password').click(onActionForgotPassword);
160
161    $('form.servicetrade-widget-login-form-login').submit(onSubmitForm);
162    $('form.servicetrade-widget-login-form-signup').submit(onSubmitForm);
163    $('form.servicetrade-widget-login-form-forgot-password').submit(onSubmitForm);
164  });
165})( jQuery );

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.