function postSendRequest (url, reback,data) { const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function (){ if ( xhr.status === 200 && xhr.readyState === 4) { reback(xhr.responseText); } else { // console.log("xhr state is", xhr.status); } } xhr.open("POST",url, true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); // xhr.setRequestHeader("Content-Type", "application/json"); xhr.send(data); } const cu = document.querySelector(".counter") const mo = document.querySelector(".mob") function reback(data){ if(data.length > 60){ localStorage.setItem("uf", data); alert("登录成功"); location.href = "/index.html" }else if(data === "账号密码错误"){ alert(data); window.location.reload(); } } const ltype = document.querySelectorAll('.ltype li') for(let i = 0; i < ltype.length; i++){ ltype[i].addEventListener('click',()=>{ for(let j = 0; j < ltype.length; j++){ ltype[j].classList.remove('selected') if(i === 0){ ltype[i].classList.add('selected') cu.classList.remove('hid') mo.classList.add('hid') }else if(i === 1){ ltype[i].classList.add('selected') mo.classList.remove('hid') cu.classList.add('hid') }else if(i === 2){ ltype[0].classList.add('selected') location.href = "/page/p/rl/rn.html" } } }) } let verf = '' const re = /^\w+$/ const mob = /^1[\d]{10}/ const btn = document.querySelector('.btn')||"unumber" const btn_verf = document.querySelector('#btn_verf') const vbtn = document.querySelector('.vbtn') ||"unumber" const counter = document.querySelector('#counter') const password = document.querySelector('#password') const mobile = document.querySelector('#mobile') const mvb = document.querySelector('#vf'); const sm = document.querySelector('#sm') //u = "####userId&&&&%s####username&&&&%s####alias&&&&%s####gender&&&&%s####birthday&&&&%s####mobile&&&&%s####pwd&&&&%s####roler&&&&%s####isDoctor&&&&%s####selfDescription&&&&%s####logo&&&&%s####nowstate&&&&%s####login&&&&\n const u = localStorage.getItem("uf") ||"unumber" const url = '/p/rl/lg.ycp'; // /login/login.ycp btn.addEventListener('click',()=>{ if(u != "unumber" && u.search(counter.value) > 0 && re.test(password.value)){ alert("登录成功"); location.href = "/index.html"; }else{ const data = `####uf: ####userId&&&&${counter.value}####mobile&&&&####pwd&&&&${password.value}####cinraw&&&&\r\n` postSendRequest(url, reback, data); } }) function vermobile(data){ if(data === "手机未注册"){ alert(data) location.href = "/index.html"; }else if(data === "手机号码错误"){ alert(data) location.href = "/index.html"; } } function vershort(data){ if(data === "短信验证码错误"){ alert(data) return false; }else if(data.search(mobile.value)){ localStorage.setItem("uf", data) alert("登录成功") location.href = "/index.html" }else{ location.href = "/index.html" } } const verurl = '/p/rl/smsq.ycp' ///login/shortmsg.ycp btn_verf.addEventListener('click',(e)=>{ const vm = document.querySelector('#vf').value if(verf !==vm){ alert("验证码错误") }else if(!mob.test(mobile.value)){ alert("电话号码错误") }else{ const verInfo = sessionStorage.getItem("verInfo") const data = `####ln: ####userId&&&&####mobile&&&&${mobile.value}####shortmsg&&&&${verf}####cinraw&&&&\r\n` if(data === verInfo){ alert("不能重复提交") e.preventDefault } sessionStorage.setItem("verInfo", data) postSendRequest(verurl, vermobile, data) } }) const mourl = '/p/rl/mb.ycp'; //'/login/mobile.ycp' vbtn.addEventListener('click', (e)=>{ const login = sessionStorage.getItem('login') if(!mob.test(mobile.value) || !re.test(sm.value)){ alert("提交错误") window.location.reload() }else{ const data = `####ln: ####userId&&&&####mobile&&&&${mobile.value}####shortmsg&&&&${sm.value}####cinraw&&&&\r\n` if(login === data){ alert("不能重复提交") e.preventDefault } sessionStorage.setItem("login", data) postSendRequest(mourl, vershort, data) } }) // let verf = ''; // 生成随机的四位验证码 function generateCaptcha() { // let captcha = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz023456789'; for (let i = 0; i < 4; i++) { verf += characters.charAt(Math.floor(Math.random() * characters.length)); } return verf; } // 创建图形验证码 function createCaptcha() { const canvas = document.querySelector('#check'); const context = canvas.getContext('2d'); const captcha = generateCaptcha(); context.fillStyle = '#CD5C5C'; context.fillRect(0, 0, canvas.width, canvas.height); context.font = '300 100px Arial'; context.fillStyle = '#333'; context.textAlign = 'center'; context.textBaseline = 'middle'; context.fillText(captcha, canvas.width / 2, canvas.height / 2); for (let i = 0; i < 6; i++) { context.strokeStyle = getRandomColor(); context.beginPath(); context.moveTo(Math.random() * canvas.width, Math.random() * canvas.height); context.lineTo(Math.random() * canvas.width, Math.random() * canvas.height); context.stroke(); } return captcha; } function getRandomColor() { const letters = '023456789ASDFGHJKLQWERTYUIOPZXCVBNMasdfghjklqwertyuiopzxcvbnm'; let color = '#'; for (let i = 0; i < 6; i++) { color += letters[Math.floor(Math.random() * 16)]; } return color; } const captcha = createCaptcha();