一、项目简述
功能包括:
用户管理,游戏商品管理,在线购买,上传,售卖记录,商品审核等等。
二、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Spring + SpringBoot + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
}
return new ResultVo(false, StatusCode.ERROR, "修改失败");
}
/**更换手机号时发送短信验证码
* 1.判断是否为更换手机号类型验证码
* 2.判断手机号格式是否正确
* 3.查询账号是否存在
* 4.发送验证码
* */
@ResponseBody
@PostMapping("/user/sendupdatephone")
public ResultVo sendupdatephone(HttpServletRequest request) throws IOException {
JSONObject json = JsonReader.receivePost(request);
final String mobilephone = json.getString("mobilephone");
Integer type = json.getInt("type");
Login login = new Login();
if(type!=2){
return new ResultVo(false,StatusCode.ACCESSERROR,"违规操作");
}
if (!JustPhone.justPhone(mobilephone)) {//判断输入的手机号格式是否正确
return new ResultVo(false,StatusCode.ERROR,"请输入正确格式的手机号");
}
//查询手机号是否存在
login.setMobilephone(mobilephone);
Login userIsExist = loginService.userLogin(login);
if (!StringUtils.isEmpty(userIsExist)){//若手机号已注册过
resUrl.put("src", "/pic/"+filenames);
res.put("msg", "");
res.put("code", 0);
res.put("data", resUrl);
String uimgUrl = "/pic/" + filenames;
String userid=(String) session.getAttribute("userid");
UserInfo userInfo = new UserInfo().setUserid(userid).setUimage(uimgUrl);
userInfoService.UpdateUserInfo(userInfo);
return res;
}
/**
* 展示个人信息
*/
@RequiresPermissions("user:userinfo")
@GetMapping("/user/lookinfo")
public class UserHomeController {
@Autowired
private UserInfoService userInfoService;
@Autowired
private CommodityService commodityService;
/**
* 个人简介
* 前端传入用户id(userid)
*/
@ResponseBody
@GetMapping("/user/userinfo/{userid}")
public ResultVo userinfo(@PathVariable("userid") String userid) {
UserInfo userInfo = userInfoService.LookUserinfo(userid);
if (!StringUtils.isEmpty(userInfo)){
return new ResultVo(true, StatusCode.OK, "查询成功",userInfo);
}
}
String rel = phonecodemap1.get(mobilephone);
if (StringUtils.isEmpty(rel)) {//验证码到期 或者 没发送短信验证码
return new ResultVo(false,StatusCode.ERROR,"请重新获取验证码");
}
//if (rel.equalsIgnoreCase(vercode)) {
if (vercode.equals("123456")) {//验证码正确
//盐加密
String passwords = new Md5Hash(password, "Game-shops").toString();
String userid = KeyUtil.genUniqueKey();
login.setId(KeyUtil.genUniqueKey()).setUserid(userid).setMobilephone(mobilephone).setPassword(passwords);
Integer integer = loginService.loginAdd(login);
//新注册用户存入默认头像、存入默认签名
userInfo.setUserid(userid).setPassword(passwords).setUimage("/pic/d1d66c3ea71044a9b938b00859ca94df.jpg").
setSign("如此清秋何吝酒,这般明月不须钱").setStatus("offline");
Integer integer1 = userInfoService.userReg(userInfo);
if (integer==1 && integer1==1){
/**注册成功后存入session*/
session.setAttribute("userid",userid);
session.setAttribute("username",username);
/**存入用户角色信息*/
userRoleService.InsertUserRole(new UserRole().setUserid(userid).setRoleid(1).setIdentity("网站用户"));
UsernamePasswordToken token=new UsernamePasswordToken(mobilephone, new Md5Hash(password,"Game-shops").toString());
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
ValidateCode vCode = new ValidateCode(820, 200, 5, 80);
vCode.write(response.getOutputStream());
}
/**注册时发送短信验证码
* 1.判断是否为注册类型验证码
* 2.判断手机号格式是否正确
* 3.判断手机号是否已经注册过
* 4.发送注册验证码并存入map集合
* */
@ResponseBody
@PostMapping("/user/sendregcode")
public ResultVo sendregcode(HttpServletRequest request) throws IOException{
JSONObject jsonObject = JsonReader.receivePost(request);
}
return new ResultVo(false, StatusCode.ERROR, "修改失败");
}
/**更换手机号时发送短信验证码
* 1.判断是否为更换手机号类型验证码
* 2.判断手机号格式是否正确
* 3.查询账号是否存在
* 4.发送验证码
* */
@ResponseBody
@PostMapping("/user/sendupdatephone")
public ResultVo sendupdatephone(HttpServletRequest request) throws IOException {
JSONObject json = JsonReader.receivePost(request);
final String mobilephone = json.getString("mobilephone");
Integer type = json.getInt("type");
request.getSession().removeAttribute("username");
return "redirect:/";
}
}
个人中心 控制器:
/**
* <p>
* 个人中心 控制器
* </p>
*
*/
@Controller
public class UserController {
return new ResultVo(true,StatusCode.OK,"登录成功");
}catch (UnknownAccountException e){
return new ResultVo(true,StatusCode.LOGINERROR,"用户名不存在");
}catch (IncorrectCredentialsException e){
return new ResultVo(true,StatusCode.LOGINERROR,"密码错误");
}
}
/**重置密码时发送短信验证码
* 1.判断是否为重置密码类型验证码
* 2.判断手机号格式是否正确
* 3.查询账号是否存在
* 4.发送验证码
* */
@ResponseBody
@PostMapping("/user/sendresetpwd")
public ResultVo sendresetpwd(HttpServletRequest request) throws IOException {
JSONObject json = JsonReader.receivePost(request);
final String mobilephone = json.getString("mobilephone");
Integer type = json.getInt("type");
Login login = new Login();
if(type!=1){
executorService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
phonecodemap2.remove(mobilephone);
((ScheduledThreadPoolExecutor) executorService).remove(this::run);
}
},5 * 60 * 1000,5 * 60 * 1000, TimeUnit.HOURS);
return new ResultVo(true,StatusCode.SMS,"验证码发送成功");
}else if(result == 2){
return new ResultVo(false,StatusCode.ERROR,"请输入正确格式的手机号");
}
return new ResultVo(false,StatusCode.REMOTEERROR,"验证码发送失败");
}
/**重置密码
* 1.判断手机号格式是否正确
* 2.查询手机号是否存在
* 3.判断验证码是否有效或正确
*/
@ResponseBody
@GetMapping("/user/userinfo/{userid}")
public ResultVo userinfo(@PathVariable("userid") String userid) {
UserInfo userInfo = userInfoService.LookUserinfo(userid);
if (!StringUtils.isEmpty(userInfo)){
return new ResultVo(true, StatusCode.OK, "查询成功",userInfo);
}
return new ResultVo(false, StatusCode.ERROR, "查询失败");
}
/**
* 分页展示个人已审核的商品信息(状态码:1)
*前端传入用户id(userid)、当前页码(nowPaging)、
*/
@ResponseBody
@GetMapping("/user/usercommodity/{userid}")
public LayuiPageVo userHomeCommodity(@PathVariable("userid") String userid,int limit, int page) {
List<Commodity> commodityList = commodityService.queryAllCommodity((page - 1) * limit, limit, userid,1);
Integer dataNumber = commodityService.queryCommodityCount(userid,1);
return new LayuiPageVo("", 0,dataNumber,commodityList);
}
}
登录注册 控制器:
/**
* <p>
* 登录注册 控制器
* </p>
response.setContentType("image/jpeg");
//禁止图像缓存。
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
ValidateCode vCode = new ValidateCode(820, 200, 5, 80);
vCode.write(response.getOutputStream());
}
/**注册时发送短信验证码
* 1.判断是否为注册类型验证码
* 2.判断手机号格式是否正确
* 3.判断手机号是否已经注册过
* 4.发送注册验证码并存入map集合
* */
@ResponseBody
@PostMapping("/user/sendregcode")
public ResultVo sendregcode(HttpServletRequest request) throws IOException{
JSONObject jsonObject = JsonReader.receivePost(request);
final String mobilephone = jsonObject.getString("mobilephone");
Integer type = jsonObject.getInt("type");
Login login = new Login();
if(type!=0){
return new ResultVo(false,StatusCode.ACCESSERROR,"违规操作");
}