山东大学软件学院项目实训weblab-6

前言

项目地址
本项目是为开发一套容器化的开发、运行、测试环境,用以支持Web开发、程序设计等课程的实验教学。

任务

实现登出和忘记密码功能

登出

function goto_codingview() {
      ElMessageBox.confirm(
        '是否确认退出?',
        '退出提示',
        {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
        }
      )
        .then(() => {
          //点击确认
          let param = new FormData();
          request('/weblab/user/logout', param,store.getToken)
          .then(res=>{
            if(res.status==200&&res.data.msg=='success'){
              store.userLogout();
              router.push({ path: '/' });
            }
          })
          .catch(error=>{
            console.log(error);
          })
          
        })
        .catch(() => {
          //点击取消
          router.push({ path: '/login_home' });
        })
    }

登出时将本地存储的相关信息删除掉

userLogout() {
      this.isLogin = 0;
      this.userId='';
      this.userPassword='';
      this.token='';
      localStorage.removeItem('isLogin');
      localStorage.removeItem('userId');
      localStorage.removeItem('userPassword');
      localStorage.removeItem('token');

    },

忘记密码

输入邮箱获取验证码

const getCheckCode = async () => {
      //发送邮箱验证码
      const form = unref(emailRef);
      if (!form) return
      try {
        await form.validate();
        let param = new FormData();
        param.append('email', emailForm.email);
        showEmail.value = 2;
        request('/weblab/user/forget_password', param)
          .then(res => {
            if (res.status == 200 && res.data.msg == 'success') {
              
            }
          })
          .catch(error => {
            console.log(error.code, error.message);
            if (error.code == 'ECONNABORTED') {
              // showEmail.value = 2;
              ElMessage({
                showClose: true,
                message: '网络超时,请稍后再试',
                type: 'error',
                center: true,
                grouping: true
              })
            }
          })
      } catch (error: any) {

        ElMessage({
          showClose: true,
          message: '输入格式不正确',
          type: 'error',
          center: true,
          grouping: true,
        })
      }
    }

输入验证码

const next = async () => {
      const form = unref(emailCheckFormRef);
      if (!form) return
      try {
        await form.validate();
        showEmail.value = 3;
      } catch (error) {
        ElMessage({
          showClose: true,
          message: '验证码错误',
          type: 'error',
          center: true,
          grouping: true
        })
      }
    };

更改密码

const goHome = async () => {
      const form = unref(resetFormRef);
      if (!form) return
      try {
        await form.validate();

        //todo 发送修改密码请求
        let param = new FormData();
        param.append('code', emailCheckForm.checkCode);
        param.append('password', resetForm.newPass);
        request('/weblab/user/reset_password', param)
          .then(res => {

            console.log(emailCheckForm.checkCode);
            console.log(resetForm.newPass);
            if (res.status == 200 && res.data.msg == 'success') {
              btnDisabled.value = true;

              ElMessage({
                showClose: true,
                message: '修改密码成功',
                type: 'success',
                center: true,
                grouping: true,
                onClose: () => { router.push({ path: '/login' }) }
              })
            }

          })
          .catch(error => {
            showEmail.value = 2;
            ElMessage({
              showClose: true,
              message: '验证码错误',
              type: 'error',
              center: true,
              grouping: true
            })

          })


      } catch (error) {
        ElMessage({
          showClose: true,
          message: '密码格式错误',
          type: 'error',
          center: true,
          grouping: true
        })
      }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值