Merge remote-tracking branch 'origin/在线访问lhj' into 在线访问lhj

在线访问lhj
李宏杰 8 months ago
commit e22e504c4b

@ -18,74 +18,108 @@ import com.tamguo.modules.book.model.DocumentEntity;
import com.tamguo.modules.book.model.enums.DocumentStatusEnum; import com.tamguo.modules.book.model.enums.DocumentStatusEnum;
import com.tamguo.modules.book.service.IDocumentService; import com.tamguo.modules.book.service.IDocumentService;
/**
* HistoryDocController
*/
@Controller @Controller
@RequestMapping(value="document") @RequestMapping(value="document")
public class HistoryDocController { public class HistoryDocController {
// 日志记录器
private Logger logger = LoggerFactory.getLogger(getClass()); private Logger logger = LoggerFactory.getLogger(getClass());
@Autowired @Autowired
private IDocumentService iDocumentService; private IDocumentService iDocumentService;
/** /**
* *
* @param id ID
* @param model
* @return
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequestMapping(value = "history" , method = RequestMethod.POST) @RequestMapping(value = "history", method = RequestMethod.POST)
public ModelAndView history(String id , ModelAndView model) { public ModelAndView history(String id, ModelAndView model) {
model.setViewName("book/history"); model.setViewName("book/history"); // 设置视图名称
// 根据 ID 查询文档实体
DocumentEntity document = iDocumentService.selectById(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")))); model.addObject("historyList", iDocumentService.selectList(Condition.create().eq("batch_no", document.getBatchNo()).eq("status", DocumentStatusEnum.HISTORY.getValue()).orderDesc(Arrays.asList("create_date"))));
return model; return model;
} }
/** /**
* *
* @param id ID
* @return
*/ */
@RequestMapping(value = "history/delete" , method = RequestMethod.POST) @RequestMapping(value = "history/delete", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Result delete(String id) { public Result delete(String id) {
try { try {
// 根据 ID 删除文档
iDocumentService.deleteById(id); iDocumentService.deleteById(id);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage() , e); logger.error(e.getMessage(), e); // 记录错误日志
return Result.failResult("删除失败!"); return Result.failResult("删除失败!"); // 返回删除失败结果
} }
return Result.successResult("删除成功!"); return Result.successResult("删除成功!"); // 返回删除成功结果
} }
/** /**
* *
* @param id ID
* @return
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequestMapping(value = "history/restore" , method = RequestMethod.POST) @RequestMapping(value = "history/restore", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Result restore(String id) { public Result restore(String id) {
try { try {
// 根据 ID 查询历史文档
DocumentEntity history = iDocumentService.selectById(id); DocumentEntity history = iDocumentService.selectById(id);
// 获取历史文档的内容和 markdown
String content = history.getContent(); String content = history.getContent();
String markdown = history.getMarkdown(); String markdown = history.getMarkdown();
// 查询与该批次号且状态为正常的文档
DocumentEntity document = iDocumentService.selectOne(Condition.create().eq("batch_no", history.getBatchNo()).eq("status", DocumentStatusEnum.NORMAL.getValue())); DocumentEntity document = iDocumentService.selectOne(Condition.create().eq("batch_no", history.getBatchNo()).eq("status", DocumentStatusEnum.NORMAL.getValue()));
// 设置文档的内容和 markdown
document.setContent(content); document.setContent(content);
document.setMarkdown(markdown); document.setMarkdown(markdown);
document.setCover("no"); document.setCover("no");
// 修改文档
iDocumentService.modify(document); iDocumentService.modify(document);
return Result.successResult(document); return Result.successResult(document); // 返回恢复成功结果和文档
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage() , e); logger.error(e.getMessage(), e); // 记录错误日志
return Result.failResult("恢复失败!"); return Result.failResult("恢复失败!"); // 返回恢复失败结果
} }
} }
/**
*
* @param id ID
* @param model
* @return
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequestMapping(value = "history/compare/{id}" , method = RequestMethod.POST) @RequestMapping(value = "history/compare/{id}", method = RequestMethod.POST)
@ResponseBody public ModelAndView compare(@PathVariable String id, ModelAndView model) {
public ModelAndView compare(@PathVariable String id , ModelAndView model) { model.setViewName("book/compare"); // 设置视图名称
model.setViewName("book/compare");
// 根据 ID 查询历史文档
DocumentEntity history = iDocumentService.selectById(id); DocumentEntity history = iDocumentService.selectById(id);
model.addObject("history", history); model.addObject("history", history); // 添加历史文档到模型
model.addObject("document", iDocumentService.selectOne(Condition.create().eq("status", DocumentStatusEnum.NORMAL.getValue()).eq("batch_no", history.getBatchNo())));
// 查询与该批次号且状态为正常的文档
model.addObject("document", iDocumentService.selectOne(Condition.create().eq("batch_no", history.getBatchNo()).eq("status", DocumentStatusEnum.NORMAL.getValue())));
return model; return model;
} }
} }

@ -1,12 +1,13 @@
package com.tamguo.web; package com.tamguo.web;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired; // 注入依赖
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller; // 定义为控制器
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping; // 处理请求映射
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod; // 请求方法
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView; // 模型和视图
import com.tamguo.modules.member.service.IMemberService;
import com.tamguo.utils.ShiroUtils; import com.tamguo.modules.member.service.IMemberService; // 会员服务接口
import com.tamguo.utils.ShiroUtils; // Shiro 工具类
/** /**
* - * -
@ -17,14 +18,19 @@ import com.tamguo.utils.ShiroUtils;
@Controller @Controller
public class IndexController { public class IndexController {
@Autowired @Autowired // 自动注入会员服务实例
IMemberService iMemberService; IMemberService iMemberService;
@RequestMapping(value = {"index.html" , "/"}, method = RequestMethod.GET) /**
public ModelAndView index(ModelAndView model){ * index.html / GET
model.setViewName("index"); *
model.addObject("member", iMemberService.selectById(ShiroUtils.getMemberId())); * @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; return model;
} }
} }

@ -22,11 +22,25 @@ import com.tamguo.common.utils.Result;
import com.tamguo.common.utils.SystemConstant; import com.tamguo.common.utils.SystemConstant;
import com.tamguo.utils.ShiroUtils; import com.tamguo.utils.ShiroUtils;
/**
*
*
* @author tamguo
*
*/
@Controller @Controller
public class LoginController { public class LoginController {
/**
*
*
* @param response
* @param session
* @throws ServletException Servlet
* @throws IOException IO
*/
@RequestMapping("captcha.jpg") @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.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg"); response.setContentType("image/jpeg");
@ -34,20 +48,41 @@ public class LoginController {
session.setAttribute(SystemConstant.KAPTCHA_SESSION_KEY, a); session.setAttribute(SystemConstant.KAPTCHA_SESSION_KEY, a);
} }
/**
* GET
*
* @param redirectUrl URL
* @param model
* @return
*/
@RequestMapping(value = "/login.html", method = RequestMethod.GET) @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.setViewName("login");
model.addObject("isVerifyCode" , "0"); model.addObject("isVerifyCode", "0");
model.addObject("redirectUrl", redirectUrl); model.addObject("redirectUrl", redirectUrl);
return model; 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) @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); Result result = Result.successResult(null);
if(StringUtils.isEmpty(verifyCode)) {
if (StringUtils.isEmpty(verifyCode)) {
result = Result.result(202, null, "请输入验证码"); result = Result.result(202, null, "请输入验证码");
} else if(StringUtils.isNotEmpty(verifyCode)){ } else if (StringUtils.isNotEmpty(verifyCode)) {
String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString(); String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString();
if (!verifyCode.equalsIgnoreCase(kaptcha)) { if (!verifyCode.equalsIgnoreCase(kaptcha)) {
result = Result.result(205, null, "验证码错误"); result = Result.result(205, null, "验证码错误");
@ -58,9 +93,9 @@ public class LoginController {
subject.login(token); subject.login(token);
session.setAttribute("currMember", ShiroUtils.getMember()); session.setAttribute("currMember", ShiroUtils.getMember());
if(!StringUtils.isEmpty(redirectUrl)) { if (!StringUtils.isEmpty(redirectUrl)) {
response.sendRedirect(redirectUrl); response.sendRedirect(redirectUrl);
}else { } else {
response.sendRedirect("index.html"); response.sendRedirect("index.html");
} }
return null; return null;
@ -73,24 +108,36 @@ public class LoginController {
} }
} }
} }
model.setViewName("login"); model.setViewName("login");
model.addObject("code", result.getCode()); model.addObject("code", result.getCode());
model.addObject("msg" , result.getMessage()); model.addObject("msg", result.getMessage());
model.addObject("username", username); model.addObject("username", username);
return model; return model;
} }
/**
* GET
*
* @param username
* @param password
* @param captcha
* @param model
* @param session
* @return
*/
@RequestMapping(value = "/miniLogin.html", method = RequestMethod.GET) @RequestMapping(value = "/miniLogin.html", method = RequestMethod.GET)
@ResponseBody @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; Result result = null;
if(StringUtils.isEmpty(captcha)) {
if (StringUtils.isEmpty(captcha)) {
result = Result.result(204, null, "请输入验证码"); result = Result.result(204, null, "请输入验证码");
} else if(StringUtils.isNotEmpty(captcha)){ } else if (StringUtils.isNotEmpty(captcha)) {
String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString(); String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString();
if (!captcha.equalsIgnoreCase(kaptcha)) { if (!captcha.equalsIgnoreCase(kaptcha)) {
result = Result.result(205, null, "验证码错误"); result = Result.result(205, null, "验证码错误");
}else { } else {
Subject subject = ShiroUtils.getSubject(); Subject subject = ShiroUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, password); UsernamePasswordToken token = new UsernamePasswordToken(username, password);
try { try {
@ -109,11 +156,16 @@ public class LoginController {
return result; return result;
} }
/**
*
*
* @return
*/
@RequestMapping(value = "/isLogin.html", method = RequestMethod.GET) @RequestMapping(value = "/isLogin.html", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Result isLogin() { public Result isLogin() {
if(ShiroUtils.isLogin()) { if (ShiroUtils.isLogin()) {
return Result.result(1, null , "已经登录"); return Result.result(1, null, "已经登录");
} }
return Result.result(0, null, "未登录"); return Result.result(0, null, "未登录");
} }

@ -1,28 +1,27 @@
package com.tamguo.web; package com.tamguo.web;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest; // 导入 HttpServletRequest 类
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse; // 导入 HttpServletResponse 类
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession; // 导入 HttpSession 类
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller; // 表示这是一个控制器类
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping; // 用于处理请求映射
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod; // 用于指定请求方法
import com.tamguo.utils.ShiroUtils; import com.tamguo.utils.ShiroUtils; // 导入 ShiroUtils 类
@Controller @Controller // 声明这是一个控制器
public class LogoutController { public class LogoutController {
/** /**
* *
*/ */
@RequestMapping(value = "logout.html", method = RequestMethod.GET) @RequestMapping(value = "logout.html", method = RequestMethod.GET) // 映射到 "logout.html" 且使用 GET 方法的请求
public String logout(HttpServletRequest request, HttpServletResponse response, HttpSession session) { public String logout(HttpServletRequest request, HttpServletResponse response, HttpSession session) { // 接收请求、响应和会话对象
if (session.getAttribute("currMember") != null) { if (session.getAttribute("currMember")!= null) { // 如果会话中当前成员不为空
session.removeAttribute("currMember"); session.removeAttribute("currMember"); // 从会话中移除当前成员属性
ShiroUtils.logout(); ShiroUtils.logout(); // 执行 ShiroUtils 的注销操作
} }
return "redirect:/"; return "redirect:/"; // 重定向到根路径
} }
} }

@ -1,81 +1,95 @@
package com.tamguo.web; package com.tamguo.web;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession; // 导入 HttpSession 类
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired; // 表示自动注入
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller; // 声明这是一个控制器类
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping; // 处理请求映射
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod; // 指定请求方法
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody; // 用于返回响应体
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView; // 模型和视图类
import com.tamguo.common.utils.Result; import com.tamguo.common.utils.Result; // 通用结果类
import com.tamguo.common.utils.SystemConstant; import com.tamguo.common.utils.SystemConstant; // 系统常量类
import com.tamguo.modules.member.service.IMemberService; import com.tamguo.modules.member.service.IMemberService; // 会员服务接口
@Controller @Controller // 控制器注解
public class PasswordController { public class PasswordController {
@Autowired @Autowired // 自动注入会员服务
private IMemberService iMemberService; private IMemberService iMemberService;
/**
*
*/
@RequestMapping(value = "password/find.html", method = RequestMethod.GET) @RequestMapping(value = "password/find.html", method = RequestMethod.GET)
public ModelAndView confirmAccount(ModelAndView model){ public ModelAndView confirmAccount(ModelAndView model) { // 处理方法,接收模型和视图对象
model.setViewName("password/confirmAccount"); model.setViewName("password/confirmAccount"); // 设置视图名称
return model; return model; // 返回模型和视图
} }
/**
*
*/
@RequestMapping(value = "password/confirmAccount.html", method = RequestMethod.POST) @RequestMapping(value = "password/confirmAccount.html", method = RequestMethod.POST)
public ModelAndView submitConfirmAccount(String username , String veritycode , ModelAndView model , HttpSession session){ public ModelAndView submitConfirmAccount(String username, String veritycode, ModelAndView model, HttpSession session) { // 处理方法,接收参数、模型和视图对象、会话对象
Result result = iMemberService.confirmAccount(username, veritycode); Result result = iMemberService.confirmAccount(username, veritycode); // 调用会员服务的确认账号方法
String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString(); String kaptcha = session.getAttribute(SystemConstant.KAPTCHA_SESSION_KEY).toString(); // 获取验证码
if (!veritycode.equalsIgnoreCase(kaptcha)) { if (!veritycode.equalsIgnoreCase(kaptcha)) { // 比较验证码是否正确
result = Result.result(202, null, "验证码错误"); result = Result.result(202, null, "验证码错误"); // 设置错误结果
} }
if(result.getCode() == 200){ if (result.getCode() == 200) { // 如果结果码为 200
model.setViewName("password/securityCheck"); model.setViewName("password/securityCheck"); // 设置视图名称
model.addObject("result", result); model.addObject("result", result); // 添加结果到模型
model.addObject("isEmail", username.contains("@") ? "1" : "0"); model.addObject("isEmail", username.contains("@")? "1" : "0"); // 添加是否为邮箱的标识到模型
}else{ } else {
model.setViewName("password/confirmAccount"); model.setViewName("password/confirmAccount"); // 设置视图名称
model.addObject("account", username); model.addObject("account", username); // 添加账号到模型
model.addObject("username",username); model.addObject("username", username); // 添加用户名到模型
model.addObject("veritycode", veritycode); model.addObject("veritycode", veritycode); // 添加验证码到模型
model.addObject("code", result.getCode()); model.addObject("code", result.getCode()); // 添加结果码到模型
} }
return model; return model; // 返回模型和视图
} }
/**
*
*/
@RequestMapping(value = "password/securityCheck.html", method = RequestMethod.POST) @RequestMapping(value = "password/securityCheck.html", method = RequestMethod.POST)
public ModelAndView securityCheck(String username , String isEmail , String mobileVcode , ModelAndView model){ public ModelAndView securityCheck(String username, String isEmail, String mobileVcode, ModelAndView model) { // 处理方法,接收参数、模型和视图对象
Result result = iMemberService.securityCheck(username , isEmail , mobileVcode); Result result = iMemberService.securityCheck(username, isEmail, mobileVcode); // 调用会员服务的安全检查方法
if(result.getCode() == 200){ if (result.getCode() == 200) { // 如果结果码为 200
model.addObject("username", username); model.addObject("username", username); // 添加用户名到模型
model.addObject("resetPasswordKey" , result.getResult()); model.addObject("resetPasswordKey", result.getResult()); // 添加重置密码键到模型
model.setViewName("password/resetPassword"); model.setViewName("password/resetPassword"); // 设置视图名称
}else{ } else {
model.addObject("result", result); model.addObject("result", result); // 添加结果到模型
model.addObject("isEmail", isEmail); model.addObject("isEmail", isEmail); // 添加是否为邮箱的标识到模型
model.addObject("codeError", "1"); model.addObject("codeError", "1"); // 添加错误标识到模型
model.setViewName("password/securityCheck"); model.setViewName("password/securityCheck"); // 设置视图名称
} }
return model; return model; // 返回模型和视图
} }
/**
*
*/
@RequestMapping(value = "password/resetPassword.html", method = RequestMethod.POST) @RequestMapping(value = "password/resetPassword.html", method = RequestMethod.POST)
public ModelAndView resetPassword(String resetPasswordKey , String username , String password , String verifypwd , ModelAndView model){ public ModelAndView resetPassword(String resetPasswordKey, String username, String password, String verifypwd, ModelAndView model) { // 处理方法,接收参数、模型和视图对象
Result result = iMemberService.resetPassword(resetPasswordKey , username , password , verifypwd); Result result = iMemberService.resetPassword(resetPasswordKey, username, password, verifypwd); // 调用会员服务的重置密码方法
if(result.getCode() == 200){ if (result.getCode() == 200) { // 如果结果码为 200
model.setViewName("password/resetPwSuccess"); model.setViewName("password/resetPwSuccess"); // 设置视图名称
}else{ } else {
model.setViewName("password/resetPassword"); model.setViewName("password/resetPassword"); // 设置视图名称
} }
return model; return model; // 返回模型和视图
} }
/**
*
*/
@RequestMapping(value = "password/checkAccount.html", method = RequestMethod.GET) @RequestMapping(value = "password/checkAccount.html", method = RequestMethod.GET)
@ResponseBody @ResponseBody // 返回响应体
public Result checkAccount(String account){ public Result checkAccount(String account) { // 处理方法,接收账号参数
return iMemberService.checkAccount(account); return iMemberService.checkAccount(account); // 调用会员服务的检查账号方法并返回结果
} }
} }

@ -19,41 +19,74 @@ import com.tamguo.modules.member.model.MemberEntity;
import com.tamguo.modules.member.service.IMemberService; import com.tamguo.modules.member.service.IMemberService;
import com.tamguo.utils.ShiroUtils; import com.tamguo.utils.ShiroUtils;
/**
* RegisterController
*/
@Controller @Controller
public class RegisterController { public class RegisterController {
/**
* IMemberService
*/
@Autowired @Autowired
private IMemberService iMemberService; private IMemberService iMemberService;
/**
* /register.html GET
* @param model
* @param session HttpSession
* @return
*/
@RequestMapping(value = "/register.html", method = RequestMethod.GET) @RequestMapping(value = "/register.html", method = RequestMethod.GET)
public ModelAndView register(ModelAndView model , HttpSession session) { public ModelAndView register(ModelAndView model, HttpSession session) {
model.setViewName("register"); model.setViewName("register");
return model; return model;
} }
/**
* /checkUsername.html GET
* @param username
* @return
*/
@RequestMapping(value = "/checkUsername.html", method = RequestMethod.GET) @RequestMapping(value = "/checkUsername.html", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Result checkUsername(String username){ public Result checkUsername(String username) {
return iMemberService.checkUsername(username); return iMemberService.checkUsername(username);
} }
/**
* /checkMobile.html GET
* @param mobile
* @return
*/
@RequestMapping(value = "/checkMobile.html", method = RequestMethod.GET) @RequestMapping(value = "/checkMobile.html", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Result checkMobile(String mobile){ public Result checkMobile(String mobile) {
return iMemberService.checkMobile(mobile); return iMemberService.checkMobile(mobile);
} }
/**
* /subRegister POST
* @param member
* @param session HttpSession
* @return
*/
@RequestMapping(value = "/subRegister", method = RequestMethod.POST) @RequestMapping(value = "/subRegister", method = RequestMethod.POST)
@ResponseBody @ResponseBody
public Result subRegister(@RequestBody MemberEntity member , HttpSession session){ public Result subRegister(@RequestBody MemberEntity member, HttpSession session) {
Result result = iMemberService.register(member); Result result = iMemberService.register(member);
if(result.getCode() == 200) { if (result.getCode() == 200) {
// 获取 Shiro 主体
Subject subject = ShiroUtils.getSubject(); Subject subject = ShiroUtils.getSubject();
// 获取注册成功的会员实体对象
MemberEntity memberEntity = (MemberEntity) result.getResult(); MemberEntity memberEntity = (MemberEntity) result.getResult();
// 创建用户名密码令牌
UsernamePasswordToken token = new UsernamePasswordToken(memberEntity.getUsername(), member.getPassword()); UsernamePasswordToken token = new UsernamePasswordToken(memberEntity.getUsername(), member.getPassword());
try { try {
// 主体登录
subject.login(token); subject.login(token);
// 设置当前会员到会话中
session.setAttribute("currMember", ShiroUtils.getMember()); session.setAttribute("currMember", ShiroUtils.getMember());
} catch (UnknownAccountException e) { } catch (UnknownAccountException e) {
return Result.result(201, null, "用户名或密码有误,请重新输入或找回密码"); return Result.result(201, null, "用户名或密码有误,请重新输入或找回密码");
@ -65,5 +98,4 @@ public class RegisterController {
} }
return result; return result;
} }
} }

@ -10,21 +10,34 @@ import com.aliyuncs.exceptions.ClientException;
import com.tamguo.common.utils.Result; import com.tamguo.common.utils.Result;
import com.tamguo.modules.sys.service.ISmsService; import com.tamguo.modules.sys.service.ISmsService;
/**
* SmsController
*/
@Controller @Controller
public class SmsController { public class SmsController {
/**
* ISmsService
*/
@Autowired @Autowired
ISmsService iSmsService; private ISmsService iSmsService;
/**
* /sendFindPasswordSms GET
* @param mobile
* @return
*/
@RequestMapping(value = {"sendFindPasswordSms"}, method = RequestMethod.GET) @RequestMapping(value = {"sendFindPasswordSms"}, method = RequestMethod.GET)
@ResponseBody @ResponseBody
public Result sendFindPasswordSms(String mobile){ public Result sendFindPasswordSms(String mobile) {
try { try {
// 调用 ISmsService 发送找回密码短信,并返回结果
return iSmsService.sendFindPasswordSms(mobile); return iSmsService.sendFindPasswordSms(mobile);
} catch (ClientException e) { } catch (ClientException e) {
// 打印异常信息
e.printStackTrace(); e.printStackTrace();
} }
// 返回错误结果
return Result.result(500, null, ""); return Result.result(500, null, "");
} }
} }
Loading…
Cancel
Save