shenxianbao_branch
sxb 10 months ago
parent 46cd545533
commit 4022c303be

@ -36,133 +36,188 @@ import com.wsk.tool.Pornographic;*/
@Slf4j
public class UserController {
// 使用@Resource注解注入UserInformationService用于处理用户信息相关业务逻辑由Spring框架自动装配
@Resource
private UserInformationService userInformationService;
// 使用@Resource注解注入UserPasswordService用于处理用户密码相关业务逻辑由Spring框架自动装配
@Resource
private UserPasswordService userPasswordService;
// 使用@Resource注解注入UserCollectionService用于处理用户收藏相关业务逻辑由Spring框架自动装配
@Resource
private UserCollectionService userCollectionService;
// 使用@Resource注解注入UserReleaseService用于处理用户发布相关业务逻辑从变量名推测具体需看业务由Spring框架自动装配
@Resource
private UserReleaseService userReleaseService;
// 使用@Resource注解注入BoughtShopService用于处理用户购买店铺相关业务逻辑从变量名推测具体需看业务由Spring框架自动装配
@Resource
private BoughtShopService boughtShopService;
// 使用@Resource注解注入UserWantService用于处理用户求购相关业务逻辑由Spring框架自动装配
@Resource
private UserWantService userWantService;
// 使用@Resource注解注入ShopCarService用于处理购物车相关业务逻辑从变量名推测具体需看业务由Spring框架自动装配
@Resource
private ShopCarService shopCarService;
// 使用@Resource注解注入OrderFormService用于处理订单表单相关业务逻辑由Spring框架自动装配
@Resource
private OrderFormService orderFormService;
// 使用@Resource注解注入GoodsOfOrderFormService用于处理订单表单中商品相关业务逻辑从变量名推测具体需看业务由Spring框架自动装配
@Resource
private GoodsOfOrderFormService goodsOfOrderFormService;
// 使用@Resource注解注入UserStateService用于处理用户状态相关业务逻辑从变量名推测具体需看业务由Spring框架自动装配
@Resource
private UserStateService userStateService;
// 使用@Resource注解注入ShopInformationService用于处理店铺信息相关业务逻辑由Spring框架自动装配
@Resource
private ShopInformationService shopInformationService;
// 使用@Resource注解注入GoodsCarService用于处理商品车可能类似购物车具体看业务相关业务逻辑由Spring框架自动装配
@Resource
private GoodsCarService goodsCarService;
// 使用@Resource注解注入SpecificeService具体业务逻辑需看其具体实现从变量名较难准确判断可能是特定业务相关由Spring框架自动装配
@Resource
private SpecificeService specificeService;
// 使用@Resource注解注入ClassificationService可能用于分类相关业务逻辑从变量名推测由Spring框架自动装配
@Resource
private ClassificationService classificationService;
// 使用@Resource注解注入AllKindsService具体业务不太明确从变量名较难准确判断由Spring框架自动装配
@Resource
private AllKindsService allKindsService;
// 使用@Resource注解注入ShopContextService可能用于店铺上下文相关业务逻辑从变量名推测由Spring框架自动装配
@Resource
private ShopContextService shopContextService;
//进入登录界面
// 处理进入登录界面的请求使用GET方法访问/login.do路径时触发该方法
// 返回登录页面的视图名称同时生成并设置token到session和model中用于后续验证等操作
@RequestMapping(value = "/login.do", method = RequestMethod.GET)
public String login(HttpServletRequest request, Model model) {
// 通过单例模式获取TokenProccessor实例并生成一个token用于标识本次登录请求等相关操作具体看业务
String token = TokenProccessor.getInstance().makeToken();
// 在日志中记录进入登录界面以及生成的token信息方便后续查看日志排查问题
log.info("进入登录界面token为:" + token);
// 将生成的token设置到HttpServletRequest的session中方便后续在不同请求间共享这个token
request.getSession().setAttribute("token", token);
// 将token添加到Model中Model用于在视图渲染时传递数据可能在前端页面会使用到这个token
model.addAttribute("token", token);
// 返回登录页面的视图名称,视图解析器会根据这个名称找到对应的页面进行渲染显示
return "page/login_page";
}
//退出
// 处理用户退出的请求,访问/logout.do路径时触发该方法
// 移除用户相关信息在session中的属性然后重定向到相应页面
@RequestMapping(value = "/logout.do")
public String logout(HttpServletRequest request) {
try {
// 从session中移除用户信息相关的属性比如用户详细信息、用户ID等实现用户退出登录的效果
request.getSession().removeAttribute("userInformation");
request.getSession().removeAttribute("uid");
System.out.println("logout");
} catch (Exception e) {
// 如果出现异常,打印异常栈信息方便排查问题,然后重定向到首页(这里假设/home.do是首页具体看配置
e.printStackTrace();
return "redirect:/home.do";
}
// 正常情况下,重定向到根路径(通常是网站首页,具体看项目配置)
return "redirect:/";
}
//用户注册,拥有插入数据而已,没什么用的
// 用户注册方法使用POST方法访问/registered.do路径时触发该方法
// 接收用户注册相关信息,先插入用户基本信息,再插入密码信息等,根据操作结果返回相应提示信息
@RequestMapping(value = "/registered.do", method = RequestMethod.POST)
public String registered(Model model,
@RequestParam String name, @RequestParam String phone, @RequestParam String password) {
// 创建一个UserInformation对象用于封装要插入的用户基本信息
UserInformation userInformation = new UserInformation();
// 设置用户名,将前端传入的用户名赋值给用户信息对象
userInformation.setUsername(name);
// 设置用户手机号,将前端传入的手机号赋值给用户信息对象
userInformation.setPhone(phone);
// 设置用户信息的修改时间为当前时间,通常用于记录数据的更新时间等业务逻辑
userInformation.setModified(new Date());
// 设置用户信息的创建时间为当前时间,记录用户注册的时间
userInformation.setCreatetime(new Date());
// 调用userInformationService的insertSelective方法插入用户基本信息根据返回结果判断插入是否成功若返回1表示插入成功
if (userInformationService.insertSelective(userInformation) == 1) {
// 如果用户基本信息插入成功通过手机号查询该用户的ID用于后续关联密码等信息
int uid = userInformationService.selectIdByPhone(phone);
// 创建一个UserPassword对象用于封装用户密码相关信息
UserPassword userPassword = new UserPassword();
// 设置用户密码的修改时间为当前时间
userPassword.setModified(new Date());
// 对用户传入的密码进行MD5加密通过StringUtils工具类的实例方法提高密码安全性然后设置到密码对象中
password = StringUtils.getInstance().getMD5(password);
userPassword.setPassword(password);
// 设置用户密码对应的用户ID关联到刚插入的用户基本信息记录
userPassword.setUid(uid);
// 调用userPasswordService的insertSelective方法插入用户密码信息插入结果保存到result变量中
int result = userPasswordService.insertSelective(userPassword);
if (result != 1) {
// 如果插入用户密码信息失败,将"fail"结果添加到Model中并返回"success"视图(这里视图名可能不太准确,具体看业务逻辑对应的页面)
if (result!= 1) {
model.addAttribute("result", "fail");
return "success";
}
// 如果用户密码插入成功,将"success"结果添加到Model中并返回"success"视图
model.addAttribute("result", "success");
return "success";
}
// 如果用户基本信息插入失败,将"fail"结果添加到Model中并返回"success"视图
model.addAttribute("result", "fail");
return "success";
}
//用户注册
// @RequestMapping(value = "/registered", method = RequestMethod.GET)
// public String registered() {
// return "registered";
// }
// 以下是另一个用户注册的方法,被注释掉了,可能是之前的实现或者备用的逻辑,暂时未启用
// 该方法使用GET方法访问/registered路径时触发直接返回注册页面的视图名称这里假设视图名称就是"registered",具体看业务配置)
// @RequestMapping(value = "/registered", method = RequestMethod.GET)
// public String registered() {
// return "registered";
// }
//验证登录
// 处理验证登录的请求使用POST方法访问/login.do路径时触发该方法与GET方法访问/login.do路径的处理逻辑不同是另一个重载方法
// 根据传入的手机号、密码、token等信息验证用户登录是否合法根据验证结果进行相应的重定向操作
@RequestMapping(value = "/login.do", method = RequestMethod.POST)
public String login(HttpServletRequest request,
@RequestParam String phone, @RequestParam String password, @RequestParam String token) {
// 从session中获取之前在登录界面GET方法的/login.do逻辑中设置的生成的token用于和本次传入的token对比防止重复提交等情况
String loginToken = (String) request.getSession().getAttribute("token");
// 如果传入的手机号或者密码为空,直接重定向到登录页面,让用户重新输入
if (StringUtils.getInstance().isNullOrEmpty(phone) || StringUtils.getInstance().isNullOrEmpty(password)) {
return "redirect:/login.do";
}
//防止重复提交
if (StringUtils.getInstance().isNullOrEmpty(token) || !token.equals(loginToken)) {
// 防止重复提交如果传入的token为空或者与session中的token不一致重定向到登录页面
if (StringUtils.getInstance().isNullOrEmpty(token) ||!token.equals(loginToken)) {
return "redirect:/login.do";
}
// 调用getId方法原代码中未显示该方法具体实现推测是验证手机号和密码是否匹配等逻辑并获取用户相关信息根据返回结果判断验证情况
boolean b = getId(phone, password, request);
//失败,不存在该手机号码
// 如果验证失败,不存在该手机号码对应的用户,重定向到登录页面并带上错误提示信息
if (!b) {
return "redirect:/login.do?msg=不存在该手机号码";
}
// 如果验证成功,重定向到根路径(通常是网站首页,具体看项目配置)
return "redirect:/";
}
//查看用户基本信息
// 处理查看用户基本信息的请求,访问/personal_info.do路径时触发该方法
// 从session中获取用户信息若存在则生成新的token并设置到session和model中然后返回用户基本信息页面的视图名称
@RequestMapping(value = "/personal_info.do")
public String personalInfo(HttpServletRequest request, Model model) {
// 从session中获取用户信息对象如果获取到的对象为空说明用户未登录重定向到登录页面
UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
return "redirect:/login.do";
}
// 生成一个新的token用于本次查看用户基本信息操作的相关验证等具体看业务
String personalInfoToken = TokenProccessor.getInstance().makeToken();
// 将新生成的token设置到HttpServletRequest的session中
request.getSession().setAttribute("personalInfoToken", personalInfoToken);
// 将token添加到Model中方便在前端页面使用可能用于页面数据验证等操作
model.addAttribute("token", personalInfoToken);
// 将用户信息对象添加到Model中方便在前端页面展示用户的基本信息
model.addAttribute("userInformation", userInformation);
// 返回用户基本信息页面的视图名称,视图解析器会根据这个名称找到对应的页面进行渲染显示
return "page/personal/personal_info";
}
//完善用户基本信息,认证
// 处理完善用户基本信息认证的请求使用POST方法访问/certification.do路径时触发该方法
// 接收用户提交的各种基本信息进行格式校验等操作后更新用户信息根据更新结果返回相应的提示信息封装在Map中
@RequestMapping(value = "/certification.do", method = RequestMethod.POST)
@ResponseBody
public Map certification(HttpServletRequest request,
@ -171,63 +226,72 @@ public class UserController {
@RequestParam(required = false) String clazz, @RequestParam String token,
@RequestParam(required = false) String sno, @RequestParam(required = false) String dormitory,
@RequestParam(required = false) String gender) {
// 从session中获取用户信息对象如果为空说明用户未登录直接返回默认的提示信息result为0的Map
UserInformation userInformation = (UserInformation) request.getSession().getAttribute("userInformation");
Map<String, Integer> map = new HashMap<>();
map.put("result", 0);
//该用户还没有登录
if (StringUtils.getInstance().isNullOrEmpty(userInformation)) {
return map;
}
// 从session中获取之前在查看用户基本信息操作中设置的personalInfoToken用于防止重复提交等验证
String certificationToken = (String) request.getSession().getAttribute("personalInfoToken");
//防止重复提交
// boolean b = token.equals(certificationToken);
// 防止重复提交如果获取到的certificationToken为空直接返回默认的提示信息result为0的Map
if (StringUtils.getInstance().isNullOrEmpty(certificationToken)) {
return map;
} else {
// 如果验证通过移除session中的certificationToken避免重复使用
request.getSession().removeAttribute("certificationToken");
}
if (userName != null && userName.length() < 25) {
// 如果传入的用户名不为空且长度小于25对用户名进行空格替换等格式化操作通过StringUtils工具类然后设置到用户信息对象中
if (userName!= null && userName.length() < 25) {
userName = StringUtils.getInstance().replaceBlank(userName);
userInformation.setUsername(userName);
} else if (userName != null && userName.length() >= 25) {
} else if (userName!= null && userName.length() >= 25) {
// 如果用户名长度大于等于25不符合要求直接返回默认的提示信息result为0的Map
return map;
}
if (realName != null && realName.length() < 25) {
// 与处理用户名类似,对真实姓名进行格式校验和设置操作,如果不符合要求则返回默认提示信息
if (realName!= null && realName.length() < 25) {
realName = StringUtils.getInstance().replaceBlank(realName);
userInformation.setRealname(realName);
} else if (realName != null && realName.length() >= 25) {
} else if (realName!= null && realName.length() >= 25) {
return map;
}
if (clazz != null && clazz.length() < 25) {
// 对班级信息进行格式校验和设置操作,如果不符合要求则返回默认提示信息
if (clazz!= null && clazz.length() < 25) {
clazz = StringUtils.getInstance().replaceBlank(clazz);
userInformation.setClazz(clazz);
} else if (clazz != null && clazz.length() >= 25) {
} else if (clazz!= null && clazz.length() >= 25) {
return map;
}
if (sno != null && sno.length() < 25) {
// 对学号信息进行格式校验和设置操作,如果不符合要求则返回默认提示信息
if (sno!= null && sno.length() < 25) {
sno = StringUtils.getInstance().replaceBlank(sno);
userInformation.setSno(sno);
} else if (sno != null && sno.length() >= 25) {
} else if (sno!= null && sno.length() >= 25) {
return map;
}
if (dormitory != null && dormitory.length() < 25) {
// 对宿舍信息进行格式校验和设置操作,如果不符合要求则返回默认提示信息
if (dormitory!= null && dormitory.length() < 25) {
dormitory = StringUtils.getInstance().replaceBlank(dormitory);
userInformation.setDormitory(dormitory);
} else if (dormitory != null && dormitory.length() >= 25) {
} else if (dormitory!= null && dormitory.length() >= 25) {
return map;
}
if (gender != null && gender.length() <= 2) {
// 对性别信息进行格式校验和设置操作,如果不符合要求则返回默认提示信息
if (gender!= null && gender.length() <= 2) {
gender = StringUtils.getInstance().replaceBlank(gender);
userInformation.setGender(gender);
} else if (gender != null && gender.length() > 2) {
} else if (gender!= null && gender.length() > 2) {
return map;
}
// 调用userInformationService的updateByPrimaryKeySelective方法更新用户信息根据返回结果判断更新是否成功
int result = userInformationService.updateByPrimaryKeySelective(userInformation);
if (result != 1) {
//更新失败,认证失败
if (result!= 1) {
// 如果更新失败,直接返回默认的提示信息result为0的Map代表认证失败
return map;
}
//认证成功
// 如果更新成功,说明认证成功将更新后的用户信息重新设置到session中然后更新提示信息的result为1表示成功
request.getSession().setAttribute("userInformation", userInformation);
map.put("result", 1);
return map;

@ -14,11 +14,11 @@
(function( global, factory ) {
// 如果在CommonJS环境中如Node.js并且module.exports存在
// 如果在CommonJS环境中如Node.js并且module.exports存在
if ( typeof module === "object" && typeof module.exports === "object" ) {
// 如果全局对象有document属性则直接导出jQuery
// 否则导出一个函数该函数在被调用时会检查是否存在document
// 如果全局对象有document属性则直接导出jQuery
// 否则导出一个函数该函数在被调用时会检查是否存在document
module.exports = global.document ?
factory( global, true ) :
function( w ) {

Loading…
Cancel
Save