diff --git a/tamguo-mms/src/main/java/com/tamguo/web/HistoryDocController.java b/tamguo-mms/src/main/java/com/tamguo/web/HistoryDocController.java index 99cce7b..a17e287 100644 --- a/tamguo-mms/src/main/java/com/tamguo/web/HistoryDocController.java +++ b/tamguo-mms/src/main/java/com/tamguo/web/HistoryDocController.java @@ -18,74 +18,108 @@ import com.tamguo.modules.book.model.DocumentEntity; import com.tamguo.modules.book.model.enums.DocumentStatusEnum; import com.tamguo.modules.book.service.IDocumentService; +/** + * HistoryDocController 类,处理历史文档相关的请求 + */ @Controller @RequestMapping(value="document") public class HistoryDocController { - + + // 日志记录器 private Logger logger = LoggerFactory.getLogger(getClass()); + @Autowired private IDocumentService iDocumentService; /** - * 历史记录 + * 历史记录请求处理方法 + * @param id 文档 ID + * @param model 模型视图对象 + * @return 模型视图 */ @SuppressWarnings("unchecked") - @RequestMapping(value = "history" , method = RequestMethod.POST) - public ModelAndView history(String id , ModelAndView model) { - model.setViewName("book/history"); + @RequestMapping(value = "history", method = RequestMethod.POST) + public ModelAndView history(String id, ModelAndView model) { + model.setViewName("book/history"); // 设置视图名称 + + // 根据 ID 查询文档实体 DocumentEntity document = iDocumentService.selectById(id); - model.addObject("document", document); + model.addObject("document", document); // 添加文档到模型 + + // 查询与该批次号且状态为历史的文档列表,并按创建日期降序排序 model.addObject("historyList", iDocumentService.selectList(Condition.create().eq("batch_no", document.getBatchNo()).eq("status", DocumentStatusEnum.HISTORY.getValue()).orderDesc(Arrays.asList("create_date")))); return model; } - + /** - * 删除 + * 删除请求处理方法 + * @param id 文档 ID + * @return 删除结果 */ - @RequestMapping(value = "history/delete" , method = RequestMethod.POST) + @RequestMapping(value = "history/delete", method = RequestMethod.POST) @ResponseBody public Result delete(String id) { try { + // 根据 ID 删除文档 iDocumentService.deleteById(id); } catch (Exception e) { - logger.error(e.getMessage() , e); - return Result.failResult("删除失败!"); + logger.error(e.getMessage(), e); // 记录错误日志 + return Result.failResult("删除失败!"); // 返回删除失败结果 } - return Result.successResult("删除成功!"); + return Result.successResult("删除成功!"); // 返回删除成功结果 } - + /** - * 恢复 + * 恢复请求处理方法 + * @param id 文档 ID + * @return 恢复结果 */ @SuppressWarnings("unchecked") - @RequestMapping(value = "history/restore" , method = RequestMethod.POST) + @RequestMapping(value = "history/restore", method = RequestMethod.POST) @ResponseBody public Result restore(String id) { try { + // 根据 ID 查询历史文档 DocumentEntity history = iDocumentService.selectById(id); - + + // 获取历史文档的内容和 markdown String content = history.getContent(); String markdown = history.getMarkdown(); + + // 查询与该批次号且状态为正常的文档 DocumentEntity document = iDocumentService.selectOne(Condition.create().eq("batch_no", history.getBatchNo()).eq("status", DocumentStatusEnum.NORMAL.getValue())); + + // 设置文档的内容和 markdown document.setContent(content); document.setMarkdown(markdown); document.setCover("no"); + + // 修改文档 iDocumentService.modify(document); - return Result.successResult(document); + return Result.successResult(document); // 返回恢复成功结果和文档 } catch (Exception e) { - logger.error(e.getMessage() , e); - return Result.failResult("恢复失败!"); + logger.error(e.getMessage(), e); // 记录错误日志 + return Result.failResult("恢复失败!"); // 返回恢复失败结果 } } - + + /** + * 比较请求处理方法 + * @param id 文档 ID + * @param model 模型视图对象 + * @return 模型视图 + */ @SuppressWarnings("unchecked") - @RequestMapping(value = "history/compare/{id}" , method = RequestMethod.POST) - @ResponseBody - public ModelAndView compare(@PathVariable String id , ModelAndView model) { - model.setViewName("book/compare"); + @RequestMapping(value = "history/compare/{id}", method = RequestMethod.POST) + public ModelAndView compare(@PathVariable String id, ModelAndView model) { + model.setViewName("book/compare"); // 设置视图名称 + + // 根据 ID 查询历史文档 DocumentEntity history = iDocumentService.selectById(id); - model.addObject("history", history); - model.addObject("document", iDocumentService.selectOne(Condition.create().eq("status", DocumentStatusEnum.NORMAL.getValue()).eq("batch_no", history.getBatchNo()))); + model.addObject("history", history); // 添加历史文档到模型 + + // 查询与该批次号且状态为正常的文档 + model.addObject("document", iDocumentService.selectOne(Condition.create().eq("batch_no", history.getBatchNo()).eq("status", DocumentStatusEnum.NORMAL.getValue()))); return model; } -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/web/IndexController.java b/tamguo-mms/src/main/java/com/tamguo/web/IndexController.java index 5eab6f6..ffba62b 100644 --- a/tamguo-mms/src/main/java/com/tamguo/web/IndexController.java +++ b/tamguo-mms/src/main/java/com/tamguo/web/IndexController.java @@ -1,30 +1,36 @@ package com.tamguo.web; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.servlet.ModelAndView; -import com.tamguo.modules.member.service.IMemberService; -import com.tamguo.utils.ShiroUtils; +import org.springframework.beans.factory.annotation.Autowired; // 注入依赖 +import org.springframework.stereotype.Controller; // 定义为控制器 +import org.springframework.web.bind.annotation.RequestMapping; // 处理请求映射 +import org.springframework.web.bind.annotation.RequestMethod; // 请求方法 +import org.springframework.web.servlet.ModelAndView; // 模型和视图 + +import com.tamguo.modules.member.service.IMemberService; // 会员服务接口 +import com.tamguo.utils.ShiroUtils; // Shiro 工具类 /** * 会员中心-首页 - * + * * @author tamguo * */ @Controller public class IndexController { - @Autowired + @Autowired // 自动注入会员服务实例 IMemberService iMemberService; - - @RequestMapping(value = {"index.html" , "/"}, method = RequestMethod.GET) - public ModelAndView index(ModelAndView model){ - model.setViewName("index"); - model.addObject("member", iMemberService.selectById(ShiroUtils.getMemberId())); + + /** + * 处理 index.html 或 / 的 GET 请求 + * + * @param model 模型和视图对象 + * @return 模型和视图对象 + */ + @RequestMapping(value = {"index.html", "/"}, method = RequestMethod.GET) + public ModelAndView index(ModelAndView model) { + model.setViewName("index"); // 设置视图名称为 "index" + model.addObject("member", iMemberService.selectById(ShiroUtils.getMemberId())); // 添加会员信息到模型中 return model; } - -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/web/LoginController.java b/tamguo-mms/src/main/java/com/tamguo/web/LoginController.java index 93f29a9..813b699 100644 --- a/tamguo-mms/src/main/java/com/tamguo/web/LoginController.java +++ b/tamguo-mms/src/main/java/com/tamguo/web/LoginController.java @@ -22,32 +22,67 @@ import com.tamguo.common.utils.Result; import com.tamguo.common.utils.SystemConstant; import com.tamguo.utils.ShiroUtils; +/** + * 登录控制器 + * + * @author tamguo + * + */ @Controller public class LoginController { + /** + * 生成验证码图片并设置到响应头和会话中 + * + * @param response 响应对象 + * @param session 会话对象 + * @throws ServletException 可能抛出的 Servlet 异常 + * @throws IOException 可能抛出的 IO 异常 + */ @RequestMapping("captcha.jpg") - public void captcha(HttpServletResponse response , HttpSession session) throws ServletException, IOException { + public void captcha(HttpServletResponse response, HttpSession session) throws ServletException, IOException { response.setHeader("Cache-Control", "no-store, no-cache"); response.setContentType("image/jpeg"); - + String a = CaptchaUtils.generateCaptcha(response.getOutputStream()); session.setAttribute(SystemConstant.KAPTCHA_SESSION_KEY, a); } - + + /** + * 处理登录页面的 GET 请求,设置模型和视图属性 + * + * @param redirectUrl 重定向 URL + * @param model 模型和视图对象 + * @return 模型和视图对象 + */ @RequestMapping(value = "/login.html", method = RequestMethod.GET) - public ModelAndView login(String redirectUrl , ModelAndView model){ + public ModelAndView login(String redirectUrl, ModelAndView model) { model.setViewName("login"); - model.addObject("isVerifyCode" , "0"); + model.addObject("isVerifyCode", "0"); model.addObject("redirectUrl", redirectUrl); return model; } - + + /** + * 处理提交登录的 POST 请求,进行登录验证和处理 + * + * @param username 用户名 + * @param password 密码 + * @param verifyCode 验证码 + * @param redirectUrl 重定向 URL + * @param model 模型和视图对象 + * @param session 会话对象 + * @param response 响应对象 + * @return 模型和视图对象或 null + * @throws IOException 可能抛出的 IO 异常 + */ @RequestMapping(value = "/submitLogin.html", method = RequestMethod.POST) - public ModelAndView submitLogin(String username , String password , String verifyCode , String redirectUrl , ModelAndView model , HttpSession session , HttpServletResponse response) throws IOException{ + public ModelAndView submitLogin(String username, String password, String verifyCode, String redirectUrl, ModelAndView model, HttpSession session, HttpServletResponse response) throws IOException { Result result = Result.successResult(null); - if(StringUtils.isEmpty(verifyCode)) { + + if (StringUtils.isEmpty(verifyCode)) { result = Result.result(202, null, "请输入验证码"); - } else if(StringUtils.isNotEmpty(verifyCode)){ + } else if (StringUtils.isNotEmpty(verifyCode)) { String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString(); if (!verifyCode.equalsIgnoreCase(kaptcha)) { result = Result.result(205, null, "验证码错误"); @@ -56,11 +91,11 @@ public class LoginController { UsernamePasswordToken token = new UsernamePasswordToken(username, password); try { subject.login(token); - + session.setAttribute("currMember", ShiroUtils.getMember()); - if(!StringUtils.isEmpty(redirectUrl)) { + if (!StringUtils.isEmpty(redirectUrl)) { response.sendRedirect(redirectUrl); - }else { + } else { response.sendRedirect("index.html"); } return null; @@ -70,27 +105,39 @@ public class LoginController { result = Result.result(202, null, "用户名或密码有误,请重新输入或找回密码"); } catch (LockedAccountException e) { result = Result.result(203, null, "账号被锁定"); - } + } } - } - model.setViewName("login"); + } + + model.setViewName("login"); model.addObject("code", result.getCode()); - model.addObject("msg" , result.getMessage()); + model.addObject("msg", result.getMessage()); model.addObject("username", username); return model; } - + + /** + * 处理迷你登录的 GET 请求,进行登录验证和处理 + * + * @param username 用户名 + * @param password 密码 + * @param captcha 验证码 + * @param model 模型和视图对象 + * @param session 会话对象 + * @return 结果对象 + */ @RequestMapping(value = "/miniLogin.html", method = RequestMethod.GET) @ResponseBody - public Result miniLogin(String username , String password , String captcha, ModelAndView model , HttpSession session) { + public Result miniLogin(String username, String password, String captcha, ModelAndView model, HttpSession session) { Result result = null; - if(StringUtils.isEmpty(captcha)) { + + if (StringUtils.isEmpty(captcha)) { result = Result.result(204, null, "请输入验证码"); - } else if(StringUtils.isNotEmpty(captcha)){ + } else if (StringUtils.isNotEmpty(captcha)) { String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString(); if (!captcha.equalsIgnoreCase(kaptcha)) { result = Result.result(205, null, "验证码错误"); - }else { + } else { Subject subject = ShiroUtils.getSubject(); UsernamePasswordToken token = new UsernamePasswordToken(username, password); try { @@ -103,18 +150,23 @@ public class LoginController { result = Result.result(202, null, "用户名或密码有误,请重新输入或找回密码"); } catch (LockedAccountException e) { result = Result.result(203, null, "账号被锁定"); - } + } } } return result; - } + } + /** + * 检查是否登录 + * + * @return 结果对象 + */ @RequestMapping(value = "/isLogin.html", method = RequestMethod.GET) @ResponseBody public Result isLogin() { - if(ShiroUtils.isLogin()) { - return Result.result(1, null , "已经登录"); + if (ShiroUtils.isLogin()) { + return Result.result(1, null, "已经登录"); } return Result.result(0, null, "未登录"); } -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/web/LogoutController.java b/tamguo-mms/src/main/java/com/tamguo/web/LogoutController.java index 4ef453b..a8a5e30 100644 --- a/tamguo-mms/src/main/java/com/tamguo/web/LogoutController.java +++ b/tamguo-mms/src/main/java/com/tamguo/web/LogoutController.java @@ -1,28 +1,27 @@ package com.tamguo.web; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpServletRequest; // 导入 HttpServletRequest 类 +import javax.servlet.http.HttpServletResponse; // 导入 HttpServletResponse 类 +import javax.servlet.http.HttpSession; // 导入 HttpSession 类 -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.stereotype.Controller; // 表示这是一个控制器类 +import org.springframework.web.bind.annotation.RequestMapping; // 用于处理请求映射 +import org.springframework.web.bind.annotation.RequestMethod; // 用于指定请求方法 -import com.tamguo.utils.ShiroUtils; +import com.tamguo.utils.ShiroUtils; // 导入 ShiroUtils 类 -@Controller +@Controller // 声明这是一个控制器 public class LogoutController { /** - * 注销 + * 注销方法 */ - @RequestMapping(value = "logout.html", method = RequestMethod.GET) - public String logout(HttpServletRequest request, HttpServletResponse response, HttpSession session) { - if (session.getAttribute("currMember") != null) { - session.removeAttribute("currMember"); - ShiroUtils.logout(); + @RequestMapping(value = "logout.html", method = RequestMethod.GET) // 映射到 "logout.html" 且使用 GET 方法的请求 + public String logout(HttpServletRequest request, HttpServletResponse response, HttpSession session) { // 接收请求、响应和会话对象 + if (session.getAttribute("currMember")!= null) { // 如果会话中当前成员不为空 + session.removeAttribute("currMember"); // 从会话中移除当前成员属性 + ShiroUtils.logout(); // 执行 ShiroUtils 的注销操作 } - return "redirect:/"; + return "redirect:/"; // 重定向到根路径 } - -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/web/PasswordController.java b/tamguo-mms/src/main/java/com/tamguo/web/PasswordController.java index fcd7116..3bd9318 100644 --- a/tamguo-mms/src/main/java/com/tamguo/web/PasswordController.java +++ b/tamguo-mms/src/main/java/com/tamguo/web/PasswordController.java @@ -1,81 +1,95 @@ package com.tamguo.web; -import javax.servlet.http.HttpSession; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; +import javax.servlet.http.HttpSession; // 导入 HttpSession 类 +import org.springframework.beans.factory.annotation.Autowired; // 表示自动注入 +import org.springframework.stereotype.Controller; // 声明这是一个控制器类 +import org.springframework.web.bind.annotation.RequestMapping; // 处理请求映射 +import org.springframework.web.bind.annotation.RequestMethod; // 指定请求方法 +import org.springframework.web.bind.annotation.ResponseBody; // 用于返回响应体 +import org.springframework.web.servlet.ModelAndView; // 模型和视图类 -import com.tamguo.common.utils.Result; -import com.tamguo.common.utils.SystemConstant; -import com.tamguo.modules.member.service.IMemberService; +import com.tamguo.common.utils.Result; // 通用结果类 +import com.tamguo.common.utils.SystemConstant; // 系统常量类 +import com.tamguo.modules.member.service.IMemberService; // 会员服务接口 -@Controller +@Controller // 控制器注解 public class PasswordController { - - @Autowired + + @Autowired // 自动注入会员服务 private IMemberService iMemberService; - + + /** + * 确认账号页面的请求映射 + */ @RequestMapping(value = "password/find.html", method = RequestMethod.GET) - public ModelAndView confirmAccount(ModelAndView model){ - model.setViewName("password/confirmAccount"); - return model; + public ModelAndView confirmAccount(ModelAndView model) { // 处理方法,接收模型和视图对象 + model.setViewName("password/confirmAccount"); // 设置视图名称 + return model; // 返回模型和视图 } - + + /** + * 提交确认账号的请求映射 + */ @RequestMapping(value = "password/confirmAccount.html", method = RequestMethod.POST) - public ModelAndView submitConfirmAccount(String username , String veritycode , ModelAndView model , HttpSession session){ - Result result = iMemberService.confirmAccount(username, veritycode); - String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString(); - if (!veritycode.equalsIgnoreCase(kaptcha)) { - result = Result.result(202, null, "验证码错误"); + public ModelAndView submitConfirmAccount(String username, String veritycode, ModelAndView model, HttpSession session) { // 处理方法,接收参数、模型和视图对象、会话对象 + Result result = iMemberService.confirmAccount(username, veritycode); // 调用会员服务的确认账号方法 + String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString(); // 获取验证码 + if (!veritycode.equalsIgnoreCase(kaptcha)) { // 比较验证码是否正确 + result = Result.result(202, null, "验证码错误"); // 设置错误结果 } - if(result.getCode() == 200){ - model.setViewName("password/securityCheck"); - model.addObject("result", result); - model.addObject("isEmail", username.contains("@") ? "1" : "0"); - }else{ - model.setViewName("password/confirmAccount"); - model.addObject("account", username); - model.addObject("username",username); - model.addObject("veritycode", veritycode); - model.addObject("code", result.getCode()); + if (result.getCode() == 200) { // 如果结果码为 200 + model.setViewName("password/securityCheck"); // 设置视图名称 + model.addObject("result", result); // 添加结果到模型 + model.addObject("isEmail", username.contains("@")? "1" : "0"); // 添加是否为邮箱的标识到模型 + } else { + model.setViewName("password/confirmAccount"); // 设置视图名称 + model.addObject("account", username); // 添加账号到模型 + model.addObject("username", username); // 添加用户名到模型 + model.addObject("veritycode", veritycode); // 添加验证码到模型 + model.addObject("code", result.getCode()); // 添加结果码到模型 } - return model; + return model; // 返回模型和视图 } - + + /** + * 安全检查页面的请求映射 + */ @RequestMapping(value = "password/securityCheck.html", method = RequestMethod.POST) - public ModelAndView securityCheck(String username , String isEmail , String mobileVcode , ModelAndView model){ - Result result = iMemberService.securityCheck(username , isEmail , mobileVcode); - if(result.getCode() == 200){ - model.addObject("username", username); - model.addObject("resetPasswordKey" , result.getResult()); - model.setViewName("password/resetPassword"); - }else{ - model.addObject("result", result); - model.addObject("isEmail", isEmail); - model.addObject("codeError", "1"); - model.setViewName("password/securityCheck"); + public ModelAndView securityCheck(String username, String isEmail, String mobileVcode, ModelAndView model) { // 处理方法,接收参数、模型和视图对象 + Result result = iMemberService.securityCheck(username, isEmail, mobileVcode); // 调用会员服务的安全检查方法 + if (result.getCode() == 200) { // 如果结果码为 200 + model.addObject("username", username); // 添加用户名到模型 + model.addObject("resetPasswordKey", result.getResult()); // 添加重置密码键到模型 + model.setViewName("password/resetPassword"); // 设置视图名称 + } else { + model.addObject("result", result); // 添加结果到模型 + model.addObject("isEmail", isEmail); // 添加是否为邮箱的标识到模型 + model.addObject("codeError", "1"); // 添加错误标识到模型 + model.setViewName("password/securityCheck"); // 设置视图名称 } - return model; + return model; // 返回模型和视图 } - + + /** + * 重置密码页面的请求映射 + */ @RequestMapping(value = "password/resetPassword.html", method = RequestMethod.POST) - public ModelAndView resetPassword(String resetPasswordKey , String username , String password , String verifypwd , ModelAndView model){ - Result result = iMemberService.resetPassword(resetPasswordKey , username , password , verifypwd); - if(result.getCode() == 200){ - model.setViewName("password/resetPwSuccess"); - }else{ - model.setViewName("password/resetPassword"); + public ModelAndView resetPassword(String resetPasswordKey, String username, String password, String verifypwd, ModelAndView model) { // 处理方法,接收参数、模型和视图对象 + Result result = iMemberService.resetPassword(resetPasswordKey, username, password, verifypwd); // 调用会员服务的重置密码方法 + if (result.getCode() == 200) { // 如果结果码为 200 + model.setViewName("password/resetPwSuccess"); // 设置视图名称 + } else { + model.setViewName("password/resetPassword"); // 设置视图名称 } - return model; + return model; // 返回模型和视图 } - + + /** + * 检查账号的请求映射 + */ @RequestMapping(value = "password/checkAccount.html", method = RequestMethod.GET) - @ResponseBody - public Result checkAccount(String account){ - return iMemberService.checkAccount(account); + @ResponseBody // 返回响应体 + public Result checkAccount(String account) { // 处理方法,接收账号参数 + return iMemberService.checkAccount(account); // 调用会员服务的检查账号方法并返回结果 } - -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/web/RegisterController.java b/tamguo-mms/src/main/java/com/tamguo/web/RegisterController.java index 59eb872..ae32fc3 100644 --- a/tamguo-mms/src/main/java/com/tamguo/web/RegisterController.java +++ b/tamguo-mms/src/main/java/com/tamguo/web/RegisterController.java @@ -19,41 +19,74 @@ import com.tamguo.modules.member.model.MemberEntity; import com.tamguo.modules.member.service.IMemberService; import com.tamguo.utils.ShiroUtils; +/** + * RegisterController 类,处理注册相关的请求 + */ @Controller public class RegisterController { - + + /** + * 依赖注入 IMemberService + */ @Autowired private IMemberService iMemberService; + /** + * 处理 /register.html 的 GET 请求,返回注册页面的视图 + * @param model 模型视图对象 + * @param session HttpSession 对象 + * @return 模型视图对象 + */ @RequestMapping(value = "/register.html", method = RequestMethod.GET) - public ModelAndView register(ModelAndView model , HttpSession session) { + public ModelAndView register(ModelAndView model, HttpSession session) { model.setViewName("register"); return model; - } - + } + + /** + * 处理 /checkUsername.html 的 GET 请求,检查用户名是否可用,并返回结果 + * @param username 用户名 + * @return 检查结果 + */ @RequestMapping(value = "/checkUsername.html", method = RequestMethod.GET) @ResponseBody - public Result checkUsername(String username){ + public Result checkUsername(String username) { return iMemberService.checkUsername(username); } - + + /** + * 处理 /checkMobile.html 的 GET 请求,检查手机号是否可用,并返回结果 + * @param mobile 手机号 + * @return 检查结果 + */ @RequestMapping(value = "/checkMobile.html", method = RequestMethod.GET) @ResponseBody - public Result checkMobile(String mobile){ + public Result checkMobile(String mobile) { return iMemberService.checkMobile(mobile); } - + + /** + * 处理 /subRegister 的 POST 请求,进行注册操作 + * @param member 会员实体对象 + * @param session HttpSession 对象 + * @return 注册结果 + */ @RequestMapping(value = "/subRegister", method = RequestMethod.POST) @ResponseBody - public Result subRegister(@RequestBody MemberEntity member , HttpSession session){ + public Result subRegister(@RequestBody MemberEntity member, HttpSession session) { Result result = iMemberService.register(member); - if(result.getCode() == 200) { + if (result.getCode() == 200) { + // 获取 Shiro 主体 Subject subject = ShiroUtils.getSubject(); + // 获取注册成功的会员实体对象 MemberEntity memberEntity = (MemberEntity) result.getResult(); + // 创建用户名密码令牌 UsernamePasswordToken token = new UsernamePasswordToken(memberEntity.getUsername(), member.getPassword()); try { + // 主体登录 subject.login(token); - + + // 设置当前会员到会话中 session.setAttribute("currMember", ShiroUtils.getMember()); } catch (UnknownAccountException e) { return Result.result(201, null, "用户名或密码有误,请重新输入或找回密码"); @@ -61,9 +94,8 @@ public class RegisterController { return Result.result(202, null, "用户名或密码有误,请重新输入或找回密码"); } catch (LockedAccountException e) { return Result.result(203, null, "账号被锁定"); - } + } } return result; } - -} +} \ No newline at end of file diff --git a/tamguo-mms/src/main/java/com/tamguo/web/SmsController.java b/tamguo-mms/src/main/java/com/tamguo/web/SmsController.java index e66eeb5..13c6c60 100644 --- a/tamguo-mms/src/main/java/com/tamguo/web/SmsController.java +++ b/tamguo-mms/src/main/java/com/tamguo/web/SmsController.java @@ -10,21 +10,34 @@ import com.aliyuncs.exceptions.ClientException; import com.tamguo.common.utils.Result; import com.tamguo.modules.sys.service.ISmsService; +/** + * SmsController 类,处理短信相关的请求 + */ @Controller public class SmsController { - + + /** + * 依赖注入 ISmsService + */ @Autowired - ISmsService iSmsService; + private ISmsService iSmsService; + /** + * 处理 /sendFindPasswordSms 的 GET 请求,发送找回密码短信 + * @param mobile 手机号 + * @return 发送结果 + */ @RequestMapping(value = {"sendFindPasswordSms"}, method = RequestMethod.GET) @ResponseBody - public Result sendFindPasswordSms(String mobile){ + public Result sendFindPasswordSms(String mobile) { try { + // 调用 ISmsService 发送找回密码短信,并返回结果 return iSmsService.sendFindPasswordSms(mobile); } catch (ClientException e) { + // 打印异常信息 e.printStackTrace(); } + // 返回错误结果 return Result.result(500, null, ""); } - -} +} \ No newline at end of file