1// jquery-AuthApi2.js - r.20171025-1 2jQuery.extend({ 3 4 AuthApi: function(options){ 5 var version = "2.2.7", 6 7 // internal consts 8 konst = { 9 'apiUrl': "/auth-p7/app/default/AuthApi4.php", 10 'actionLoginPwd': 'a=aLoginPwd', 11 'actionLoginSam': 'a=aLoginSam', 12 'actionDlgPwcange': 'a=aDlgPwchange', 13 'actionReset': 'a=aReset', 14 15 'arqChangePasswordUrl': "/home/app/default/pwchangedialog.php", 16 17 'changePasswordDialogCode': 'changePasswordDialog', 18 'accountChoiceDialogCode': 'accountChoiceDialog', 19 20 'warnMsgShowingTime': 5000, 21 'successMsgShowingTime': 3000, 22 'choiceDialogTimeout': 30000, // OKKIO!! in produzione MAX 30sec (30000ms) 23 'globalTimeout': 30000 // OKKIO!!! in produzione 30sec. (30000ms) 24 }, 25 26 // default options 27 defaults = { 28 'action': 'authenticate', // action to run (default=authenticate): authenticate|samauthenticate|passwordChange|reset 29 30 'authTarget': '', // app-code/project-code (optional) 31 'authCid': '', // customer-code (optional) 32 'authLogin': '', // login-name 33 'authPass': '', // password 34 'authPin': '', // pin 35 'authAllowAccountChoice': true, // enable/disable Account-Choice dialog 36 'authCompleted': function(data,status,xhr){}, // authentication completed callback 37 38 'resetCompleted': function(data,status,xhr){}, // reset completed callback 39 40 'onDialogOpen': function(code, dialog){}, // (any) dialog on-open callback 41 42 'onError': function( xhr, status, error ){} // on ajaxerror callback 43 } 44 ; 45 46 options=typeof(options)=='object' ? options : {}; 47 options = $.extend({}, defaults, options); 48 49 50 51 // execute password-change procedure 52 var changePasswordExec=function(dialog){ 53 var $dialog=$(dialog), 54 $msgContainer=$dialog.find('.aapi-dlg-unit.warnings'), 55 $successContainer=$dialog.find('.aapi-dlg-unit.success'), 56 url=konst.arqChangePasswordUrl+'?action=SAVE', 57 /*postData={ 58 'login': $dialog.find('[name="user"]').val(), 59 'password': $dialog.find('[name="pold"]').val(), 60 'np1': $dialog.find('[name="pnew"]').val(), 61 'np2': $dialog.find('[name="rnew"]').val() 62 };*/ 63 postData=$('#pwdChangeForm').serialize(); 64 65 if(jQuery("#j-captcha-aDlgPwchange").length > 0) 66 { 67 postData += postData.trim() != '' ? '&' : ''; 68 postData += 'j-captchaCx='+jQuery("#j-captcha-aDlgPwchange").realperson('getHash'); 69 } 70 71 $.post(url, postData, function(response){ 72 73 if(response=="OK"){ 74 $successContainer.slideDown(); 75 $dialog.dialog("option","buttons",[]); 76 window.setTimeout(function(){ 77 $dialog.dialog("close"); 78 }, konst.successMsgShowingTime); 79 80 }else{ 81 $msgContainer.html(response).slideDown(); 82 window.setTimeout(function(){ 83 $msgContainer.slideUp(); 84 }, konst.warnMsgShowingTime); 85 } 86 }); 87 } 88 89 // start password-change procedure 90 var changePasswordStart=function(flavour){ 91 var url = konst.apiUrl+'?'+konst.actionDlgPwcange; // url for dialog template 92 flavour=(typeof flavour=="string")?flavour:""; 93 // getting dialog template 94 $.post(url, false, function(json, textStatus) { 95 var $html=$(json.data.dialog); // dialog template 96 // removing elements from template depending on flavor 97 switch(flavour){ 98 case "change": 99 $html.find('.aapi-dlg-unit.header').addClass("x-remove"); 100 $html.find('.aapi-dlg-unit.header.change').removeClass("x-remove"); 101 break; 102 case "expired": 103 $html.find('.aapi-dlg-unit.header').addClass("x-remove"); 104 $html.find('.aapi-dlg-unit.header.expired').removeClass("x-remove"); 105 break; 106 default: 107 $html.find('.aapi-dlg-unit.header').addClass("x-remove"); 108 } 109 $html.find('.x-remove').remove(); 110 $html.find('.aapi-dlg-unit.warnings').hide(); 111 $html.find('.aapi-dlg-unit.success').hide(); 112 113 114 // showing dialog: PasswordChangeDialog 115 $($html).dialog({ 116 'buttons': [ 117 { 118 'text': json.data.strings.abort, 119 'click': function(){$(this).dialog('close')} 120 }, 121 { 122 'text': json.data.strings.ok, 123 'click': function(){ 124 changePasswordExec(this); 125 } 126 } 127 ], 128 'dialogClass': "aapi-dlg", 129 'width': "30em", 130 'modal': true, 131 'open': function(){ 132 var $dialog=$(this); 133 // hide dialog titlebar 134 $dialog.closest('.ui-dialog').find('.ui-dialog-titlebar').hide(); 135 // fill some input fields 136 $dialog.find('[name="user"]').val(options.authLogin); 137 $dialog.find('[name="pold"]').val(options.authPass); 138 139 window.setTimeout(function(){
140 $dialog.find('.aapi-dlg-unit.warnings').slideUp(); 141 }, konst.warnMsgShowingTime); 142 // call onDialogOpen callback if defined 143 if(typeof options.onDialogOpen == "function"){ 144 options.onDialogOpen(konst.changePasswordDialogCode, this) 145 } 146 }, 147 'close': function(){ 148 $(this).remove(); 149 }, 150 'resizable': false 151 }); 152 153 }, "json"); 154 } 155 156 // evaluate requested-action following the authentication process 157 var evalActionRequested=function(actionRequested){ 158 //console.log("inPLUGIN: evalActionRequested: ", actionRequested); 159 switch(actionRequested){ 160 case konst.changePasswordDialogCode: 161 changePasswordStart('expired') 162 break; 163 } 164 } 165 166 // authentication callback 167 var onAuthCompleted=function(json,status,xhr){ 168 // are there a requested-action? 169 if(json.data && json.data.auth && json.data.auth.actionRequested){ 170 // if so... evaluate it 171 evalActionRequested(json.data.auth.actionRequested); 172 } 173 174 if(typeof options.authCompleted == "function"){ 175 176 //console.log("inPLUGIN: onAuthCompleted: ", json); 177 // check conditions for AccountChoiceDialog 178 var runChoicheDialog=options.authAllowAccountChoice 179 && json.data != undefined 180 && json.data.auth.verified 181 && !json.data.auth.loggedIn 182 ; 183 184 if(runChoicheDialog){ 185 //console.log("inPLUGIN: onAuthCompleted: running AccountChoiceDialog "); 186 var $html=false; 187 if(json.data.pfolio.filteredDialogHtml){ 188 $html=$(json.data.pfolio.filteredDialogHtml); 189 }else if(json.data.pfolio.fullDialogHtml){ 190 $html=$(json.data.pfolio.fullDialogHtml); 191 } 192 if($html){ 193 194 } 195 196 // showing dialog: AccountChoiceDialog 197 $($html).dialog({ 198 'buttons': [], 199 'dialogClass': "aapi-dlg", 200 'width': "30em", 201 'modal': true, 202 'open': function(){ 203 var $dialog=$(this); 204 // hide dialog titlebar 205 $dialog.closest('.ui-dialog').find('.ui-dialog-titlebar').hide(); 206 207 // ensure closing dialog after timeout 208 window.setTimeout(function(){ 209 // but only if not already closed 210 if ($.contains(document, $dialog[0])){ 211 $.post(konst.apiUrl+'?'+konst.actionReset); 212 $dialog.dialog("close"); 213 } 214 }, konst.choiceDialogTimeout); 215 216 // call onDialogOpen callback if defined 217 if(typeof options.onDialogOpen == "function"){ 218 options.onDialogOpen(konst.accountChoiceDialogCode, this) 219 } 220 221 $dialog.find('.item[x-account]') 222 .unbind() 223 .click(function(){ 224 // AccountChoiceDialog item clicked 225 var xaccount=$(this).attr('x-account'); 226 var ajaxOptions = { 227 'url': konst.apiUrl+'?'+konst.actionLoginSam, 228 'data': {'uid': xaccount}, 229 'async': true, 230 'type': "POST", 231 'success': onAuthCompleted, 232 'error': onError 233 }; 234 $.ajax(ajaxOptions); 235 $dialog.dialog("close"); 236 237 }); 238 239 }, 240 'close': function(){ 241 $(this).remove(); 242 }, 243 'resizable': false 244 }); 245 246 }else{ 247 //console.log("inPLUGIN: onAuthCompleted: skipped AccountChoiceDialog "); 248 } 249 250 if(typeof options.authCompleted == "function"){ 251 options.authCompleted(json,status,xhr); 252 } 253 } 254 } 255 256 // authentication callback 257 var onResetCompleted=function(json,status,xhr){ 258 //console.log("inPLUGIN: onResetCompleted: ", json, status, xhr); 259 if(typeof options.resetCompleted == "function"){ 260 options.resetCompleted(json,status,xhr); 261 } 262 263 } 264 265 // on Error callback 266 var onError=function(xhr,status,error){ 267 //console.log("inPLUGIN: onError: ", xhr,status,error); 268 if(typeof options.onError == "function"){ 269 options.onError(xhr,status,error); 270 } 271 } 272 273 // running of specific actions 274 var postData={},ajaxOptions={}; 275 switch(options.action){ 276 277 case 'authenticate': 278 postData = { 279 'cid': options.authCid, 280 'uid': options.authLogin, 281 'pwd': options.authPass, 282 'pin': options.authPin, 283 'target': options.authTarget 284 }; 285 ajaxOptions = { 286 'url': konst.apiUrl+'?'+konst.actionLoginPwd, 287 'data': postData, 288 'async': true, 289 'type': "POST", 290 'success': onAuthCompleted, 291 'error': onError, 292 'timeout': konst.globalTimeout 293 }; 294 $.ajax(ajaxOptions); 295 break; 296 297 case 'samauthenticate': 298 postData = { 299 'uid': options.authLogin, 300 }; 301 ajaxOptions = { 302 'url': konst.apiUrl+'?'+konst.actionLoginSam, 303 'data': postData, 304 'async': true, 305 'type': "POST", 306 'success': onAuthCompleted, 307 'error': onError, 308 'timeout': konst.globalTimeout 309 }; 310 $.ajax(ajaxOptions); 311 break; 312 313 case 'passwordChange': 314 changePasswordStart('change'); 315 break; 316 317 case 'reset': 318 default: 319 ajaxOptions = { 320 'url': konst.apiUrl+'?'+konst.actionReset, 321 'async': true, 322 'type': "POST", 323 'success': onResetCompleted, 324 'error': onError, 325 'timeout': konst.globalTimeout 326 }; 327 $.ajax(ajaxOptions); 328 break; 329 330 } 331 332 } 333}) 334
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.