webix.ui.fullScreen(); var name = ""; var title = ""; JG.cpauth_type = parseInt("0"); if(JG.cpauth_type < 0 || JG.cpauth_type > 3) JG.cpauth_type = 0; /*if(JG.ONLINE == false){ motor para deslogar a sessao webix.ajax().get("/dispatch.php?mvc=set&module=cpanel&console=cp_session_destroy", { online : JG.ONLINE }, function(text, xml, xhr){ console.log(text); webix.message({text:text}); }); }*/ webix.ajax().post("/dispatch.php?mvc=get&module=cpanel&console=cpauth",{ error:function(text, data, XmlHttpRequest){ webix.message.keyboard = false; webix.alert({ title:"Erro 1", ok:"Reconectar", type:"alert-warning", text:"Impossível obter resposta do servidor", callback:function(){location.href = "/"} }); JG = {}; }, success:function(text, data, XmlHttpRequest){ data = data.json(); JG.authkey = data.authkey; if(JG.ONLINE == false){ webix.ui({ view: "window", id: "cpanel_win_login", position:"center", move: !0, resize: !1, head: { view: "toolbar", cols: [ { view: "label", label: "

Login

" } ] }, body: { view: "form", id:"cpanel_frm_login", elements:[ { template : "", height:"135", borderless: 1 }, { label: "CPF/CNPJ", id:"cpanel_fld_cpfcnpj", view: "text", name: "cpfcnpj", labelPosition:"top", hidden:false, on:{ onKeyPress: function(code, obj){ var value = this.getValue(); value = value.replace(/[^0-9]/g,''); if(value.length == 11){ var ret = value.substr(0,3)+"."+value.substr(3,3)+"."+value.substr(6,3)+"-"+value.substr(-2); this.setValue(ret); }else if(value.length == 14){ var ret = value.substr(0,2)+"."+value.substr(2,3)+"."+value.substr(5,3)+"/"+value.substr(8,4)+"-"+value.substr(-2); this.setValue(ret); }else if(value.length == 15){ var ret = value.substr(1,2)+"."+value.substr(3,3)+"."+value.substr(6,3)+"/"+value.substr(9,4)+"-"+value.substr(-2); this.setValue(ret); } }, onBlur: function(code, obj){ var value = this.getValue(); value = value.replace(/[^0-9]/g,''); if(value.length == 11){ var ret = value.substr(0,3)+"."+value.substr(3,3)+"."+value.substr(6,3)+"-"+value.substr(-2); this.setValue(ret); }else if(value.length == 14){ var ret = value.substr(0,2)+"."+value.substr(2,3)+"."+value.substr(5,3)+"/"+value.substr(8,4)+"-"+value.substr(-2); this.setValue(ret); }else if(value.length == 15){ var ret = value.substr(1,2)+"."+value.substr(3,3)+"."+value.substr(6,3)+"/"+value.substr(9,4)+"-"+value.substr(-2); this.setValue(ret); } } } }, { label: "Usuário", id:"cpanel_fld_usercpanel", view: "text", name: "usercpanel", labelPosition:"top", hidden:true }, { label: "Senha", id:"cpanel_fld_passcpanel", view: "text", name: "passcpanel", type: "password", labelPosition:"top", hidden:true }, { view:"richselect", id:"cpanel_fld_address", name:"address", label:"Para qual endereço deseja atendimento:", labelPosition:"top", hidden:true, options:[] }, { label: "Login", view: "button", type: "form", height: 40, click: function(){ var frm = this.getFormView(); if(frm.validate()){ var values = $$("cpanel_frm_login").getValues(); var _md5 = ""; JG._md5 = ""; var _passhash = ""; var _user = ""; JG.user = ""; var address = ""; if(JG.cpauth_type == 0){ _md5 = jcore.md5(values.passcpanel); JG._md5 = _md5; _passhash = jcore.md5(JG.authkey + _md5); _user = values.usercpanel; JG.user = _user; }else if(JG.cpauth_type == 1){ var cpfcnpj = values.cpfcnpj cpfcnpj = cpfcnpj.replace(/[^0-9]/g,''); address = values.address; _md5 = jcore.md5(cpfcnpj); JG._md5 = _md5; _passhash = jcore.md5(JG.authkey + _md5); }else if(JG.cpauth_type == 2){ var cpfcnpj = values.cpfcnpj cpfcnpj = cpfcnpj.replace(/[^0-9]/g,''); address = values.address; _md5 = jcore.md5(values.passcpanel); JG._md5 = _md5; _passhash = jcore.md5(JG.authkey + _md5); _user = values.usercpanel; JG.user = _user; }else if(JG.cpauth_type == 3){ var cpfcnpj = values.cpfcnpj cpfcnpj = cpfcnpj.replace(/[^0-9]/g,''); address = values.address; var pass = values.passcpanel; pass = pass.replace(/[^0-9]/g,''); _md5 = jcore.md5(pass); JG._md5 = _md5; _passhash = jcore.md5(JG.authkey + _md5); _user = values.usercpanel; JG.user = _user; } var urllogin = "/dispatch.php?mvc=set&module=cpanel&console=cp_auth&passhash="+_passhash+"&authkey="+JG.authkey+"&user="+_user+"&cpfcnpj="+cpfcnpj+"&auth_type="+JG.cpauth_type+"&address="+address; webix.ajax().post(urllogin, {}, function(text, data, xhr){ var response = data.json(); if(response.success){ $$('cpanel_win_login').close(); JG.ONLINE = true; JG.CLID = response.clid; cpsession(1); if(JG.ONLINE == true && JG.CLID != 0 && (JG.authkey != '' || typeof(JG.authkey)!='undefined')) dispatchercp("/dispatch.php?mvc=main&module=cpanel&console=cp_panel"); }else{ if(response.errno == 100){ $$("cpanel_fld_address").show(); $$('cpanel_fld_address').getPopup().getList().clearAll(); $$("cpanel_fld_address").getList().parse(response.address); $$("cpanel_fld_address").setValue(response.address[0].id); webix.message(response.error); }else{ var _text = response.errno+": "+response.error; webix.message({ type:"error", text:_text }); } } }); }else{ webix.message({ type:"error", text:"Campos Incorretos" }); } }, hotkey: "enter" }, { template: "
Recuperar dados para acesso
", view: "label", height: 25, click: function() { getdtapass(); } }, { view:"text", id:"cpanel_fld_cpauth_type", name:"auth_type", hidden:true}, { template: "
Cadastrar usuário/senha?
", view: "label", height: 25, click: function() { register_login(); } }, ], rules:{ "cpfcnpj":function(value){ value = value.replace(/[^0-9]/g,''); if(value.length == 11) return true; // CPF else if(value.length == 14) return true; // CNPJ else return false; }, "usercpanel":function(value){ return value.length >= 3; }, "passcpanel":function(value){ return value.length >= 4; } }, } }); $$('cpanel_win_login').attachEvent("onShow", function(){ $$("cpanel_fld_cpauth_type").setValue(JG.cpauth_type); switch(JG.cpauth_type){ case 0: $$("cpanel_fld_cpfcnpj").hide(); $$("cpanel_fld_usercpanel").show(); $$("cpanel_fld_passcpanel").show(); break; case 1: $$("cpanel_fld_cpfcnpj").show(); $$("cpanel_fld_usercpanel").hide(); $$("cpanel_fld_passcpanel").hide(); break; case 2: $$("cpanel_fld_cpfcnpj").show(); $$("cpanel_fld_usercpanel").hide(); $$("cpanel_fld_passcpanel").show(); break; case 3: $$("cpanel_fld_cpfcnpj").show(); $$("cpanel_fld_usercpanel").hide(); $$("cpanel_fld_passcpanel").show(); break; } }); $$('cpanel_win_login').show(); function link(e, t) { return '' + e + "" } function register_login(){ webix.ui({ view: "window", id: "cpanel_reg_login", position: 'center', head: '
Cadastrar novo usuário
', headHeight: 25, move: !0, width: 500, body: { view: "form", id:"cpanel_frm_reg_login", padding: 30, elementsConfig:{ labelPosition: "top", }, elements: [ { view: "text", id: "cpanel_reg_cpfcnpj", label: "CPF/CNPJ", name: "cpfcnpj", on:{ onKeyPress: function(code, obj){ var value = this.getValue(); value = value.replace(/[^0-9]/g,''); if(value.length == 11){ var ret = value.substr(0,3)+"."+value.substr(3,3)+"."+value.substr(6,3)+"-"+value.substr(-2); this.setValue(ret); }else if(value.length == 14){ var ret = value.substr(0,2)+"."+value.substr(2,3)+"."+value.substr(5,3)+"/"+value.substr(8,4)+"-"+value.substr(-2); this.setValue(ret); }else if(value.length == 15){ var ret = value.substr(1,2)+"."+value.substr(3,3)+"."+value.substr(6,3)+"/"+value.substr(9,4)+"-"+value.substr(-2); this.setValue(ret); } }, onBlur: function(code, obj){ var value = this.getValue(); value = value.replace(/[^0-9]/g,''); if(value.length == 11){ var ret = value.substr(0,3)+"."+value.substr(3,3)+"."+value.substr(6,3)+"-"+value.substr(-2); this.setValue(ret); }else if(value.length == 14){ var ret = value.substr(0,2)+"."+value.substr(2,3)+"."+value.substr(5,3)+"/"+value.substr(8,4)+"-"+value.substr(-2); this.setValue(ret); }else if(value.length == 15){ var ret = value.substr(1,2)+"."+value.substr(3,3)+"."+value.substr(6,3)+"/"+value.substr(9,4)+"-"+value.substr(-2); this.setValue(ret); } } } }, { label: "Usuário", view: "text", name: "usercpanel", id: "cpanel_reg_username", }, { label: "Senha", id: "cpanel_reg_pass", view: "text", name: "passcpanel", type: "password", placeholder: "Pelo menos 4 caracteres", }, { label: "E-mail", id: "cpanel_reg_mail", view: "text", name: "recmail", placeholder: "sample@sample.com", }, { label: "Celular", id: "cpanel_reg_mobile", view: "text", name: "recmobile", on:{ onKeyPress: function(code, obj){ var value = this.getValue(); value = value.replace(/[^0-9]/g,''); if(value.length == 11){ var ret = "("+value.substr(0,2)+")"+value.substr(2,5)+"-"+value.substr(-4); this.setValue(ret); } }, onBlur: function(code, obj){ var value = this.getValue(); value = value.replace(/[^0-9]/g,''); if(value.length == 11){ var ret = "("+value.substr(0,2)+")"+value.substr(2,5)+"-"+value.substr(-4); this.setValue(ret); } } } }, { cols: [ { label: "Save", view: "button", type: "form", height: 40, click: function(){ var rfrm = this.getFormView(); if(rfrm.validate()){ webix.ajax().get("/dispatch.php?mvc=set&module=cpanel&console=cp_add_login", $$("cpanel_frm_reg_login").getValues(), function(text, xml, xhr){ var response = JSON.parse(text); if(response.success){ webix.message({text:"Usuário cadastrado com sucesso!"}) $$("cpanel_reg_login").close(); location.href="/"; }else{ var _text = response.errno+": "+response.error; webix.message({ type:"error", text:_text }); } }); }else{ webix.message({ type:"error", text:"Campos Incorretos" }); } }, }, {}, { label: "Cancel", view: "button", height: 40, click: function(){ location.href="/"; }, } ] } ], rules:{ "cpfcnpj":function(value){ value = value.replace(/[^0-9]/g,''); if(value.length == 11) return true; // CPF else if(value.length == 14) return true; // CNPJ else return false; }, "usercpanel":function(value){ return(value.length >= 3 && value.length <80); }, "passcpanel":function(value){ return(value.length >= 4 && value.length <100); }, "recmail":webix.rules.isEmail, "recmobile":function(value){ if(value.match(/^(\()?\d{2}(\))?(-|\s)?\d{5}(-|\s)\d{4}$/) != null){ return true; }else return false; }, }, } }).show(); } function getdtapass(){ webix.ui({ view: "window", id: "cpanel_reg_login_recorver", position: 'center', head: '
Recuperar dados para acesso
', headHeight: 25, move: !0, width: 500, height: 170, body: { view: "form", id:"cpanel_frm_reg_login_recover", padding: 30, elementsConfig:{ labelPosition: "top", }, elements: [ { label: "E-mail cadastrado no sistema", id: "cpanel_reg_mail", view: "text", name: "recovermail", type: "email", placeholder: "seu_email@dominio.com.br", }, { cols: [ { label: "Enviar", view: "button", type: "form", height: 40, click: function(){ var rfrm = this.getFormView(); if(rfrm.validate()){ webix.ajax().post("/dispatch.php?mvc=set&module=cpanel&console=cp_recoverpass", $$("cpanel_frm_reg_login_recover").getValues(), function(text, xml, xhr){ var response = JSON.parse(text); if(response.success){ webix.message({text:"Pedido de recuperação de senha em análise."}) $$("cpanel_reg_login_recorver").close(); location.href="/"; }else{ var _text = response.errno+": "+response.error; webix.message({ type:"error", text:_text }); } }); }else{ webix.message({ type:"error", text:"Email incorreto!" }); } }, }, {}, { label: "Cancel", view: "button", hotkey: "esc", height: 40, click: function(){ location.href="/"; }, } ] } ], rules:{ "recovermail":webix.rules.isEmail, }, } }).show(); } $$('cpanel_frm_login').focus('usercpanel'); } } });