|
|
@@ -124,9 +124,7 @@ public class LoginController {
|
|
|
// }
|
|
|
|
|
|
/**
|
|
|
- * android 端登录,微信登录
|
|
|
- * 只要带login,都不用权鉴
|
|
|
- *
|
|
|
+ * android 微信登录
|
|
|
* @param openid
|
|
|
* @param unionid
|
|
|
* @param response
|
|
|
@@ -160,6 +158,7 @@ public class LoginController {
|
|
|
if (wxInfo == null) {
|
|
|
//先main_info主表添加信息
|
|
|
mainInfo = createMainInfo();
|
|
|
+ mainInfo.setToken(token);
|
|
|
mainInfoService.addMainInfo(mainInfo);
|
|
|
//微信表添加信息 wx_info
|
|
|
wxInfo = new WxInfo();
|
|
|
@@ -171,6 +170,15 @@ public class LoginController {
|
|
|
wxInfoService.addWxInfo(wxInfo);
|
|
|
} else {
|
|
|
mainInfo = mainInfoService.findMainInfoById(wxInfo.getUserId());
|
|
|
+ //删除用户对应的token
|
|
|
+ Boolean bSuccess = redisSettingMap.deleteValue(RedisType.TOKEN,mainInfo.getToken());
|
|
|
+ if (!bSuccess) {
|
|
|
+ //不存在的话不用处理
|
|
|
+ log.info("client_wx_login,redis 不存在此用户 token。");
|
|
|
+ }
|
|
|
+ //更新token
|
|
|
+ mainInfo.setToken(token);
|
|
|
+ mainInfoService.addMainInfo(mainInfo);
|
|
|
}
|
|
|
|
|
|
//拿到用户userid
|
|
|
@@ -235,74 +243,75 @@ public class LoginController {
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
|
|
- @GetMapping("/client_login")
|
|
|
- public ResultVO client_login(@RequestParam("appid") String appid,
|
|
|
- @RequestParam("code") String code,
|
|
|
- @RequestParam("platfrom") String platFrom,
|
|
|
- HttpServletResponse response,
|
|
|
- HttpServletRequest request) {
|
|
|
- //检查redis 的token 是否存在,存在则删除
|
|
|
- String headToken = request.getHeader("token");
|
|
|
- if (StringUtils.isNotBlank(headToken)) {
|
|
|
-// Boolean bSuccess = redisTemplate.delete(String.format(RedisConstant.TOKEN_PREFIX, headToken));
|
|
|
- Boolean bSuccess = redisSettingMap.deleteValue(RedisType.TOKEN,headToken);
|
|
|
- if (!bSuccess) {
|
|
|
- //删除不成功,redis不存在,是非法token
|
|
|
-// throw new WxInfoException(ResultEnum.TOKEN_IS_ILLEGAL.getCode(), ResultEnum.TOKEN_IS_ILLEGAL.getMessage());
|
|
|
- log.info("redis 没有对应的token");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //1.配置
|
|
|
- //2.调用方法
|
|
|
- final WxMaService wxService = WxMaConfiguration.getMaService(appid);
|
|
|
-
|
|
|
- try {
|
|
|
- //token
|
|
|
- String token = UUID.randomUUID().toString();
|
|
|
- Integer expire = RedisConstant.EXPIRE;//过期时间
|
|
|
-
|
|
|
- Map<String, String> tokenMap = new HashMap<>();
|
|
|
- if (StringUtils.equals(platFrom, "weixin")) {
|
|
|
- WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(code);
|
|
|
- //1.openid 和数据库的对比,没有用户的话,添加新增用户
|
|
|
- WxInfo wxInfo = wxInfoService.findWxInfoByOpenid(session.getOpenid());
|
|
|
-
|
|
|
- if (wxInfo == null) {
|
|
|
- //先main_info主表添加信息
|
|
|
- MainInfo mainInfo = createMainInfo();
|
|
|
- mainInfoService.addMainInfo(mainInfo);
|
|
|
- //微信表添加信息 wx_info
|
|
|
- wxInfo = new WxInfo();
|
|
|
- wxInfo.setUserId(mainInfo.getUserId());
|
|
|
- wxInfo.setOpenid(session.getOpenid());
|
|
|
- wxInfo.setCreateTime(DateUtil.date());
|
|
|
- wxInfo.setUpdateTime(DateUtil.date());
|
|
|
- wxInfoService.addWxInfo(wxInfo);
|
|
|
- }
|
|
|
-
|
|
|
- //拿到微信对应的用户userid
|
|
|
- tokenMap.put("userId", wxInfo.getUserId());
|
|
|
- tokenMap.put("openid", session.getOpenid());
|
|
|
- tokenMap.put("sessionKey", session.getSessionKey());
|
|
|
- tokenMap.put("unionid", session.getUnionid());
|
|
|
- }
|
|
|
- //2.设置token 到redis
|
|
|
- // redisTemplate.opsForValue().set(String.format(RedisConstant.TOKEN_PREFIX,token),session.getOpenid()+session.getSessionKey(),expire, TimeUnit.SECONDS);
|
|
|
-// redisTemplate.opsForHash().putAll(redisSettingMap.getTokenKey(token), tokenMap);
|
|
|
-// redisTemplate.expire(redisSettingMap.getTokenKey(token), expire, TimeUnit.SECONDS);
|
|
|
- redisSettingMap.putToken(token,tokenMap);
|
|
|
- //3.设置token到cookie
|
|
|
- CookieUtil.set(response, CookieConstant.TOKEN, token, expire);
|
|
|
- //TODO 可以增加自己的逻辑,关联业务相关数据
|
|
|
- LoginVO loginVO = new LoginVO();
|
|
|
- loginVO.setToken(token);
|
|
|
- return ResultVOUtil.success(loginVO);
|
|
|
- } catch (WxErrorException e) {
|
|
|
- log.error(e.getMessage(), e);
|
|
|
- return ResultVOUtil.error(500, e.toString());
|
|
|
- }
|
|
|
- }
|
|
|
+// @GetMapping("/client_login")
|
|
|
+// @Deprecated
|
|
|
+// public ResultVO client_login(@RequestParam("appid") String appid,
|
|
|
+// @RequestParam("code") String code,
|
|
|
+// @RequestParam("platfrom") String platFrom,
|
|
|
+// HttpServletResponse response,
|
|
|
+// HttpServletRequest request) {
|
|
|
+// //检查redis 的token 是否存在,存在则删除
|
|
|
+// String headToken = request.getHeader("token");
|
|
|
+// if (StringUtils.isNotBlank(headToken)) {
|
|
|
+//// Boolean bSuccess = redisTemplate.delete(String.format(RedisConstant.TOKEN_PREFIX, headToken));
|
|
|
+// Boolean bSuccess = redisSettingMap.deleteValue(RedisType.TOKEN,headToken);
|
|
|
+// if (!bSuccess) {
|
|
|
+// //删除不成功,redis不存在,是非法token
|
|
|
+//// throw new WxInfoException(ResultEnum.TOKEN_IS_ILLEGAL.getCode(), ResultEnum.TOKEN_IS_ILLEGAL.getMessage());
|
|
|
+// log.info("redis 没有对应的token");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// //1.配置
|
|
|
+// //2.调用方法
|
|
|
+// final WxMaService wxService = WxMaConfiguration.getMaService(appid);
|
|
|
+//
|
|
|
+// try {
|
|
|
+// //token
|
|
|
+// String token = UUID.randomUUID().toString();
|
|
|
+// Integer expire = RedisConstant.EXPIRE;//过期时间
|
|
|
+//
|
|
|
+// Map<String, String> tokenMap = new HashMap<>();
|
|
|
+// if (StringUtils.equals(platFrom, "weixin")) {
|
|
|
+// WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(code);
|
|
|
+// //1.openid 和数据库的对比,没有用户的话,添加新增用户
|
|
|
+// WxInfo wxInfo = wxInfoService.findWxInfoByOpenid(session.getOpenid());
|
|
|
+//
|
|
|
+// if (wxInfo == null) {
|
|
|
+// //先main_info主表添加信息
|
|
|
+// MainInfo mainInfo = createMainInfo();
|
|
|
+// mainInfoService.addMainInfo(mainInfo);
|
|
|
+// //微信表添加信息 wx_info
|
|
|
+// wxInfo = new WxInfo();
|
|
|
+// wxInfo.setUserId(mainInfo.getUserId());
|
|
|
+// wxInfo.setOpenid(session.getOpenid());
|
|
|
+// wxInfo.setCreateTime(DateUtil.date());
|
|
|
+// wxInfo.setUpdateTime(DateUtil.date());
|
|
|
+// wxInfoService.addWxInfo(wxInfo);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //拿到微信对应的用户userid
|
|
|
+// tokenMap.put("userId", wxInfo.getUserId());
|
|
|
+// tokenMap.put("openid", session.getOpenid());
|
|
|
+// tokenMap.put("sessionKey", session.getSessionKey());
|
|
|
+// tokenMap.put("unionid", session.getUnionid());
|
|
|
+// }
|
|
|
+// //2.设置token 到redis
|
|
|
+// // redisTemplate.opsForValue().set(String.format(RedisConstant.TOKEN_PREFIX,token),session.getOpenid()+session.getSessionKey(),expire, TimeUnit.SECONDS);
|
|
|
+//// redisTemplate.opsForHash().putAll(redisSettingMap.getTokenKey(token), tokenMap);
|
|
|
+//// redisTemplate.expire(redisSettingMap.getTokenKey(token), expire, TimeUnit.SECONDS);
|
|
|
+// redisSettingMap.putToken(token,tokenMap);
|
|
|
+// //3.设置token到cookie
|
|
|
+// CookieUtil.set(response, CookieConstant.TOKEN, token, expire);
|
|
|
+// //TODO 可以增加自己的逻辑,关联业务相关数据
|
|
|
+// LoginVO loginVO = new LoginVO();
|
|
|
+// loginVO.setToken(token);
|
|
|
+// return ResultVOUtil.success(loginVO);
|
|
|
+// } catch (WxErrorException e) {
|
|
|
+// log.error(e.getMessage(), e);
|
|
|
+// return ResultVOUtil.error(500, e.toString());
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* <pre>
|
|
|
@@ -364,22 +373,22 @@ public class LoginController {
|
|
|
* @param phoneNumber
|
|
|
* @return
|
|
|
*/
|
|
|
- @GetMapping("/getCode")
|
|
|
- @Deprecated
|
|
|
- public ResultVO getCode(@RequestParam(value = "phoneNumber") String phoneNumber) {
|
|
|
- Integer expire = RedisConstant.CODE_EXPIRE;//过期时间
|
|
|
- String code = String.valueOf((int) ((Math.random() * 9 + 1) * 1000));
|
|
|
- if (phoneNumber != null) {
|
|
|
- aliyunSMSUtil.sendSms(phoneNumber, code);
|
|
|
- //成功后保存code到redis
|
|
|
-// redisTemplate.opsForValue().set(String.format(RedisConstant.SMS_PREFIX, phoneNumber), code, expire, TimeUnit.SECONDS);
|
|
|
- redisSettingMap.setSMS(phoneNumber,code);
|
|
|
- log.info("getCode:" + code);
|
|
|
- return ResultVOUtil.success();
|
|
|
- } else {
|
|
|
- return ResultVOUtil.error(200, "获取code失败");
|
|
|
- }
|
|
|
- }
|
|
|
+// @GetMapping("/getCode")
|
|
|
+// @Deprecated
|
|
|
+// public ResultVO getCode(@RequestParam(value = "phoneNumber") String phoneNumber) {
|
|
|
+// Integer expire = RedisConstant.CODE_EXPIRE;//过期时间
|
|
|
+// String code = String.valueOf((int) ((Math.random() * 9 + 1) * 1000));
|
|
|
+// if (phoneNumber != null) {
|
|
|
+// aliyunSMSUtil.sendSms(phoneNumber, code);
|
|
|
+// //成功后保存code到redis
|
|
|
+//// redisTemplate.opsForValue().set(String.format(RedisConstant.SMS_PREFIX, phoneNumber), code, expire, TimeUnit.SECONDS);
|
|
|
+// redisSettingMap.setSMS(phoneNumber,code);
|
|
|
+// log.info("getCode:" + code);
|
|
|
+// return ResultVOUtil.success();
|
|
|
+// } else {
|
|
|
+// return ResultVOUtil.error(200, "获取code失败");
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 2021-09-18
|
|
|
@@ -392,7 +401,7 @@ public class LoginController {
|
|
|
@GetMapping("/getCodeAccordingType")
|
|
|
public ResultVO getCodeAccordingType(@RequestParam(value = "account") String account,
|
|
|
@RequestParam(value = "type") Integer type) {
|
|
|
- Integer expire = RedisConstant.CODE_EXPIRE;//过期时间
|
|
|
+ //Integer expire = RedisConstant.CODE_EXPIRE;//过期时间
|
|
|
String code = String.valueOf((int) ((Math.random() * 9 + 1) * 1000));
|
|
|
if (account != null) {
|
|
|
|
|
|
@@ -456,47 +465,47 @@ public class LoginController {
|
|
|
* @param code
|
|
|
* @return
|
|
|
*/
|
|
|
- @GetMapping("/SMS_bind_phone")
|
|
|
- @Deprecated
|
|
|
- public ResultVO userBindPhoneNumber(@RequestParam("phoneNumber") String phoneNumber,
|
|
|
- @RequestParam("code") String code,
|
|
|
- @RequestParam("userId") String userId) {
|
|
|
- String codeValue = redisSettingMap.getValue(RedisType.SMS,phoneNumber);
|
|
|
- if (!StringUtils.equals(codeValue, code)) {
|
|
|
- return ResultVOUtil.error(UserEnum.USER_CODE_ERROR.getCode(), UserEnum.USER_CODE_ERROR.getMessage());
|
|
|
- }
|
|
|
- log.info("codeValue:" + codeValue);
|
|
|
-
|
|
|
- try {
|
|
|
-
|
|
|
- MainInfo phoneMainInfo = mainInfoService.findMainInfoByPhoneNumber(phoneNumber);
|
|
|
- if (phoneMainInfo != null) {
|
|
|
- //如果存在,此手机号提示已注册
|
|
|
- return ResultVOUtil.error(UserEnum.USER_HAS_REGISTER_PHONE.getCode(), UserEnum.USER_HAS_REGISTER_PHONE.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- MainInfo mainInfo = mainInfoService.findMainInfoById(userId);
|
|
|
- //TODO 验证码登录流程
|
|
|
- //如果不存在用户
|
|
|
- if (mainInfo == null) {
|
|
|
- return ResultVOUtil.error(UserEnum.USER_REGISTER_ERROR.getCode(), UserEnum.USER_REGISTER_ERROR.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- mainInfo.setTelephoneNumber(phoneNumber);
|
|
|
- mainInfoService.addMainInfo(mainInfo);
|
|
|
- //TODO 写入成功后,删除redis里面保存的code
|
|
|
- Boolean bSuccess = redisSettingMap.deleteValue(RedisType.SMS,phoneNumber);
|
|
|
- if (!bSuccess) {
|
|
|
- //删除不成功,redis不存在
|
|
|
- log.info("redis 没有对应的token");
|
|
|
- }
|
|
|
- return ResultVOUtil.success();
|
|
|
-
|
|
|
- } catch (UserException e) {
|
|
|
- return ResultVOUtil.error(UserEnum.USER_REGISTER_ERROR.getCode(), UserEnum.USER_REGISTER_ERROR.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ //@GetMapping("/SMS_bind_phone")
|
|
|
+ //@Deprecated
|
|
|
+ //public ResultVO userBindPhoneNumber(@RequestParam("phoneNumber") String phoneNumber,
|
|
|
+ // @RequestParam("code") String code,
|
|
|
+ // @RequestParam("userId") String userId) {
|
|
|
+ // String codeValue = redisSettingMap.getValue(RedisType.SMS,phoneNumber);
|
|
|
+ // if (!StringUtils.equals(codeValue, code)) {
|
|
|
+ // return ResultVOUtil.error(UserEnum.USER_CODE_ERROR.getCode(), UserEnum.USER_CODE_ERROR.getMessage());
|
|
|
+ // }
|
|
|
+ // log.info("codeValue:" + codeValue);
|
|
|
+ //
|
|
|
+ // try {
|
|
|
+ //
|
|
|
+ // MainInfo phoneMainInfo = mainInfoService.findMainInfoByPhoneNumber(phoneNumber);
|
|
|
+ // if (phoneMainInfo != null) {
|
|
|
+ // //如果存在,此手机号提示已注册
|
|
|
+ // return ResultVOUtil.error(UserEnum.USER_HAS_REGISTER_PHONE.getCode(), UserEnum.USER_HAS_REGISTER_PHONE.getMessage());
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // MainInfo mainInfo = mainInfoService.findMainInfoById(userId);
|
|
|
+ // //TODO 验证码登录流程
|
|
|
+ // //如果不存在用户
|
|
|
+ // if (mainInfo == null) {
|
|
|
+ // return ResultVOUtil.error(UserEnum.USER_REGISTER_ERROR.getCode(), UserEnum.USER_REGISTER_ERROR.getMessage());
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // mainInfo.setTelephoneNumber(phoneNumber);
|
|
|
+ // mainInfoService.addMainInfo(mainInfo);
|
|
|
+ // //TODO 写入成功后,删除redis里面保存的code
|
|
|
+ // Boolean bSuccess = redisSettingMap.deleteValue(RedisType.SMS,phoneNumber);
|
|
|
+ // if (!bSuccess) {
|
|
|
+ // //删除不成功,redis不存在
|
|
|
+ // log.info("redis 没有对应的token");
|
|
|
+ // }
|
|
|
+ // return ResultVOUtil.success();
|
|
|
+ //
|
|
|
+ // } catch (UserException e) {
|
|
|
+ // return ResultVOUtil.error(UserEnum.USER_REGISTER_ERROR.getCode(), UserEnum.USER_REGISTER_ERROR.getMessage());
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ //}
|
|
|
|
|
|
/**
|
|
|
* 通过验证码,绑定用户手机号码或者邮箱。
|
|
|
@@ -629,59 +638,59 @@ public class LoginController {
|
|
|
* @param code
|
|
|
* @return
|
|
|
*/
|
|
|
- @GetMapping("/SMS_login")
|
|
|
- @Deprecated
|
|
|
- public ResultVO userRegistrationAndSMSLogin(String phoneNumber, String code) {
|
|
|
- String codeValue = redisSettingMap.getValue(RedisType.SMS,phoneNumber);
|
|
|
- if (!StringUtils.equals(codeValue, code)) {
|
|
|
- log.warn("【code校验】Redis 中查找不到验证码 {},==,{}", codeValue, code);
|
|
|
- return ResultVOUtil.error(UserEnum.USER_CODE_ERROR.getCode(), UserEnum.USER_CODE_ERROR.getMessage());
|
|
|
- }
|
|
|
- log.info("codeValue:" + codeValue);
|
|
|
- //token
|
|
|
- String token = UUID.randomUUID().toString();
|
|
|
- Integer expire = RedisConstant.EXPIRE;//过期时间
|
|
|
- Map<String, String> tokenMap = new HashMap<>();
|
|
|
-
|
|
|
- try {
|
|
|
- MainInfo mainInfo = mainInfoService.findMainInfoByPhoneNumber(phoneNumber);
|
|
|
- //TODO 验证码登录流程
|
|
|
- //如果不存在用户
|
|
|
- if (mainInfo == null) {
|
|
|
- //先main_info主表添加信息
|
|
|
- mainInfo = createMainInfo();
|
|
|
- mainInfo.setTelephoneNumber(phoneNumber);
|
|
|
- mainInfoService.addMainInfo(mainInfo);
|
|
|
- }
|
|
|
- //TODO 写入成功后,删除redis里面保存的code
|
|
|
- Boolean bSuccess = redisSettingMap.deleteValue(RedisType.SMS,phoneNumber);
|
|
|
- if (!bSuccess) {
|
|
|
- //删除不成功,redis不存在
|
|
|
- log.info("redis 没有对应的token");
|
|
|
- }
|
|
|
-
|
|
|
- tokenMap.put("userId", mainInfo.getUserId());
|
|
|
-
|
|
|
- redisTemplate.opsForHash().putAll(redisSettingMap.getTokenKey(token), tokenMap);
|
|
|
- redisTemplate.expire(redisSettingMap.getTokenKey(token), expire, TimeUnit.SECONDS);
|
|
|
-
|
|
|
- //返回一个token
|
|
|
- LoginVO loginVO = new LoginVO();
|
|
|
- loginVO.setToken(token);
|
|
|
- loginVO.setNewUser(bUserInfoByUserId(mainInfo.getUserId()));
|
|
|
- return ResultVOUtil.success(loginVO);
|
|
|
-
|
|
|
- } catch (UserException e) {
|
|
|
-
|
|
|
- log.error(e.getMessage(), e);
|
|
|
- return ResultVOUtil.error(UserEnum.USER_REGISTER_ERROR.getCode(), UserEnum.USER_REGISTER_ERROR.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ //@GetMapping("/SMS_login")
|
|
|
+ //@Deprecated
|
|
|
+ //public ResultVO userRegistrationAndSMSLogin(String phoneNumber, String code) {
|
|
|
+ // String codeValue = redisSettingMap.getValue(RedisType.SMS,phoneNumber);
|
|
|
+ // if (!StringUtils.equals(codeValue, code)) {
|
|
|
+ // log.warn("【code校验】Redis 中查找不到验证码 {},==,{}", codeValue, code);
|
|
|
+ // return ResultVOUtil.error(UserEnum.USER_CODE_ERROR.getCode(), UserEnum.USER_CODE_ERROR.getMessage());
|
|
|
+ // }
|
|
|
+ // log.info("codeValue:" + codeValue);
|
|
|
+ // //token
|
|
|
+ // String token = UUID.randomUUID().toString();
|
|
|
+ // Integer expire = RedisConstant.EXPIRE;//过期时间
|
|
|
+ // Map<String, String> tokenMap = new HashMap<>();
|
|
|
+ //
|
|
|
+ // try {
|
|
|
+ // MainInfo mainInfo = mainInfoService.findMainInfoByPhoneNumber(phoneNumber);
|
|
|
+ // //TODO 验证码登录流程
|
|
|
+ // //如果不存在用户
|
|
|
+ // if (mainInfo == null) {
|
|
|
+ // //先main_info主表添加信息
|
|
|
+ // mainInfo = createMainInfo();
|
|
|
+ // mainInfo.setTelephoneNumber(phoneNumber);
|
|
|
+ // mainInfoService.addMainInfo(mainInfo);
|
|
|
+ // }
|
|
|
+ // //TODO 写入成功后,删除redis里面保存的code
|
|
|
+ // Boolean bSuccess = redisSettingMap.deleteValue(RedisType.SMS,phoneNumber);
|
|
|
+ // if (!bSuccess) {
|
|
|
+ // //删除不成功,redis不存在
|
|
|
+ // log.info("redis 没有对应的token");
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // tokenMap.put("userId", mainInfo.getUserId());
|
|
|
+ //
|
|
|
+ // redisTemplate.opsForHash().putAll(redisSettingMap.getTokenKey(token), tokenMap);
|
|
|
+ // redisTemplate.expire(redisSettingMap.getTokenKey(token), expire, TimeUnit.SECONDS);
|
|
|
+ //
|
|
|
+ // //返回一个token
|
|
|
+ // LoginVO loginVO = new LoginVO();
|
|
|
+ // loginVO.setToken(token);
|
|
|
+ // loginVO.setNewUser(bUserInfoByUserId(mainInfo.getUserId()));
|
|
|
+ // return ResultVOUtil.success(loginVO);
|
|
|
+ //
|
|
|
+ // } catch (UserException e) {
|
|
|
+ //
|
|
|
+ // log.error(e.getMessage(), e);
|
|
|
+ // return ResultVOUtil.error(UserEnum.USER_REGISTER_ERROR.getCode(), UserEnum.USER_REGISTER_ERROR.getMessage());
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ //}
|
|
|
|
|
|
/**
|
|
|
- * 根据不同类型账号注册登录
|
|
|
- * 手机或者邮箱
|
|
|
+ * 根据不同类型账号注册(ps:未注册的进行注册)->登录
|
|
|
+ * 手机或者邮箱 code登录
|
|
|
* @param account
|
|
|
* @param code
|
|
|
* @param type
|
|
|
@@ -697,9 +706,8 @@ public class LoginController {
|
|
|
log.info("codeValue:" + codeValue);
|
|
|
//token
|
|
|
String token = UUID.randomUUID().toString();
|
|
|
- Integer expire = RedisConstant.EXPIRE;//过期时间
|
|
|
+ //Integer expire = RedisConstant.EXPIRE;//过期时间
|
|
|
Map<String, String> tokenMap = new HashMap<>();
|
|
|
-
|
|
|
try {
|
|
|
MainInfo mainInfo = null;
|
|
|
if(type.equals(0)){
|
|
|
@@ -707,7 +715,7 @@ public class LoginController {
|
|
|
}else if(type.equals(1)){
|
|
|
mainInfo = mainInfoService.findMainInfoByEmail(account);
|
|
|
}
|
|
|
- //TODO 验证码登录流程
|
|
|
+ //验证码登录流程
|
|
|
//如果不存在用户
|
|
|
if (mainInfo == null) {
|
|
|
//先main_info主表添加信息
|
|
|
@@ -717,13 +725,24 @@ public class LoginController {
|
|
|
}else if(type.equals(1)){
|
|
|
mainInfo.setEmail(account);
|
|
|
}
|
|
|
+ mainInfo.setToken(token);
|
|
|
+ mainInfoService.addMainInfo(mainInfo);
|
|
|
+ } else {
|
|
|
+ //删除用户对应的token
|
|
|
+ Boolean bSuccess = redisSettingMap.deleteValue(RedisType.TOKEN,mainInfo.getToken());
|
|
|
+ if (!bSuccess) {
|
|
|
+ //不存在的话不用处理
|
|
|
+ log.info("SMS_login_from_type,redis 不存在此用户 token。");
|
|
|
+ }
|
|
|
+ //更新token
|
|
|
+ mainInfo.setToken(token);
|
|
|
mainInfoService.addMainInfo(mainInfo);
|
|
|
}
|
|
|
- //TODO 写入成功后,删除redis里面保存的code
|
|
|
+ //写入成功后,删除redis里面保存的code
|
|
|
Boolean bSuccess =redisSettingMap.deleteValue(RedisType.SMS, account);
|
|
|
if (!bSuccess) {
|
|
|
//删除不成功,redis不存在
|
|
|
- log.info("redis 没有对应的token");
|
|
|
+ log.info("code删除不成功!");
|
|
|
}
|
|
|
|
|
|
tokenMap.put("userId", mainInfo.getUserId());
|
|
|
@@ -752,45 +771,45 @@ public class LoginController {
|
|
|
* @param password
|
|
|
* @return
|
|
|
*/
|
|
|
- @GetMapping("/password_login")
|
|
|
- @Deprecated
|
|
|
- public ResultVO userPasswordLogin(String phoneNumber, String password) {
|
|
|
- try {
|
|
|
- MainInfo mainInfo = mainInfoService.findMainInfoByPhoneNumberAndPassword(phoneNumber, password);
|
|
|
-
|
|
|
- //TODO 密码登录流程判断
|
|
|
-// if(!StringUtils.equals(mainInfo.getTelephoneNumber(),phoneNumber)){
|
|
|
-// return ResultVOUtil.error(UserEnum.USER_NOT_PHONE_NUMBER.getCode(),UserEnum.USER_NOT_PHONE_NUMBER.getMessage());
|
|
|
-// }
|
|
|
-// if(!StringUtils.equals(mainInfo.getPassword(),password)){
|
|
|
-// return ResultVOUtil.error(UserEnum.USER_PASSWORD_ERROR.getCode(),UserEnum.USER_PASSWORD_ERROR.getMessage());
|
|
|
+// @GetMapping("/password_login")
|
|
|
+// @Deprecated
|
|
|
+// public ResultVO userPasswordLogin(String phoneNumber, String password) {
|
|
|
+// try {
|
|
|
+// MainInfo mainInfo = mainInfoService.findMainInfoByPhoneNumberAndPassword(phoneNumber, password);
|
|
|
+//
|
|
|
+// //TODO 密码登录流程判断
|
|
|
+//// if(!StringUtils.equals(mainInfo.getTelephoneNumber(),phoneNumber)){
|
|
|
+//// return ResultVOUtil.error(UserEnum.USER_NOT_PHONE_NUMBER.getCode(),UserEnum.USER_NOT_PHONE_NUMBER.getMessage());
|
|
|
+//// }
|
|
|
+//// if(!StringUtils.equals(mainInfo.getPassword(),password)){
|
|
|
+//// return ResultVOUtil.error(UserEnum.USER_PASSWORD_ERROR.getCode(),UserEnum.USER_PASSWORD_ERROR.getMessage());
|
|
|
+//// }
|
|
|
+// if (mainInfo == null) {
|
|
|
+// return ResultVOUtil.error(UserEnum.USER_PASSWORD_ERROR.getCode(), UserEnum.USER_PASSWORD_ERROR.getMessage());
|
|
|
// }
|
|
|
- if (mainInfo == null) {
|
|
|
- return ResultVOUtil.error(UserEnum.USER_PASSWORD_ERROR.getCode(), UserEnum.USER_PASSWORD_ERROR.getMessage());
|
|
|
- }
|
|
|
- //token
|
|
|
- String token = UUID.randomUUID().toString();
|
|
|
- Integer expire = RedisConstant.EXPIRE;//过期时间
|
|
|
- Map<String, String> tokenMap = new HashMap<>();
|
|
|
-
|
|
|
- //TODO 登录成功,返回对应的字段
|
|
|
- tokenMap.put("userId", mainInfo.getUserId());
|
|
|
- redisTemplate.opsForHash().putAll(redisSettingMap.getTokenKey(token), tokenMap);
|
|
|
- redisTemplate.expire(redisSettingMap.getTokenKey(token), expire, TimeUnit.SECONDS);
|
|
|
-
|
|
|
- //返回一个token
|
|
|
- LoginVO loginVO = new LoginVO();
|
|
|
- loginVO.setToken(token);
|
|
|
- loginVO.setNewUser(bUserInfoByUserId(mainInfo.getUserId()));
|
|
|
- return ResultVOUtil.success(loginVO);
|
|
|
- } catch (UserException e) {
|
|
|
-
|
|
|
- log.error(e.getMessage(), e);
|
|
|
- return ResultVOUtil.error(UserEnum.USER_REGISTER_ERROR.getCode(), UserEnum.USER_REGISTER_ERROR.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
+// //token
|
|
|
+// String token = UUID.randomUUID().toString();
|
|
|
+// Integer expire = RedisConstant.EXPIRE;//过期时间
|
|
|
+// Map<String, String> tokenMap = new HashMap<>();
|
|
|
+//
|
|
|
+// //TODO 登录成功,返回对应的字段
|
|
|
+// tokenMap.put("userId", mainInfo.getUserId());
|
|
|
+// redisTemplate.opsForHash().putAll(redisSettingMap.getTokenKey(token), tokenMap);
|
|
|
+// redisTemplate.expire(redisSettingMap.getTokenKey(token), expire, TimeUnit.SECONDS);
|
|
|
+//
|
|
|
+// //返回一个token
|
|
|
+// LoginVO loginVO = new LoginVO();
|
|
|
+// loginVO.setToken(token);
|
|
|
+// loginVO.setNewUser(bUserInfoByUserId(mainInfo.getUserId()));
|
|
|
+// return ResultVOUtil.success(loginVO);
|
|
|
+// } catch (UserException e) {
|
|
|
+//
|
|
|
+// log.error(e.getMessage(), e);
|
|
|
+// return ResultVOUtil.error(UserEnum.USER_REGISTER_ERROR.getCode(), UserEnum.USER_REGISTER_ERROR.getMessage());
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 根据手机号或者邮箱进行密码登录
|
|
|
@@ -812,16 +831,27 @@ public class LoginController {
|
|
|
if (mainInfo == null) {
|
|
|
return ResultVOUtil.error(UserEnum.USER_PASSWORD_ERROR.getCode(), UserEnum.USER_PASSWORD_ERROR.getMessage());
|
|
|
}
|
|
|
+ //刪除舊的token
|
|
|
+ Boolean bSuccess = redisSettingMap.deleteValue(RedisType.TOKEN,mainInfo.getToken());
|
|
|
+ if (!bSuccess) {
|
|
|
+ //不存在的话不用处理
|
|
|
+ log.info("password_login_type,redis 不存在此用户 token。");
|
|
|
+ }
|
|
|
+
|
|
|
//token
|
|
|
String token = UUID.randomUUID().toString();
|
|
|
- Integer expire = RedisConstant.EXPIRE;//过期时间
|
|
|
+ //Integer expire = RedisConstant.EXPIRE;//过期时间
|
|
|
Map<String, String> tokenMap = new HashMap<>();
|
|
|
-
|
|
|
//TODO 登录成功,返回对应的字段
|
|
|
tokenMap.put("userId", mainInfo.getUserId());
|
|
|
// redisTemplate.opsForHash().putAll(redisSettingMap.getTokenKey(token), tokenMap);
|
|
|
// redisTemplate.expire(redisSettingMap.getTokenKey(token), expire, TimeUnit.SECONDS);
|
|
|
redisSettingMap.putToken(token,tokenMap);
|
|
|
+
|
|
|
+ //更新token
|
|
|
+ mainInfo.setToken(token);
|
|
|
+ mainInfoService.addMainInfo(mainInfo);
|
|
|
+
|
|
|
//返回一个token
|
|
|
LoginVO loginVO = new LoginVO();
|
|
|
loginVO.setToken(token);
|
|
|
@@ -856,8 +886,7 @@ public class LoginController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 删除token
|
|
|
- *
|
|
|
+ * Client 退出操作时候,删除token
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
|
|
@@ -878,14 +907,17 @@ public class LoginController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 苹果登录
|
|
|
+ * @param identityToken
|
|
|
+ * @param response
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@GetMapping("/client_apple_login")
|
|
|
public ResultVO appleLogin(@RequestParam("identityToken") String identityToken,
|
|
|
HttpServletResponse response,
|
|
|
HttpServletRequest request) {
|
|
|
-
|
|
|
-
|
|
|
//检查redis 的token 是否存在,存在则删除
|
|
|
String headToken = request.getHeader("token");
|
|
|
if (StringUtils.isNotBlank(headToken)) {
|
|
|
@@ -896,10 +928,7 @@ public class LoginController {
|
|
|
log.info("redis 没有对应的token");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
//todo 处理identityToken,判断是否是非法,暂时默认全部合法
|
|
|
-
|
|
|
-
|
|
|
try {
|
|
|
//验证identityToken
|
|
|
if(!AppleUtil.verify(identityToken)){
|
|
|
@@ -928,6 +957,7 @@ public class LoginController {
|
|
|
if (appleInfo == null) {
|
|
|
//先main_info主表添加信息
|
|
|
mainInfo = createMainInfo();
|
|
|
+ mainInfo.setToken(token);
|
|
|
mainInfoService.addMainInfo(mainInfo);
|
|
|
//微信表添加信息 wx_info
|
|
|
appleInfo = new AppleInfo();
|
|
|
@@ -938,6 +968,15 @@ public class LoginController {
|
|
|
appleInfoService.addAppleInfo(appleInfo);
|
|
|
} else {
|
|
|
mainInfo = mainInfoService.findMainInfoById(appleInfo.getUserId());
|
|
|
+ //刪除舊的token
|
|
|
+ Boolean bSuccess = redisSettingMap.deleteValue(RedisType.TOKEN,mainInfo.getToken());
|
|
|
+ if (!bSuccess) {
|
|
|
+ //不存在的话不用处理
|
|
|
+ log.info("client_apple_login,redis 不存在此用户 token。");
|
|
|
+ }
|
|
|
+ //更新token
|
|
|
+ mainInfo.setToken(token);
|
|
|
+ mainInfoService.addMainInfo(mainInfo);
|
|
|
}
|
|
|
|
|
|
//拿到用户userid
|
|
|
@@ -1009,9 +1048,11 @@ public class LoginController {
|
|
|
{
|
|
|
map.put("showGame",false);
|
|
|
map.put("showVideo",false);
|
|
|
+ map.put("showTool",false);
|
|
|
}else{
|
|
|
map.put("showGame",versionCode.getIsShowGame().equals(1));
|
|
|
map.put("showVideo",versionCode.getIsShowVideo().equals(1));
|
|
|
+ map.put("showTool",versionCode.getIsShowTool().equals(1));
|
|
|
}
|
|
|
map.put("versionCode",versionCode.getCode());
|
|
|
map.put("title",versionCode.getTitle());
|
|
|
@@ -1023,6 +1064,24 @@ public class LoginController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 验证一下当前是否存在修改密码的code
|
|
|
+ * 需要限制访问次数等
|
|
|
+ * @param account
|
|
|
+ * @param code
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/SMS_verify_code")
|
|
|
+ public ResultVO onlyVerifyCode(@RequestParam("account") String account,
|
|
|
+ @RequestParam("code") String code) {
|
|
|
+
|
|
|
+ String codeValue = redisSettingMap.getValue(RedisType.SMS, account);
|
|
|
+ if (!StringUtils.equals(codeValue, code)) {
|
|
|
+ return ResultVOUtil.error(UserEnum.USER_CODE_ERROR.getCode(), UserEnum.USER_CODE_ERROR.getMessage());
|
|
|
+ }
|
|
|
+ return ResultVOUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 根据手机号或者邮箱获取验证码
|
|
|
@@ -1036,8 +1095,7 @@ public class LoginController {
|
|
|
public ResultVO userModifyPassword(@RequestParam("account") String account,
|
|
|
@RequestParam("code") String code,
|
|
|
@RequestParam("type") Integer type,
|
|
|
- @RequestParam("password") String password,
|
|
|
- @RequestParam("userId") String userId) {
|
|
|
+ @RequestParam("password") String password) {
|
|
|
|
|
|
String codeValue = redisSettingMap.getValue(RedisType.SMS, account);
|
|
|
if (!StringUtils.equals(codeValue, code)) {
|