|
@@ -1,25 +1,91 @@
|
|
|
package com.finikes.oc.base.controller;
|
|
package com.finikes.oc.base.controller;
|
|
|
|
|
|
|
|
import com.finikes.oc.BaseDTO;
|
|
import com.finikes.oc.BaseDTO;
|
|
|
|
|
+import com.finikes.oc.BizException;
|
|
|
|
|
+import com.finikes.oc.base.dao.PassportDAO;
|
|
|
|
|
+import com.finikes.oc.base.dto.RegisterResponseDTO;
|
|
|
|
|
+import com.finikes.oc.base.entity.Passport;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
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 javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
@RequestMapping("/passport")
|
|
@RequestMapping("/passport")
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
@Controller
|
|
@Controller
|
|
|
public class PassportController {
|
|
public class PassportController {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private PassportDAO passportDAO;
|
|
|
|
|
+
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
@RequestMapping(value = "/", method = RequestMethod.PUT)
|
|
@RequestMapping(value = "/", method = RequestMethod.PUT)
|
|
|
public BaseDTO register(@RequestBody Map<String, Object> map) {
|
|
public BaseDTO register(@RequestBody Map<String, Object> map) {
|
|
|
// 获取手机号码
|
|
// 获取手机号码
|
|
|
String mobile = (String) map.get("mobile");
|
|
String mobile = (String) map.get("mobile");
|
|
|
- // 如果已经注册就报错 TODO
|
|
|
|
|
|
|
+ String password = (String) map.get("password");
|
|
|
|
|
+ // 如果已经注册就报错
|
|
|
|
|
+ Passport tmp = passportDAO.findByMobile(mobile);
|
|
|
|
|
+ if (tmp != null && tmp.getState() == 1) {
|
|
|
|
|
+ return new BaseDTO(new BizException("100", "该手机号码已经注册"));
|
|
|
|
|
+ }
|
|
|
// 预注册并生成短信验证码 TODO
|
|
// 预注册并生成短信验证码 TODO
|
|
|
- return new BaseDTO();
|
|
|
|
|
|
|
+ String veriCode = "1234";
|
|
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
|
|
+ long veriCodeDeadline = now + 60 * 1000 * 5;
|
|
|
|
|
+ int id = 0;
|
|
|
|
|
+ if (tmp == null) {
|
|
|
|
|
+ id = passportDAO.insert(mobile, password, veriCode, veriCodeDeadline);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ passportDAO.updateVeriCode(mobile, veriCode, veriCodeDeadline);
|
|
|
|
|
+ id = tmp.getId();
|
|
|
|
|
+ }
|
|
|
|
|
+ RegisterResponseDTO dto = new RegisterResponseDTO();
|
|
|
|
|
+ dto.setPassportId(String.valueOf(id));
|
|
|
|
|
+ dto.setVerificationCode(veriCode);
|
|
|
|
|
+ return new BaseDTO().setContent(dto);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ResponseBody
|
|
|
|
|
+ @RequestMapping(value = "/", method = RequestMethod.POST)
|
|
|
|
|
+ public BaseDTO login(@RequestBody Map<String, Object> map, HttpServletRequest request,
|
|
|
|
|
+ HttpServletResponse response) {
|
|
|
|
|
+ String mobile = (String) map.get("mobile");
|
|
|
|
|
+ String securityCode = (String) map.get("securityCode");
|
|
|
|
|
+ String type = (String) map.get("type");
|
|
|
|
|
+ System.out.println(mobile + " ++++++");
|
|
|
|
|
+ Passport tmp = passportDAO.findByMobile(mobile);
|
|
|
|
|
+ System.out.println(tmp);
|
|
|
|
|
+ if (tmp == null || tmp.getState() != 1) {
|
|
|
|
|
+ System.out.println("00000000");
|
|
|
|
|
+ return new BaseDTO(new BizException("101", "登录失败"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ("1".equals(type)) { // 密码登录
|
|
|
|
|
+ if (securityCode.equals(tmp.getPassword())) {
|
|
|
|
|
+ HttpSession session = request.getSession();
|
|
|
|
|
+ session.setAttribute("PASSPORT", tmp);
|
|
|
|
|
+ return new BaseDTO();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.out.println("1111111");
|
|
|
|
|
+ return new BaseDTO(new BizException("101", "登录失败"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (securityCode.equals(tmp.getVeriCode()) && (System.currentTimeMillis() + 6000 * 5) <= tmp.getVeriCodeDeadline()) {
|
|
|
|
|
+ HttpSession session = request.getSession();
|
|
|
|
|
+ session.setAttribute("PASSPORT", tmp);
|
|
|
|
|
+ return new BaseDTO();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.out.println("2222222222");
|
|
|
|
|
+ return new BaseDTO(new BizException("101", "登录失败"));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|