diff --git a/src/main/java/me/mofun/controller/GetBackPwdController.java b/src/main/java/me/mofun/controller/GetBackPwdController.java
new file mode 100644
index 0000000..2153186
--- /dev/null
+++ b/src/main/java/me/mofun/controller/GetBackPwdController.java
@@ -0,0 +1,342 @@
+package me.mofun.controller;
+
+
+import me.mofun.entity.User;
+import me.mofun.service.IUserService;
+import me.mofun.util.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.Date;
+import java.util.Random;
+
+@Controller
+public class GetBackPwdController {
+
+ @Autowired
+ private IUserService userService;
+
+ /**
+ * 跳转到找回密码首页
+ */
+ @GetMapping("/getbackpwd/index")
+ public String index() {
+ return "index";
+ }
+
+ /**
+ * 验证找回密码信息
+ */
+ @PostMapping("/getbackpwd/getBackPwd")
+ public void getBackPwd(HttpServletRequest request, HttpServletResponse response,
+ @RequestParam String rnd, @RequestParam String mail) throws IOException {
+ response.setContentType("text/plain;charset=UTF-8");
+ PrintWriter out = response.getWriter();
+
+ Cookie[] cookies = request.getCookies();
+ if (request.isRequestedSessionIdFromCookie() && cookies != null) {
+ for (Cookie cookie : cookies) {
+ if ("rndCode".equals(cookie.getName())) {
+ String rndCode = cookie.getValue();
+ if (rnd.trim().equalsIgnoreCase(rndCode)) {
+ User user = userService.userByName(mail);
+ if (user == null) {
+ out.print("false");
+ } else {
+ out.print("1");
+ }
+ } else {
+ out.print("3");
+ }
+ break;
+ }
+ }
+ }
+ out.flush();
+ out.close();
+ }
+
+ /**
+ * 生成随机验证码图片
+ */
+ @GetMapping("/getbackpwd/getRandomCode")
+ public void getRandomCode(HttpServletRequest request, HttpServletResponse response) {
+ response.setContentType("image/jpeg");//设置相应类型,告诉浏览器输出的内容为图片
+ response.setHeader("Pragma", "No-cache");//设置响应头信息,告诉浏览器不要缓存此内容
+ response.setHeader("Cache-Control", "no-cache");
+ response.setDateHeader("Expire", 0);
+ RandomValidateCode randomValidateCode = new RandomValidateCode();
+ try {
+ randomValidateCode.getRandcode(request, response);//输出图片方法
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 跳转到邮箱验证页面
+ */
+ @GetMapping("/getbackpwd/findemailcheck")
+ public String findemailcheck() {
+ return "findemailcheck";
+ }
+
+ /**
+ * 跳转到手机验证页面并发送验证码
+ */
+ @GetMapping("/getbackpwd/findmobilecheck")
+ public String findmobilecheck(@RequestParam String mail) {
+ String key = MD5Util.encode(mail) + MD5Util.encode(DateUtil.dateTimeToStr(new Date())) + Base64.getEncode(mail);
+ try {
+ SendFindPwdCode(mail);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return "findmobilecheck";
+ }
+
+ /**
+ * 发送找回密码邮件
+ */
+ @PostMapping("/getbackpwd/sendFindPwdMail")
+ public void sendFindPwdMail(HttpServletRequest request, HttpServletResponse response,
+ @RequestParam String rnd, @RequestParam String mail) throws IOException {
+ response.setContentType("text/plain;charset=UTF-8");
+ PrintWriter out = response.getWriter();
+
+ String key = MD5Util.encode(mail) + MD5Util.encode(DateUtil.dateTimeToStr(new Date())) + Base64.getEncode(mail);
+ String html = "
" +
+ "" +
+ "| " +
+ "" +
+ "" +
+ "" +
+ " | " +
+ "
" +
+ "
" +
+ "" +
+ "" +
+ "| " + ApplicationListenerImpl.sysConfigureJson.getDomain() + " " + ApplicationListenerImpl.sysConfigureJson.getIcp() + " | " +
+ "
" +
+ "
";
+
+ Cookie[] cookies = request.getCookies();
+ if (request.isRequestedSessionIdFromCookie() && cookies != null) {
+ for (Cookie cookie : cookies) {
+ if ("rndCode".equals(cookie.getName())) {
+ String rndCode = cookie.getValue();
+ if (rnd.trim().equalsIgnoreCase(rndCode)) {
+ if (MemCachedClientHelp.getIMemcachedCache().get(MD5Util.encode(mail)) == null) {
+ boolean flag = EmailUtil.sendEmailOverSSL(
+ ApplicationListenerImpl.sysConfigureJson.getMailName(),
+ ApplicationListenerImpl.sysConfigureJson.getMailPwd(),
+ mail,
+ ApplicationListenerImpl.sysConfigureJson.getSiteName() + "取回密码",
+ html);
+ if (flag) {
+ MemCachedClientHelp.getIMemcachedCache().put(MD5Util.encode(mail), mail, new Date(10 * 60 * 1000));
+ out.print("0");
+ } else {
+ out.print("false");
+ }
+ } else {
+ out.print("3");
+ }
+ } else {
+ out.print("2");
+ }
+ break;
+ }
+ }
+ }
+ out.flush();
+ out.close();
+ }
+
+ /**
+ * 跳转到密码重置页面
+ */
+ @GetMapping("/getbackpwd/findreset")
+ public String findreset(@RequestParam String key, HttpServletRequest request) throws UnsupportedEncodingException {
+ if (StringUtil.isNotBlank(key)) {
+ key = key.substring(64);
+ String mail = Base64.getDecode(key);
+ if (StringUtil.isNotBlank(mail)) {
+ User user = userService.userByName(mail);
+ if (user != null) {
+ request.setAttribute("user", user);
+ request.setAttribute("mail", mail);
+ return "findreset";
+ }
+ }
+ }
+ return "index_index";
+ }
+
+ /**
+ * 验证手机短信验证码
+ */
+ @PostMapping("/getbackpwd/findMobileReset")
+ public void findMobileReset(HttpServletRequest request, HttpServletResponse response,
+ @RequestParam String rnd, @RequestParam String mail) throws IOException {
+ response.setContentType("text/plain;charset=UTF-8");
+ PrintWriter out = response.getWriter();
+
+ String phone = null;
+ if (mail.matches("^1[0-9]{10}$")) {
+ phone = mail;
+ }
+ try {
+ Object validateCodeObj = MemCachedClientHelp.getIMemcachedCache().get(Base64.getEncode(phone));
+ if (validateCodeObj != null && validateCodeObj.toString().equals(rnd)) {
+ out.print("0");
+ } else {
+ out.print("-1");
+ }
+ } catch (Exception ex) {
+ out.print("-1");
+ ex.printStackTrace();
+ }
+ out.flush();
+ out.close();
+ }
+
+ /**
+ * 更新密码
+ */
+ @PostMapping("/getbackpwd/updatePwd")
+ public void updatePwd(HttpServletResponse response,
+ @RequestParam String mail, @RequestParam String newPwd) throws IOException {
+ response.setContentType("text/plain;charset=UTF-8");
+ PrintWriter out = response.getWriter();
+
+ User user = userService.userByName(mail);
+ if (user != null) {
+ user.setUserPwd(newPwd);
+ userService.add(user);
+ out.print("0");
+ } else {
+ out.print("false");
+ }
+ out.flush();
+ out.close();
+ }
+
+ /**
+ * 跳转到找回密码成功页面
+ */
+ @GetMapping("/getbackpwd/findok")
+ public String findok() {
+ return "findok";
+ }
+
+ /**
+ * 发送手机短信验证码
+ */
+ @PostMapping("/getbackpwd/regSendMes")
+ public void regSendMes(HttpServletResponse response, @RequestParam String mail) throws IOException {
+ response.setContentType("text/plain;charset=UTF-8");
+ PrintWriter out = response.getWriter();
+
+ Random random = new Random();
+ String ran = "";
+ for (int i = 0; i < 6; i++) {
+ ran += random.nextInt(9);
+ }
+ if (mail.matches("^1[0-9]{10}$")) {
+ String phone = mail;
+ if (MemCachedClientHelp.getIMemcachedCache().get(Base64.getEncode(phone)) == null) {
+ try {
+ boolean result = SendSMS.sendSMS(phone, ran);
+ if (!result) {
+ out.print("false");
+ out.flush();
+ out.close();
+ return;
+ }
+ MemCachedClientHelp.getIMemcachedCache().put(Base64.getEncode(phone), ran, new Date(2 * 60 * 1000));
+ out.print("0");
+ } catch (Exception e) {
+ e.printStackTrace();
+ out.print("error");
+ }
+ } else {
+ out.print("2");
+ }
+ } else {
+ out.print("error");
+ }
+ out.flush();
+ out.close();
+ }
+
+ /**
+ * 发送找回密码时的手机短信验证码
+ */
+ private boolean SendFindPwdCode(String mail) throws Exception {
+ Random random = new Random();
+ String ran = "";
+ for (int i = 0; i < 6; i++) {
+ ran += random.nextInt(9);
+ }
+ if (mail.matches("^1[0-9]{10}$")) {
+ String phone = mail;
+ if (MemCachedClientHelp.getIMemcachedCache().get(Base64.getEncode(phone)) == null) {
+ boolean result = SendSMS.sendSMS(phone, ran);
+ if (!result) {
+ return false;
+ }
+ MemCachedClientHelp.getIMemcachedCache().put(Base64.getEncode(phone), ran, new Date(2 * 60 * 1000));
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/mofun/controller/IndexController.java b/src/main/java/me/mofun/controller/IndexController.java
index d69bd47..d7926ef 100644
--- a/src/main/java/me/mofun/controller/IndexController.java
+++ b/src/main/java/me/mofun/controller/IndexController.java
@@ -1,12 +1,15 @@
package me.mofun.controller;
import me.mofun.entity.*;
+import me.mofun.entity.dto.ProductSpellbuyproductDTO;
import me.mofun.entity.pojo.BuyHistoryJSON;
import me.mofun.entity.pojo.ProductJSON;
import me.mofun.entity.pojo.UserJSON;
import me.mofun.entity.vo.Pagination;
import me.mofun.service.*;
-import me.mofun.util.*;
+import me.mofun.util.ApplicationListenerImpl;
+import me.mofun.util.MemCachedClientHelp;
+import me.mofun.util.UserNameUtil;
import me.mofun.utils.ViewUtils;
import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
@@ -22,25 +25,25 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 首页控制器
+ * 从Struts2 Action改造为Spring MVC Controller
*/
@Controller
@RequestMapping("/")
public class IndexController {
- // 常量定义:分页大小、缓存时间(毫秒)等
+ // 常量定义
private static final int PAGE_SIZE_SMALL = 2;
private static final int PAGE_SIZE_MEDIUM = 5;
private static final int PAGE_SIZE_LARGE = 8;
private static final int PAGE_SIZE_XLARGE = 10;
private static final int PAGE_SIZE_XXLARGE = 100;
- private static final long CACHE_EXPIRE_MS = 5000; // 缓存过期时间:5秒
+ private static final long CACHE_EXPIRE_MS = 5000;
// 用户等级经验值常量
private static final int LEVEL_1_EXP = 10000;
@@ -52,7 +55,7 @@ public class IndexController {
private static final int LEVEL_7_EXP = 5000000;
private static final int LEVEL_8_EXP = 10000000;
- // 服务依赖(构造器注入)
+ // 服务依赖
private final ISpellbuyrecordService spellbuyrecordService;
private final ILatestlotteryService latestlotteryService;
private final ISpellbuyproductService spellbuyproductService;
@@ -60,7 +63,7 @@ public class IndexController {
private final IRecommendService recommendService;
private final IUserService userService;
- // 静态缓存(需注意线程安全,使用volatile保证可见性)
+ // 静态缓存
private static volatile List nowBuyProductList;
private static volatile List newRecordList;
private static volatile Long allBuyCount;
@@ -70,9 +73,8 @@ public class IndexController {
private static volatile Long beginDateByNowBuyProduct;
private static volatile Long nowDateByNewRecord = System.currentTimeMillis();
private static volatile Long beginDateByNewRecord;
- private static volatile List newsList; // 新闻缓存
+ private static volatile List newsList;
- // 构造器注入
@Autowired
public IndexController(ISpellbuyrecordService spellbuyrecordService,
ILatestlotteryService latestlotteryService,
@@ -92,69 +94,44 @@ public class IndexController {
private ViewUtils viewUtils;
private final String module = "index";
- @GetMapping("/show")
- public String show() {
- return null;
- }
-
/**
- * 首页入口(改造后)
+ * 首页
*/
- @GetMapping("/index")
- public ModelAndView index(Model model) {
-
-
- // 1. 首页广告位下方推荐(取2条最新商品)
- Pagination phoneDigitalPage = spellbuyrecordService.indexNewProductList(0, 2);
- List newProductList = convertToProductJSONList((List