var operationStatus = "login"; function login() { clearMessage(); username = $("#username").val(); password = $("#passwd").val(); if (!checkInputDataCorrect(username, password)) { return; } encPassword = encryptPassword(password); postData = { "user_name": username, "password": encPassword }; sendLogin(postData); } function sendLogin(postData) { $.ajax({ url: "/api/v1/user/login", type: "post", dataType: "json", contentType: "application/json", data: JSON.stringify(postData), success: (result) => { console.log("获取到数据:" + JSON.stringify(result)); resultCode = result.code; switch(resultCode) { case 1: showMessage("好啦"); storeToken(result.data.access_token); showDialog("LoginTest", "获得数据:" + JSON.stringify(result.data)); break; case 2: showMessage("请求的数据不对哦"); break; case 3: showMessage("密码或用户名不正确..."); break; case -1: showMessage("哦豁,有个家伙写BUG了"); break; default : showMessage("出现了不知道什么原因的错误,应给是服务器那边的锅") } }, error: (msg, status) => { console.log(msg.status); showMessage("登录时发生错误:" + status + " " + msg.status); } }) } function register() { clearMessage(); username = $("#username").val(); password = $("#passwd").val(); if (!checkInputDataCorrect(username, password)) { return; } encPassword = encryptPassword(password); postData = { "user_name": username, "password": encPassword }; $.ajax({ url: "/api/v1/user/register", type: "post", dataType: "json", contentType: "application/json", data: JSON.stringify(postData), success: (result) => { console.log("获取到数据:" + JSON.stringify(result)); resultCode = result.code; switch(resultCode) { case 1: showMessage("好啦"); storeToken(result.data.access_token); showDialog("RegisterTest", "获得数据:" + JSON.stringify(result.data)); break; case 2: showMessage("请求的数据不对哦"); break; case 4: showMessage("用户名已经被别人用啦"); break; case -1: showMessage("哦豁,有个家伙写BUG了"); break; default : showMessage("出现了不知道什么原因的错误,应给是服务器那边的锅") } }, error: (msg, status) => { console.log(msg.status); showMessage("注册时发生错误:" + status + " " + msg.status); } }) } function jumpToFillInformation() { } function checkInputDataCorrect(username, password) { if (username == "" || passwd == "") { showMessage("用户名和密码都不可以是空的哦"); return false; } if (!isLetter(username)) { showMessage("用户名只能是大小写字母和数字哦"); return false; } if (!isNormalCharacter(passwd)) { showMessage("不知道你往密码框都搞了点什么东西..."); return false; } if (username.length > 32) { showMessage("用户名太长啦(应该小于32个字符)"); return; } if (password.length < 8) { showMessage("密码长度太短啦(大于等于8小于等于32)"); return; } else if (password > 32){ showMessage("密码长度太长啦(大于等于8小于等于32)"); return; } return true; }