微信小程序云开发——实现 线上注册,登录的逻辑,并保存账号到云数据库( 四 ):修改密码


要有遥不可及的梦想,也要有脚踏实地的本事。----------- Grapefruit.Banuit Gang(香柚帮)


继上一章节柚子完成了登录的逻辑代码已经好久了,都给忘了,这一章节补上修改密码逻辑代码,修改密码相对注册登录就简单多了,很好理解,直接上代码吧:

下面是柚子写的登录页面,仅供参考:

wxml:

<view class="container">
  <image src="https://7069-pintu-game-52d2a-1301643624.tcb.qcloud.la/pintu_icon/login_bg.jpg"></image>
</view>
<view class="login_box">
  <view class="section">
    <input password='true' placeholder="请输入原始密码" value='{{old_pass}}' placeholder-class="color" bindblur='old_pass' />
    <image src="https://7069-pintu-game-52d2a-1301643624.tcb.qcloud.la/pintu_icon/pass.png"></image>
  </view>
  <view class="section">
    <input password='true' placeholder="请输入新密码" value='{{pass1}}' placeholder-class="color" bindblur='pass1' />
    <image src="https://7069-pintu-game-52d2a-1301643624.tcb.qcloud.la/pintu_icon/pass.png"></image>
  </view>
  <view class="section">
    <input password='true' placeholder="请确认新密码" value='{{pass2}}' placeholder-class="color" bindblur='pass2' />
    <image src="https://7069-pintu-game-52d2a-1301643624.tcb.qcloud.la/pintu_icon/pass.png"></image>
  </view>
  <button class="login" type="primary" bindtap="confirm">确定</button>
</view>

wxss:

/* pages/login/login.wxss */
.container {
  position: absolute;
  width: 100%;
  height: 100%;
}
.container image {
  width: 100%;
  height: 100%;
}
.login_box{
  width: 90%;
  position: absolute;
  top: 15%;
  left: 5%;
}
.section{
  width: 100%;
  border-bottom: 4rpx solid #FFF;
  margin-top: 40rpx;
  position: relative;
}
.section input{
  height: 100rpx;
  color: #FFF;
  box-sizing: border-box;
  padding-left: 80rpx;
  font-size: 36rpx;
}
.section image{
  width: 60rpx;
  height: 60rpx;
  position: absolute;
  top: 20rpx;
  left: 10rpx;
}
.color{
  color: #FFF;
}
.login{
  margin-top: 200rpx;
}

app.wxss

/**app.wxss**/
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  box-sizing: border-box;
} 

大致样子是这样的:

js代码: 

const db = wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    old_pass: '',
    pass1: '',
    pass2: ''
  },
  old_pass(e) {
    this.setData({
      old_pass: e.detail.value
    })
  },
  pass1(e) {
    this.setData({
      pass1: e.detail.value
    })
  },
  pass2(e) {
    this.setData({
      pass2: e.detail.value
    })
  },
  confirm() {
    var that = this
    // 重置密码接口
    db.collection('login').doc(wx.getStorageSync('userId')).get().then(res => {
      if (res.data.pass1 == that.data.old_pass) {
        db.collection('login').doc(wx.getStorageSync('userId')).update({
          data: {
            pass1: that.data.pass1,
            pass2: that.data.pass2
          },
          success: function(res) {
            if (res.errMsg == 'document.update:ok') {
              wx.showToast({
                title: '重置成功',
                icon: 'none',
                duration: 2000
              })
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1
                })
              }, 1000)
            }
          }
        })
      } else {
        wx.showToast({
          title: '原始密码输入错误',
          icon: 'none',
          duration: 2000
        })
      }
    })
  },
})

就这些了,看不懂的可以留言咨询,希望能帮助到你。

  • 1
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@Grapefruit

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值