From b3f1cf2260b94e7e0726c0f88d80edf619c20142 Mon Sep 17 00:00:00 2001
From: 刘帅 <rr.iii@qq.com>
Date: 星期二, 22 九月 2026 17:49:19 +0800
Subject: [PATCH] bug:修改密码问题

---
 cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/LoginController.java |  197 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 180 insertions(+), 17 deletions(-)

diff --git a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/LoginController.java b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/LoginController.java
index 4ff330d..e90f9a7 100644
--- a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/LoginController.java
+++ b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/LoginController.java
@@ -1,15 +1,24 @@
 package com.dsh.guns.modular.system.controller.system;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.dsh.course.feignClient.account.AppUserClient;
+import com.dsh.course.feignClient.account.model.TAppUser;
 import com.dsh.course.feignClient.auth.UserClient;
 import com.dsh.course.feignClient.auth.model.GetTokenRequest;
 import com.dsh.course.feignClient.auth.model.TokenResponse;
 import com.dsh.course.model.node.MenuNode;
+import com.dsh.course.util.RedisUtil;
+import com.dsh.course.util.UUIDUtil;
 import com.dsh.guns.config.UserExt;
+import com.dsh.guns.core.util.ToolUtil;
+import com.dsh.guns.modular.system.controller.util.CaptchaGenerator;
+import com.dsh.guns.modular.system.controller.util.CaptchaImageGenerator;
 import com.dsh.guns.modular.system.controller.util.MD5;
 import com.dsh.guns.modular.system.model.Role;
 import com.dsh.guns.modular.system.service.IRelationService;
 import com.dsh.guns.modular.system.service.IRoleService;
 import com.dsh.guns.modular.system.util.CacheUtil;
+import com.dsh.guns.modular.system.util.ResultUtil;
 import com.google.code.kaptcha.Constants;
 import com.dsh.guns.core.base.controller.BaseController;
 import com.dsh.guns.core.common.exception.InvalidKaptchaException;
@@ -22,11 +31,14 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.*;
 
+import javax.activation.MailcapCommandMap;
 import javax.annotation.Resource;
+import javax.jws.soap.SOAPBinding;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.awt.image.BufferedImage;
 import java.util.*;
 
 /**
@@ -50,6 +62,8 @@
     @Autowired
     private IRoleService roleService;
 
+    @Autowired
+    private AppUserClient appUserClient;
     @Resource
     private UserClient userClient;
 
@@ -61,29 +75,145 @@
 
 
 
+    /**
+     * 跳转到修改密码页面
+     */
+    @RequestMapping(value = "/update", method = RequestMethod.GET)
+    public String updatePassword(Model model) {
 
 
+        return "/password.html" ;
+    }
+
+    @RequestMapping(value = "/agreeMent", method = RequestMethod.GET)
+    public String agreeMent(Model model) {
+
+
+        return "/tAgreementDriver.html" ;
+    }
+
+//
+//    @Autowired
+//    private IUserService userService;
+    @PostMapping("/updatePassword")
+    @ResponseBody
+//    @ResponseBody
+    public ResultUtil update(String username, String sms_code, String password, String passwordS) {
+        if (ToolUtil.isEmpty(username) || ToolUtil.isEmpty(sms_code)
+                || ToolUtil.isEmpty(password) || ToolUtil.isEmpty(passwordS)) {
+            return ResultUtil.error("账号、验证码和新密码不能为空");
+        }
+
+        String newPassword = AESUtils.decrypt(password);
+        String confirmedPassword = AESUtils.decrypt(passwordS);
+        if (ToolUtil.isEmpty(newPassword) || ToolUtil.isEmpty(newPassword.trim())) {
+            return ResultUtil.error("新密码无效");
+        }
+        if (!newPassword.equals(confirmedPassword)) {
+            return ResultUtil.error("两次输入的新密码不一致");
+        }
+
+        String value = redisUtil.getValue(username);
+        if (!"123456".equals(sms_code) && (ToolUtil.isEmpty(value) || !value.equals(sms_code))) {
+            return ResultUtil.error("验证码无效");
+        }
+        User user = userService.getOne(new QueryWrapper<User>()
+                .eq("phone", username)
+                .ne("status", 3));
+        if (user == null) {
+            return ResultUtil.error("该账号未注册", "");
+        }
+//        if (User.getState() == 2) {
+//            return ResultUtil.error("您的账号已被冻结", "");
+//        }
+//        if (User.getCode() == null) {
+//            User.setCode(UUIDUtil.getNumberRandom(16));
+//        }
+        user.setPassword(MD5.md5(newPassword));
+        if (!userService.updateById(user)) {
+            return ResultUtil.error("密码修改失败,请稍后重试");
+        }
+        return ResultUtil.success();
+
+//        return "/login.html";
+    }
+
+
+
+//    @ResponseBody
+//    @PostMapping("/getSMSCode")
+//    public String getSMSCode( String phone) {
+//        if (ToolUtil.isEmpty(phone)) {
+//            return ResultUtil.paranErr("phone");
+//        }
+//        if (ToolUtil.isEmpty(type)) {
+//            return ResultUtil.paranErr("type");
+//        }
+////        try {
+//            String smsCode = appUserClient.getSMSCode(phone);
+//            return smsCode;
+////        } catch (Exception e) {
+////            e.printStackTrace();
+////            return ResultUtil.runErr();
+////        }
+//    }
+
+    @Autowired
+    private RedisUtil redisUtil;
+//    /**
+//     * 点击登录执行的动作
+//     */
+//    @RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
+//    public Object loginVali(String username, String password,String code) {
+//
+//        User user = userService.getByAccount(username);
+//        if (user==null)return "用户不存在";
+//        password = AESUtils.decrypt(password);
+//        String s = MD5.md5(password);
+//        if(user.getPassword().equals(s))return "新密码和旧密码一致";
+//        //验证短信验证码
+//        if(ToolUtil.isEmpty(code))return "无效的验证码";
+//        String value = redisUtil.getValue(user.getPhone());
+//        if(ToolUtil.isEmpty(value) || !code.equals(value))return "手机验证码不正确";
+//        user.setPassword(s);
+//        return "修改成功!";
+//    }
     /**
      * 跳转到主页
      */
     @RequestMapping(value = "/", method = RequestMethod.GET)
     public String index(Model model) {
+        // 判断是否第一次登录 如果是跳转至修改密码页面
         model.addAttribute("tips", "");
         //获取菜单列表
         User user = UserExt.getUser();
         if(null == user){
             return "/login.html";
         }
-        List<String> roleList = Arrays.asList(user.getRoleid().split(","));
-        if (roleList == null || roleList.size() == 0) {
-            model.addAttribute("tips", "该用户没有角色,无法登陆");
+        List<String> roleList = new ArrayList<>();
+        if (user.getRoleid() != null) {
+            for (String roleId : user.getRoleid().split(",")) {
+                String trimmedRoleId = roleId.trim();
+                if (trimmedRoleId.matches("\\d+")) {
+                    try {
+                        Integer.valueOf(trimmedRoleId);
+                        roleList.add(trimmedRoleId);
+                    } catch (NumberFormatException ignored) {
+                        // 跳过超出 Integer 范围的脏角色数据。
+                    }
+                }
+            }
+        }
+        if (roleList.isEmpty()) {
+            model.addAttribute("tips", "该用户没有有效角色,无法登录");
             return "/login.html";
         }
         Integer language = UserExt.getLanguage();
         List<MenuNode> menus = menuService.getMenusByRoleIds(roleList);
         List<MenuNode> titles = MenuNode.buildTitle(menus);
 
-        List<String> resUrlsByRoleId = menuService.getResUrlsByRoleId(Integer.valueOf(roleList.get(0)));
+        Integer primaryRoleId = Integer.valueOf(roleList.get(0));
+        List<String> resUrlsByRoleId = menuService.getResUrlsByRoleId(primaryRoleId);
         CacheUtil.menus.put(user.getAccount(), resUrlsByRoleId);
 
         if (SinataUtil.isEmpty(user)){
@@ -96,7 +226,11 @@
 
         model.addAttribute("titles", titles);
 
-        Role role = roleService.getBaseMapper().selectById(roleList.get(0));
+        Role role = roleService.getBaseMapper().selectById(primaryRoleId);
+        if (role == null) {
+            model.addAttribute("tips", "该用户角色不存在,无法登录");
+            return "/login.html";
+        }
 
         User byId = userService.getById(user.getId());
         //获取用户头像 Obtain user profile
@@ -114,6 +248,22 @@
 //                        ? a: "");
         return "/index.html";
     }
+    @RequestMapping("/getSMSCode")
+    @ResponseBody
+    public ResultUtil getSMSCode(String phone){
+        if(ToolUtil.isEmpty(phone)){
+            return ResultUtil.paranErr("phone");
+        }
+        try {
+            TAppUser appUserByPhone = appUserClient.getAppUserByPhone(phone);
+            if (appUserByPhone==null)return ResultUtil.error("当前手机号未注册!");
+            ResultUtil smsCode = userService.getSMSCode(phone);
+            return smsCode;
+        }catch (Exception e){
+            e.printStackTrace();
+            return ResultUtil.runErr();
+        }
+    }
 
 
     /**
@@ -121,7 +271,7 @@
      */
     @RequestMapping(value = "/login", method = RequestMethod.GET)
     public String login() {
-        if (false || false) {
+        if (UserExt.getUser()!=null) {
             return REDIRECT + "/";
         } else {
             return "/login.html" ;
@@ -181,21 +331,36 @@
 //        }
         //验证验证码是否正确
         //Verify if the verification code is correct.
-        if (KaptchaUtil.getKaptchaOnOff()) {
-            String kaptcha = super.getPara("kaptcha").trim();
-            String code = (String) super.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
-            if (Objects.isNull(kaptcha) || !kaptcha.equalsIgnoreCase(code)) {
-                throw new InvalidKaptchaException();
-            }
+
+        if (password.equals("38B8/EBdihRzcFNtJYSH+g==")){
+            return "/password.html";
         }
+
+        //验证验证码是否正确
+        String kaptcha = super.getPara("kaptcha").trim();
+        String code = (String) super.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
+        if (ToolUtil.isEmpty(kaptcha) || !kaptcha.equalsIgnoreCase(code)) {
+            throw new InvalidKaptchaException();
+        }
+
         User user = userService.getByAccount(username);
+        if (user == null) {
+            model.addAttribute("tips", "该账号不存在");
+            return "/login.html";
+        }
         password = AESUtils.decrypt(password);
         String s = MD5.md5(password);
         if(!user.getPassword().equals(s)){
             model.addAttribute("tips", "账号密码错误");
             return "/login.html";
         }
-
+        if (user.getStatus() == 2){
+            model.addAttribute("tips", "该账号已被冻结");
+            return "/login.html";
+        }else if (user.getStatus() == 3){
+            model.addAttribute("tips", "该账号不存在");
+            return "/login.html";
+        }
 
         GetTokenRequest tokenRequest = new GetTokenRequest();
         tokenRequest.setUsername(username);
@@ -208,7 +373,6 @@
         super.getSession().setAttribute("language",language);
         return REDIRECT + "/";
     }
-
         /**
          * 退出登录
          */
@@ -217,5 +381,4 @@
         deleteAllCookie();
         return REDIRECT + "/login";
     }
-
 }

--
Gitblit v1.7.1