欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

2019-7-29--登陆验证

程序员文章站 2022-08-20 15:34:50
upitem() { console.log("1 :", 1); let user = this.username; let pwd = this.password; if (user == "" || pwd == "") { this.$toast("账号或密码不能为空!!"); } else... ......
upitem() {
      console.log("1 :", 1);
      let user = this.username;
      let pwd = this.password;
      if (user == "" || pwd == "") {
        this.$toast("账号或密码不能为空!!");
      } else {
        let pattuser = /^[a-z]\w{2,14}$/;
        let pattpwd = /^\w{2,15}$/;
        if (!pattuser.test(user)) {
          this.$toast("用户名必须满足字符开头,\n 且长度在2-15为之间!!");
        } else {
          if (!pattpwd.test(pwd)) {
            this.$toast("密码必须为2-15位非特殊字符!");
          } else {
            var params = new urlsearchparams();
            params.append("username", user);
            params.append("password", pwd);
            this.axios
              .post("http://www.doubleb.fun/api/checklogin.php", params)
              .then(res => {
                if (res.data.status == "200") {
                  // console.log('res :', res);
                  this.uid = res.data.uid;
                  document.cookie =
                    "userstate=" + res.data.usertoken + "&uid=" + this.uid;
                  this.$toast("登录成功");
                  this.show = false;
                  //   settimeout(() => {
                  //     this.addcar();
                  //   }, 50);
                } else {
                  this.$toast("登录失败!! \n 请检查用户名或者密码后重新输入。");
                }

                console.log(res);
              })
              .catch(err => {
                console.error(err);
              });
          }
        }
      }
    }