|
|
|
|
|
package me.mofun.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.http.HTMLFilter;
|
|
|
|
|
|
import com.alibaba.druid.support.json.JSONUtils;
|
|
|
|
|
|
import me.mofun.entity.User;
|
|
|
|
|
|
import me.mofun.service.IUserService;
|
|
|
|
|
|
import me.mofun.util.*;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
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.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
|
|
|
|
|
|
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.math.BigDecimal;
|
|
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
|
|
@Controller
|
|
|
|
|
|
@RequestMapping("/register")
|
|
|
|
|
|
public class RegisterController {
|
|
|
|
|
|
private static final long serialVersionUID = 5054777863371691520L;
|
|
|
|
|
|
private Logger logger = Logger.getLogger(this.getClass());
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private IUserService userService;
|
|
|
|
|
|
|
|
|
|
|
|
public static IPSeeker seeker = new IPSeeker();
|
|
|
|
|
|
static HTMLFilter htmlFilter = new HTMLFilter();
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/index")
|
|
|
|
|
|
public ModelAndView index(@RequestParam(required = false) String forward, HttpServletRequest request) {
|
|
|
|
|
|
ModelAndView mav = new ModelAndView();
|
|
|
|
|
|
if (StringUtil.isNotBlank(forward)) {
|
|
|
|
|
|
forward = htmlFilter.filter(forward);
|
|
|
|
|
|
mav.addObject("forward", forward);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Cookie[] cookies = request.getCookies();
|
|
|
|
|
|
if (request.isRequestedSessionIdFromCookie() && cookies != null) {
|
|
|
|
|
|
for (Cookie cookie : cookies) {
|
|
|
|
|
|
if (cookie.getName().equals("userId") && StringUtils.isNotBlank(cookie.getValue())) {
|
|
|
|
|
|
mav.setViewName("index_index");
|
|
|
|
|
|
return mav;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
mav.setViewName("index");
|
|
|
|
|
|
return mav;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/register")
|
|
|
|
|
|
public void register(@RequestParam String str,
|
|
|
|
|
|
@RequestParam String userPwd,
|
|
|
|
|
|
HttpServletRequest request,
|
|
|
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
|
|
|
response.setContentType("text/plain;charset=UTF-8");
|
|
|
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
|
|
|
|
|
|
|
|
str = htmlFilter.filter(str);
|
|
|
|
|
|
userPwd = htmlFilter.filter(userPwd);
|
|
|
|
|
|
User user = new User();
|
|
|
|
|
|
String ip = request.getHeader("X-Real-IP");
|
|
|
|
|
|
if (ip == null) {
|
|
|
|
|
|
ip = "127.0.0.1";
|
|
|
|
|
|
}
|
|
|
|
|
|
String date = DateUtil.DateTimeToStr(new Date());
|
|
|
|
|
|
|
|
|
|
|
|
if (str.indexOf("@") != -1) {
|
|
|
|
|
|
user.setMail(str);
|
|
|
|
|
|
user.setMailCheck("3");
|
|
|
|
|
|
user.setMobileCheck("3");
|
|
|
|
|
|
if (StringUtils.isNotBlank(userPwd)) {
|
|
|
|
|
|
user.setUserPwd(userPwd);
|
|
|
|
|
|
}
|
|
|
|
|
|
user.setIpAddress(ip);
|
|
|
|
|
|
user.setIpLocation(seeker.getAddress(ip));
|
|
|
|
|
|
user.setOldDate(date);
|
|
|
|
|
|
user.setNewDate(date);
|
|
|
|
|
|
user.setBalance(BigDecimal.valueOf(ApplicationListenerImpl.sysConfigureJson.getRegBalance()));
|
|
|
|
|
|
user.setCommissionBalance(0.00);
|
|
|
|
|
|
user.setCommissionCount(0.00);
|
|
|
|
|
|
user.setCommissionMention(0.00);
|
|
|
|
|
|
user.setCommissionPoints(0);
|
|
|
|
|
|
user.setFaceImg("/Images/defaultUserFace.png");
|
|
|
|
|
|
user.setUserType("0");
|
|
|
|
|
|
user.setExperience(0);
|
|
|
|
|
|
|
|
|
|
|
|
Cookie[] cookies = request.getCookies();
|
|
|
|
|
|
if (request.isRequestedSessionIdFromCookie() && cookies != null) {
|
|
|
|
|
|
for (Cookie cookie : cookies) {
|
|
|
|
|
|
if (cookie.getName().equals("inviteId") && StringUtils.isNotBlank(cookie.getValue())) {
|
|
|
|
|
|
user.setInvite(Integer.parseInt(cookie.getValue()));
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
userService.add(user);
|
|
|
|
|
|
out.print("true");
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
out.print("false");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (StringUtils.isNotBlank(userPwd)) {
|
|
|
|
|
|
MemCachedClientHelp.getIMemcachedCache().put(str, userPwd, new Date(10 * 60 * 1000));
|
|
|
|
|
|
out.print("true");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
out.print("false");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/mobilecheck")
|
|
|
|
|
|
public ModelAndView mobilecheck(@RequestParam String str, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
|
|
ModelAndView mav = new ModelAndView();
|
|
|
|
|
|
if (MemCachedClientHelp.getIMemcachedCache().get(str) == null) {
|
|
|
|
|
|
response.setContentType("text/html;charset=UTF-8");
|
|
|
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
|
|
out.print("<script>alert(\"该手机号没有注册,请注册!\");window.location.href=\"/register/index.html\";</script>");
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
return null;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
mav.addObject("isVerify", Base64.getEncode(str));
|
|
|
|
|
|
mav.setViewName("mobilecheck");
|
|
|
|
|
|
return mav;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/regSendMes")
|
|
|
|
|
|
public void regSendMes(@RequestParam String isVerify,
|
|
|
|
|
|
@RequestParam String phone,
|
|
|
|
|
|
HttpServletResponse response) throws Exception {
|
|
|
|
|
|
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 (isVerify.equals(Base64.getEncode(phone))) {
|
|
|
|
|
|
if (MemCachedClientHelp.getIMemcachedCache().get(Base64.getEncode(phone)) == null) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
boolean result = SendSMS.sendSMS(phone, ran);
|
|
|
|
|
|
if (result) {
|
|
|
|
|
|
MemCachedClientHelp.getIMemcachedCache().put(Base64.getEncode(phone), ran, new Date(2 * 60 * 1000));
|
|
|
|
|
|
out.print("0");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
out.print("error");
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
out.print("error");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
out.print("2");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
out.print("error");
|
|
|
|
|
|
}
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/checkMobileCode")
|
|
|
|
|
|
public void checkMobileCode(@RequestParam String isVerify,
|
|
|
|
|
|
@RequestParam String key,
|
|
|
|
|
|
HttpServletRequest request,
|
|
|
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
|
|
|
response.setContentType("text/plain;charset=UTF-8");
|
|
|
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
|
|
User user = new User();
|
|
|
|
|
|
String ip = request.getHeader("X-Real-IP");
|
|
|
|
|
|
if (ip == null) {
|
|
|
|
|
|
ip = "127.0.0.1";
|
|
|
|
|
|
}
|
|
|
|
|
|
String date = DateUtil.DateTimeToStr(new Date());
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (MemCachedClientHelp.getIMemcachedCache().get(isVerify) != null) {
|
|
|
|
|
|
if (MemCachedClientHelp.getIMemcachedCache().get(isVerify).equals(key)) {
|
|
|
|
|
|
String phone = Base64.getDecode(isVerify);
|
|
|
|
|
|
user.setPhone(phone);
|
|
|
|
|
|
user.setMailCheck("3");
|
|
|
|
|
|
user.setMobileCheck("0");
|
|
|
|
|
|
String userPwd = (String) MemCachedClientHelp.getIMemcachedCache().get(phone);
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(userPwd)) {
|
|
|
|
|
|
out.print("timeOut");
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
user.setUserPwd(userPwd);
|
|
|
|
|
|
user.setIpAddress(ip);
|
|
|
|
|
|
user.setIpLocation(seeker.getAddress(ip));
|
|
|
|
|
|
user.setOldDate(date);
|
|
|
|
|
|
user.setNewDate(date);
|
|
|
|
|
|
user.setBalance(BigDecimal.valueOf(ApplicationListenerImpl.sysConfigureJson.getRegBalance()));
|
|
|
|
|
|
user.setCommissionBalance(0.00);
|
|
|
|
|
|
user.setCommissionCount(0.00);
|
|
|
|
|
|
user.setCommissionMention(0.00);
|
|
|
|
|
|
user.setCommissionPoints(0);
|
|
|
|
|
|
user.setFaceImg("/Images/defaultUserFace.png");
|
|
|
|
|
|
user.setUserType("0");
|
|
|
|
|
|
user.setExperience(0);
|
|
|
|
|
|
|
|
|
|
|
|
Cookie[] cookies = request.getCookies();
|
|
|
|
|
|
if (request.isRequestedSessionIdFromCookie() && cookies != null) {
|
|
|
|
|
|
for (Cookie cookie : cookies) {
|
|
|
|
|
|
if (cookie.getName().equals("inviteId") && StringUtils.isNotBlank(cookie.getValue())) {
|
|
|
|
|
|
user.setInvite(Integer.parseInt(cookie.getValue()));
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
userService.add(user);
|
|
|
|
|
|
out.print("0");
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
out.print("false");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
out.print("1");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
out.print("false");
|
|
|
|
|
|
}
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/mobileok")
|
|
|
|
|
|
public ModelAndView mobileok(@RequestParam String phone,
|
|
|
|
|
|
HttpServletRequest request,
|
|
|
|
|
|
HttpServletResponse response) throws UnsupportedEncodingException {
|
|
|
|
|
|
ModelAndView mav = new ModelAndView("mobileok");
|
|
|
|
|
|
User user = userService.userByName(phone);
|
|
|
|
|
|
String isVerify = "1";
|
|
|
|
|
|
|
|
|
|
|
|
if (user != null) {
|
|
|
|
|
|
if (user.getMobileCheck().equals("0")) {
|
|
|
|
|
|
isVerify = "0";
|
|
|
|
|
|
if (request.isRequestedSessionIdFromCookie()) {
|
|
|
|
|
|
Cookie cookie = new Cookie("phone", user.getPhone());
|
|
|
|
|
|
cookie.setMaxAge(-1);
|
|
|
|
|
|
cookie.setPath("/");
|
|
|
|
|
|
cookie.setDomain(ApplicationListenerImpl.sysConfigureJson.getDomain());
|
|
|
|
|
|
response.addCookie(cookie);
|
|
|
|
|
|
|
|
|
|
|
|
Cookie cookie2 = new Cookie("userId", String.valueOf(user.getUserId()));
|
|
|
|
|
|
cookie2.setMaxAge(-1);
|
|
|
|
|
|
cookie2.setPath("/");
|
|
|
|
|
|
cookie2.setDomain(ApplicationListenerImpl.sysConfigureJson.getDomain());
|
|
|
|
|
|
response.addCookie(cookie2);
|
|
|
|
|
|
|
|
|
|
|
|
Cookie cookie3 = new Cookie("face", URLEncoder.encode(user.getFaceImg(), "UTF-8"));
|
|
|
|
|
|
cookie3.setMaxAge(-1);
|
|
|
|
|
|
cookie3.setPath("/");
|
|
|
|
|
|
cookie3.setDomain(ApplicationListenerImpl.sysConfigureJson.getDomain());
|
|
|
|
|
|
response.addCookie(cookie3);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
mav.addObject("isVerify", isVerify);
|
|
|
|
|
|
return mav;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/emailcheck")
|
|
|
|
|
|
public ModelAndView emailcheck(@RequestParam String str, HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
|
|
ModelAndView mav = new ModelAndView();
|
|
|
|
|
|
User user = userService.userByName(str);
|
|
|
|
|
|
if (user == null) {
|
|
|
|
|
|
response.setContentType("text/html;charset=UTF-8");
|
|
|
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
|
|
out.print("<script>alert(\"该邮箱没有注册,请注册!\");window.location.href=\"/register/index.html\";</script>");
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
return null;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
mav.addObject("isVerify", user.getMailCheck());
|
|
|
|
|
|
mav.setViewName("emailcheck");
|
|
|
|
|
|
return mav;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/SendRegisterMail")
|
|
|
|
|
|
public void SendRegisterMail(@RequestParam String mail, HttpServletResponse response) 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 + "|" + DateUtil.DateToStr(new Date(), "yyyyMMdd"));
|
|
|
|
|
|
|
|
|
|
|
|
String html = "<table width=\"600\" cellspacing=\"0\" cellpadding=\"0\" style=\"border: #dddddd 1px solid; padding: 20px 0;\">" +
|
|
|
|
|
|
// 邮件HTML内容保持不变
|
|
|
|
|
|
"</table>";
|
|
|
|
|
|
|
|
|
|
|
|
if (MemCachedClientHelp.getIMemcachedCache().get(MD5Util.encode(mail)) == null) {
|
|
|
|
|
|
User user = userService.userByName(mail);
|
|
|
|
|
|
if (user != null) {
|
|
|
|
|
|
if (user.getMailCheck().equals("0")) {
|
|
|
|
|
|
out.print("0");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
try {
|
|
|
|
|
|
boolean flag = EmailUtil.sendEmail(
|
|
|
|
|
|
ApplicationListenerImpl.sysConfigureJson.getMailName(),
|
|
|
|
|
|
ApplicationListenerImpl.sysConfigureJson.getMailPwd(),
|
|
|
|
|
|
mail,
|
|
|
|
|
|
ApplicationListenerImpl.sysConfigureJson.getSiteName() + "验证注册邮箱",
|
|
|
|
|
|
html
|
|
|
|
|
|
);
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
user.setMailCheck("1");
|
|
|
|
|
|
user.setMailKey(key);
|
|
|
|
|
|
userService.add(user);
|
|
|
|
|
|
if (MemCachedClientHelp.getIMemcachedCache() != null) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
MemCachedClientHelp.getIMemcachedCache().put(MD5Util.encode(mail), mail, new Date(10 * 60 * 1000));
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
out.print("2");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
out.print("false");
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
out.print("false");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
User user = userService.userByName(mail);
|
|
|
|
|
|
if (user != null) {
|
|
|
|
|
|
if (user.getMailCheck().equals("1")) {
|
|
|
|
|
|
out.print("3");
|
|
|
|
|
|
} else if (user.getMailCheck().equals("0")) {
|
|
|
|
|
|
out.print("0");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/emailok")
|
|
|
|
|
|
public ModelAndView emailok(@RequestParam(required = false) String key,
|
|
|
|
|
|
HttpServletRequest request,
|
|
|
|
|
|
HttpServletResponse response) throws UnsupportedEncodingException {
|
|
|
|
|
|
ModelAndView mav = new ModelAndView("emailok");
|
|
|
|
|
|
String isVerify = "1";
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(key)) {
|
|
|
|
|
|
String keyMailDateStr = key.substring(64);
|
|
|
|
|
|
String[] keyStr = Base64.getDecode(keyMailDateStr).split("\\|");
|
|
|
|
|
|
if (keyStr.length == 2) {
|
|
|
|
|
|
String mail = keyStr[0];
|
|
|
|
|
|
Date date = DateUtil.StrToDate(keyStr[1], "yyyyMMdd");
|
|
|
|
|
|
if (DateUtil.addDate(new Date(), -1).before(date) && StringUtils.isNotBlank(mail)) {
|
|
|
|
|
|
User user = userService.userByName(mail);
|
|
|
|
|
|
if (MemCachedClientHelp.getIMemcachedCache().get(MD5Util.encode(mail)) != null ||
|
|
|
|
|
|
(user != null && user.getMailKey().equals(key))) {
|
|
|
|
|
|
if (!user.getMailCheck().equals("0")) {
|
|
|
|
|
|
user.setMailCheck("0");
|
|
|
|
|
|
user.setMailKey("");
|
|
|
|
|
|
userService.add(user);
|
|
|
|
|
|
isVerify = "0";
|
|
|
|
|
|
|
|
|
|
|
|
if (request.isRequestedSessionIdFromCookie()) {
|
|
|
|
|
|
Cookie cookie = new Cookie("mail", user.getMail());
|
|
|
|
|
|
cookie.setMaxAge(-1);
|
|
|
|
|
|
cookie.setPath("/");
|
|
|
|
|
|
cookie.setDomain(ApplicationListenerImpl.sysConfigureJson.getDomain());
|
|
|
|
|
|
response.addCookie(cookie);
|
|
|
|
|
|
|
|
|
|
|
|
Cookie cookie2 = new Cookie("userId", String.valueOf(user.getUserId()));
|
|
|
|
|
|
cookie2.setMaxAge(-1);
|
|
|
|
|
|
cookie2.setPath("/");
|
|
|
|
|
|
cookie2.setDomain(ApplicationListenerImpl.sysConfigureJson.getDomain());
|
|
|
|
|
|
response.addCookie(cookie2);
|
|
|
|
|
|
|
|
|
|
|
|
Cookie cookie3 = new Cookie("face", URLEncoder.encode(user.getFaceImg(), "UTF-8"));
|
|
|
|
|
|
cookie3.setMaxAge(-1);
|
|
|
|
|
|
cookie3.setPath("/");
|
|
|
|
|
|
cookie3.setDomain(ApplicationListenerImpl.sysConfigureJson.getDomain());
|
|
|
|
|
|
response.addCookie(cookie3);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
isVerify = "1";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
mav.addObject("isVerify", isVerify);
|
|
|
|
|
|
return mav;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/authorizeIsExists")
|
|
|
|
|
|
public void authorizeIsExists(@RequestParam String openId, HttpServletResponse response) throws IOException {
|
|
|
|
|
|
response.setContentType("application/json;charset=UTF-8");
|
|
|
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
|
|
User user = userService.isNotOpenId(openId);
|
|
|
|
|
|
if (user == null) {
|
|
|
|
|
|
out.print("false");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 这里简化处理,实际应使用JSON工具序列化
|
|
|
|
|
|
out.print(JSONUtils.toJSONString(user));
|
|
|
|
|
|
}
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/authorizeRegsiter")
|
|
|
|
|
|
public void authorizeRegsiter(@RequestParam String openId,
|
|
|
|
|
|
@RequestParam(required = false) String userName,
|
|
|
|
|
|
@RequestParam(required = false) String userFace,
|
|
|
|
|
|
HttpServletRequest request,
|
|
|
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
|
|
|
response.setContentType("application/json;charset=UTF-8");
|
|
|
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
|
|
User user = new User();
|
|
|
|
|
|
String ip = request.getHeader("X-Real-IP");
|
|
|
|
|
|
String date = DateUtil.DateTimeToStr(new Date());
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(userName)) {
|
|
|
|
|
|
user.setUserName(userName);
|
|
|
|
|
|
}
|
|
|
|
|
|
user.setMobileCheck("3");
|
|
|
|
|
|
user.setMailCheck("3");
|
|
|
|
|
|
user.setUserPwd(openId);
|
|
|
|
|
|
user.setQqOpenId(openId);
|
|
|
|
|
|
user.setIpAddress(ip == null ? "127.0.0.1" : ip);
|
|
|
|
|
|
user.setIpLocation(seeker.getAddress(user.getIpAddress()));
|
|
|
|
|
|
user.setOldDate(date);
|
|
|
|
|
|
user.setBalance(BigDecimal.valueOf(ApplicationListenerImpl.sysConfigureJson.getRegBalance()));
|
|
|
|
|
|
user.setCommissionBalance(0.00);
|
|
|
|
|
|
user.setCommissionCount(0.00);
|
|
|
|
|
|
user.setCommissionMention(0.00);
|
|
|
|
|
|
user.setCommissionPoints(0);
|
|
|
|
|
|
user.setFaceImg(userFace);
|
|
|
|
|
|
user.setUserType("0");
|
|
|
|
|
|
user.setExperience(0);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
userService.add(user);
|
|
|
|
|
|
out.print(JSONUtils.toJSONString(user));
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
out.print("false");
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/qqUserInfoAuth")
|
|
|
|
|
|
public ModelAndView qqUserInfoAuth(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
|
|
ModelAndView mav = new ModelAndView();
|
|
|
|
|
|
Cookie[] cookies = request.getCookies();
|
|
|
|
|
|
|
|
|
|
|
|
if (request.isRequestedSessionIdFromCookie() && cookies != null) {
|
|
|
|
|
|
for (Cookie cookie : cookies) {
|
|
|
|
|
|
if (cookie.getName().equals("userId") && StringUtils.isNotBlank(cookie.getValue())) {
|
|
|
|
|
|
User user = userService.findById(cookie.getValue());
|
|
|
|
|
|
user.setAttribute22(user.getQqOpenId());
|
|
|
|
|
|
|
|
|
|
|
|
if ((StringUtils.isNoneEmpty(user.getMobileCheck()) && !user.getMobileCheck().equals("0")) &&
|
|
|
|
|
|
(StringUtils.isNoneEmpty(user.getMail()) && !user.getMailCheck().equals("0"))) {
|
|
|
|
|
|
mav.setViewName("qqUserInfoAuth");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
mav.setViewName("index_index");
|
|
|
|
|
|
}
|
|
|
|
|
|
mav.addObject("user", user);
|
|
|
|
|
|
return mav;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
response.setContentType("text/html;charset=UTF-8");
|
|
|
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
|
|
out.print("<script>alert(\"您的浏览器未开启Cookie功能,无法保存购物信息,请先开启Cookie功能后继续购物!\");window.location.href=\"" +
|
|
|
|
|
|
ApplicationListenerImpl.sysConfigureJson.getWwwUrl() + "/help/help.html?newsId=18\";</script>");
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
return mav;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/isExists")
|
|
|
|
|
|
public void isExists(@RequestParam String userName, HttpServletResponse response) throws IOException {
|
|
|
|
|
|
response.setContentType("text/plain;charset=UTF-8");
|
|
|
|
|
|
PrintWriter out = response.getWriter();
|
|
|
|
|
|
User user = userService.userByName(userName);
|
|
|
|
|
|
out.print(user == null ? "true" : "false");
|
|
|
|
|
|
out.flush();
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|