1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

小程序修改密码

This commit is contained in:
程序员小墨 2023-04-17 18:46:15 +08:00
parent 0238251ab0
commit b72f36febc
14 changed files with 255 additions and 14 deletions

View File

@ -1,18 +1,28 @@
还要做的部分
【想一想访客怎么处理】
小程序提审要做的:
小程序首页密码修改
订单发货小程序端显示发货详情
体温上报添加一个按钮 可以删除当日填报
小程序扫门禁码之后门禁开门(扫码 websocket 推到门禁端),小程序端显示开门成功
项目部署到服务器
小程序端用户头像
大门 人员进出 后台管理(进出日志)
后台订单管理页
订单发货小程序端显示
小程序扫门禁码之后门禁开门(扫码 websocket 推到门禁端)
门禁端左侧提示文字修改
@ -20,9 +30,6 @@
后台管理 按照id进行筛选
体温上报添加一个按钮 可以删除当日填报
项目部署到服务器
& 演示时快速创建账号
& 小程序提审(提审时隐藏小商店 调试按钮、上帝按钮)
& 发给老班看一看

View File

@ -99,7 +99,7 @@ public class UserController {
user = new User();
user.setId(null);
user.setUsername(UUID.randomUUID().toString().replace("-", "").substring(0, 10));
user.setPassword(UUID.randomUUID().toString());
user.setPassword("");
user.setRealname("微信用户" + user.getUsername().substring(0, 5));
user.setRoleId(3);
user.setPermission("1");
@ -127,6 +127,34 @@ public class UserController {
return userService.getUserById(id);
}
/**
* 修改密码的接口
*
* @param oldpwd
* @param newpwd
* @return
*/
@PostMapping("/updatePwd")
@ResponseBody
public Res updatePwd(@RequestParam("userId") Integer userId,
@RequestParam("oldpwd") String oldpwd,
@RequestParam("newpwd") String newpwd) {
if (newpwd == null || Objects.equals(newpwd, "")) {
return Res.error("新密码不能为空");
}
if (oldpwd == null) {
oldpwd = "";
}
// 调用Service层的方法传入旧密码和新密码
boolean result = userService.updatePwd(userId, oldpwd, newpwd);
// 根据结果返回响应
if (result) {
return Res.success("修改成功");
} else {
return Res.error("旧密码不正确,修改失败");
}
}
/**
* 获取用户列表
*

View File

@ -3,6 +3,7 @@ package com.cxyxiaomo.epp.user.dao;
import com.cxyxiaomo.epp.common.pojo.User;
import com.cxyxiaomo.epp.common.vo.UserVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@ -15,6 +16,8 @@ public interface UserDao {
public boolean updateUser(User user);
public boolean updatePwd(@Param("id") Integer id, @Param("password") String password);
public User getUserById(Integer id);
User getUserByUsername(String username);

View File

@ -3,10 +3,12 @@ package com.cxyxiaomo.epp.user.service;
import com.cxyxiaomo.epp.common.pojo.User;
import com.cxyxiaomo.epp.common.vo.UserVO;
import com.cxyxiaomo.epp.user.dao.UserDao;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Objects;
@Service
public class UserService {
@ -47,4 +49,30 @@ public class UserService {
public boolean deleteUser(Integer userId) {
return userDao.deleteUserById(userId);
}
/**
* 修改密码的方法
*
* @param oldpwd
* @param newpwd
* @return
*/
public boolean updatePwd(Integer userId, String oldpwd, String newpwd) {
// 获取当前登录的用户信息
User user = userDao.getUserById(userId);
// 创建一个密码加密器
String oldpwdHash = DigestUtils.sha512Hex(oldpwd);
// 判断旧密码是否匹配 或者是未设置密码的初始用户
if (Objects.equals(oldpwdHash, user.getPassword()) ||
(Objects.equals(oldpwd, "") && Objects.equals(user.getPassword(), ""))) {
// 如果匹配对新密码进行加密
String newpwdHash = DigestUtils.sha512Hex(newpwd);
// 调用mapper层的方法更新数据库中的密码
userDao.updatePwd(user.getId(), newpwdHash);
return true;
} else {
// 如果不匹配返回false
return false;
}
}
}

View File

@ -48,6 +48,11 @@
</set>
WHERE id = #{id}
</update>
<update id="updatePwd" parameterType="com.cxyxiaomo.epp.common.pojo.User">
UPDATE user
SET `password` = #{password}
WHERE id = #{id}
</update>
<select id="getUserById" parameterType="java.lang.Integer" resultType="com.cxyxiaomo.epp.common.pojo.User">
SELECT *
FROM user

View File

@ -10,7 +10,8 @@
"pages/shop/orderDetail",
"pages/shop/myOrder",
"pages/scan/entrance",
"pages/person/person"
"pages/person/person",
"pages/person/updpwd"
],
"window": {
"backgroundTextStyle": "dark",
@ -68,4 +69,4 @@
"lazyCodeLoading": "requiredComponents",
"style": "v2",
"sitemapLocation": "sitemap.json"
}
}

View File

@ -136,7 +136,7 @@ Page({
filterMenuItems = filterMenuItems
.filter((item) => {
let a = indexItem.includes(item.url)
console.log("filterMenuItems -> filter", item.url, indexItem)
// console.log("filterMenuItems -> filter", item.url, indexItem)
return a
})
return filterMenuItems

View File

@ -15,7 +15,7 @@
</view>
</view>
<view style="text-align: center;">
<button type="warn" bindtap="magicButton">上帝按钮</button>
<!-- <button type="warn" bindtap="magicButton">上帝按钮</button> -->
<!-- <button type="primary" size="mini" bindtap="toggleDot">切换小红点</button> -->
<!-- <text>调试信息:{{ debugText }}</text> -->
</view>

View File

@ -24,6 +24,10 @@ Page({
id: "myOrder",
title: "我的订单",
},
{
id: "updpwd",
title: "修改密码",
},
{
id: "logout",
color: 'red',
@ -140,6 +144,12 @@ Page({
})
break
// 修改密码
case "updpwd":
wx.navigateTo({
url: '/pages/person/updpwd'
})
break
// 退出登录
case "logout":
wx.clearStorageSync()

View File

@ -0,0 +1,105 @@
// pages/person/updpwd.js
// 获取应用实例
const app = getApp()
Page({
data: {
waiting: false,
oldpwd: '', // 旧密码
newpwd: '', // 新密码
newpwd2: '' // 确认新密码
},
// 表单提交事件
submitForm(e) {
// 获取表单数据
let { oldpwd, newpwd, newpwd2 } = e.detail.value
// 验证表单数据
if (!newpwd || !newpwd2) {
// 新密码不能为空
wx.showToast({
title: '新密码不能为空',
icon: 'none'
})
} else if (newpwd !== newpwd2) {
// 两次密码不一致
wx.showToast({
title: '两次密码不一致',
icon: 'none'
})
} else {
let userInfo = wx.getStorageSync("userInfo")
if (!userInfo || !userInfo.id) {
console.log("userInfo", userInfo)
wx.showModal({
title: '登陆失效',
content: '请重新登录',
showCancel: false,
complete: (res) => {
wx.navigateBack()
}
})
}
// 调用后台接口修改密码
this.setData({
waiting: true,
})
wx.showNavigationBarLoading()
var that = this
wx.request({
url: app.globalData.baseUrl + '/user/updatePwd', // 后台接口地址
method: 'POST',
data: {
userId: userInfo.id,
oldpwd, // 旧密码
newpwd // 新密码
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success(res) {
wx.hideNavigationBarLoading()
that.setData({
waiting: false,
})
console.log("res.data.success", res.data.success)
// 请求成功
if (res.data.success) {
// 修改成功
wx.showModal({
title: '修改成功',
content: '密码修改成功',
showCancel: false,
complete: (res) => {
// 返回上一页
wx.navigateBack()
}
})
} else {
// 修改失败
// wx.showToast({
// title: res.data.msg,
// icon: 'none'
// })
wx.showModal({
title: '修改失败',
content: res.data.msg,
showCancel: false
})
}
},
fail(err) {
wx.hideNavigationBarLoading()
that.setData({
waiting: false,
})
// 请求失败
wx.showToast({
title: '网络异常,请稍后重试',
icon: 'none'
})
},
})
}
}
})

View File

@ -0,0 +1,4 @@
{
"usingComponents": {},
"navigationBarTitleText": "修改密码"
}

View File

@ -0,0 +1,19 @@
<!-- pages/person/updpwd.wxml -->
<view class="container">
<view class="title">修改密码</view>
<view style="text-align: center; margin-bottom: 12px;">
* 微信快捷登录的初始密码为空
</view>
<form bindsubmit="submitForm" report-submit="true">
<view class="input-group">
<input type="password" name="oldpwd" placeholder="请输入旧密码" required />
</view>
<view class="input-group">
<input type="password" name="newpwd" placeholder="请输入新密码" required />
</view>
<view class="input-group">
<input type="password" name="newpwd2" placeholder="请确认新密码" required />
</view>
<button disabled="{{ waiting }}" type="primary" form-type="submit">提交</button>
</form>
</view>

View File

@ -0,0 +1,31 @@
/* pages/person/updpwd.wxss */
.container {
padding: 20rpx;
}
.title {
font-size: 36rpx;
font-weight: bold;
text-align: center;
margin-bottom: 40rpx;
}
.input-group {
margin-bottom: 20rpx;
}
input {
width: 100%;
height: 80rpx;
border: 1rpx solid #ccc;
border-radius: 10rpx;
padding: 0 20rpx;
}
button {
width: 100%;
height: 80rpx;
background-color: #1aad19;
color: white;
border-radius: 10rpx;
}

View File

@ -97,9 +97,9 @@ let menuItemDict = {
},
'update-password': {
for: ['user', 'admin'],
title: "密码修改",
title: "修改密码",
image: "updPwd.png",
switchFunc: switchTab,
switchFunc: navigateTo,
url: '/pages/person/updpwd'
},
// 'assign': {