|
|
@@ -1,108 +1,108 @@
|
|
|
-package org.jeecg.modules.api.sys;
|
|
|
-
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import io.swagger.annotations.ApiImplicitParam;
|
|
|
-import io.swagger.annotations.ApiImplicitParams;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.jeecg.common.sms.SMSConst;
|
|
|
-import org.jeecg.common.util.ErrorCode;
|
|
|
-import org.jeecg.common.util.RedisUtil;
|
|
|
-import org.jeecg.common.util.StringUtils;
|
|
|
-import org.jeecg.modules.hwuser.service.IHwUserService;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-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.RestController;
|
|
|
-import org.springframework.web.servlet.ModelAndView;
|
|
|
-import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-@Slf4j
|
|
|
-@Api(tags = "用户api")
|
|
|
-@RestController
|
|
|
-@RequestMapping("/api/hwuser")
|
|
|
-public class LoginAppControllerAPI extends BaseAppController {
|
|
|
- @Autowired
|
|
|
- private IHwUserService hwUserService;
|
|
|
- @Autowired
|
|
|
- private RedisUtil redisUtil;
|
|
|
-
|
|
|
- /**
|
|
|
- * 手机端快速登录,验证码发送
|
|
|
- */
|
|
|
- @ApiOperation(notes = "getAuthCode", httpMethod = "GET", value = "app获取验证码")
|
|
|
- @ApiImplicitParams(@ApiImplicitParam(name = "phone", value = "手机号", required = true, paramType = "query", dataType = "string"))
|
|
|
- @GetMapping(value = "/getAuthCode")
|
|
|
- public ModelAndView getAuthCode4LoginQuickly(HttpServletRequest request, HttpServletResponse response) {
|
|
|
- response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
- response.setHeader("Access-Control-Allow-Method", "POST,GET");
|
|
|
- Map<String, Object> obj = null;
|
|
|
- HashMap<String, String> requestMap = findRequestMap(request);
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
- try {
|
|
|
- Map<String, Object> returnMap = hwUserService.sendMobileCode(requestMap);
|
|
|
- if (SMSConst.OKCode.equals(returnMap.get("success"))) {
|
|
|
- map.put("code", returnMap.get("code"));
|
|
|
- obj = successResult(ErrorCode.code_1000, "", map);
|
|
|
- } else {
|
|
|
- obj = errorResult(ErrorCode.code_1008, (String) returnMap.get("msg"));
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- obj = errorResult(ErrorCode.code_1008, "获取验证码失败");
|
|
|
- logError(request, e.getMessage(), e);
|
|
|
- }
|
|
|
-
|
|
|
- ModelAndView view = new ModelAndView(new MappingJackson2JsonView(), obj);
|
|
|
- return view;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 手机端快速登录,登录验证
|
|
|
- */
|
|
|
- @PostMapping(value = "/phoneLogin")
|
|
|
- public ModelAndView phoneLogin(HttpServletRequest request, HttpServletResponse response) {
|
|
|
- response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
- response.setHeader("Access-Control-Allow-Method", "POST,GET");
|
|
|
- Map<String, Object> obj = null;
|
|
|
- HashMap<String, String> requestMap = findRequestMap(request);
|
|
|
- Map<String, Object> returnMap = new HashMap<String, Object>();
|
|
|
- try {
|
|
|
- String phone = requestMap.get("phone");
|
|
|
- if (StringUtils.isNotBlank(phone)) {
|
|
|
- if ("15214381724".equals(phone)) {
|
|
|
- returnMap = hwUserService.getLoginApp(requestMap, request);
|
|
|
- obj = successResult(ErrorCode.code_1000, "登录成功", returnMap);
|
|
|
- }else{
|
|
|
- String code = (String) redisUtil.get(phone);
|
|
|
- String getCode = requestMap.get("code");
|
|
|
- if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(getCode)) {
|
|
|
- if (code.equals(getCode)) {
|
|
|
- returnMap = hwUserService.getLoginApp(requestMap, request);
|
|
|
- obj = successResult(ErrorCode.code_1000, "登录成功", returnMap);
|
|
|
- } else {
|
|
|
- obj = errorResult(ErrorCode.code_1011, "验证码错误");
|
|
|
- }
|
|
|
- } else {
|
|
|
- obj = errorResult(ErrorCode.code_1012, "验证码无效或用户不存在");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- obj = errorResult(ErrorCode.code_1003, "登录失败");
|
|
|
- logError(request, e.getMessage(), e);
|
|
|
- }
|
|
|
- ModelAndView view = new ModelAndView(new MappingJackson2JsonView(), obj);
|
|
|
- return view;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+package org.jeecg.modules.api.sys;
|
|
|
+
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.sms.SMSConst;
|
|
|
+import org.jeecg.common.util.ErrorCode;
|
|
|
+import org.jeecg.common.util.RedisUtil;
|
|
|
+import org.jeecg.common.util.StringUtils;
|
|
|
+import org.jeecg.modules.hwuser.service.IHwUserService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.servlet.ModelAndView;
|
|
|
+import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Api(tags = "用户api")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/hwuser")
|
|
|
+public class LoginAppControllerAPI extends BaseAppController {
|
|
|
+ @Autowired
|
|
|
+ private IHwUserService hwUserService;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手机端快速登录,验证码发送
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(notes = "getCaptchaCode", httpMethod = "POST", value = "app获取验证码")
|
|
|
+ @ApiImplicitParams(@ApiImplicitParam(name = "phone", value = "手机号", required = true, paramType = "query", dataType = "string"))
|
|
|
+ @GetMapping(value = "/getCaptchaCode")
|
|
|
+ public ModelAndView getCaptchaCode(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
+ response.setHeader("Access-Control-Allow-Method", "POST,GET");
|
|
|
+ Map<String, Object> obj = null;
|
|
|
+ HashMap<String, String> requestMap = findRequestMap(request);
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ try {
|
|
|
+ Map<String, Object> returnMap = hwUserService.sendMobileCode(requestMap, request);
|
|
|
+ if (SMSConst.OKCode.equals(returnMap.get("success"))) {
|
|
|
+ map.put("code", returnMap.get("code"));
|
|
|
+ obj = successResult(ErrorCode.code_1000, "", map);
|
|
|
+ } else {
|
|
|
+ obj = errorResult(ErrorCode.code_1008, (String) returnMap.get("msg"));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ obj = errorResult(ErrorCode.code_1008, "获取验证码失败");
|
|
|
+ logError(request, e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ ModelAndView view = new ModelAndView(new MappingJackson2JsonView(), obj);
|
|
|
+ return view;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手机端快速登录,登录验证
|
|
|
+ */
|
|
|
+ @PostMapping(value = "/phoneLogin")
|
|
|
+ public ModelAndView phoneLogin(HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
+ response.setHeader("Access-Control-Allow-Method", "POST,GET");
|
|
|
+ Map<String, Object> obj = null;
|
|
|
+ HashMap<String, String> requestMap = findRequestMap(request);
|
|
|
+ Map<String, Object> returnMap = new HashMap<String, Object>();
|
|
|
+ try {
|
|
|
+ String phone = requestMap.get("phone");
|
|
|
+ if (StringUtils.isNotBlank(phone)) {
|
|
|
+ if ("15214381724".equals(phone)) {
|
|
|
+ returnMap = hwUserService.getLoginApp(requestMap, request);
|
|
|
+ obj = successResult(ErrorCode.code_1000, "登录成功", returnMap);
|
|
|
+ } else {
|
|
|
+ String code = (String) redisUtil.get(phone);
|
|
|
+ String getCode = requestMap.get("code");
|
|
|
+ if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(getCode)) {
|
|
|
+ if (code.equals(getCode)) {
|
|
|
+ returnMap = hwUserService.getLoginApp(requestMap, request);
|
|
|
+ obj = successResult(ErrorCode.code_1000, "登录成功", returnMap);
|
|
|
+ } else {
|
|
|
+ obj = errorResult(ErrorCode.code_1011, "验证码错误");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ obj = errorResult(ErrorCode.code_1012, "验证码无效或用户不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ obj = errorResult(ErrorCode.code_1003, "登录失败");
|
|
|
+ logError(request, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ ModelAndView view = new ModelAndView(new MappingJackson2JsonView(), obj);
|
|
|
+ return view;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|