|
|
@ -19,8 +19,8 @@ import com.blockchain.server.user.common.utils.EmailCodeUtils; |
|
|
|
import com.blockchain.server.user.common.utils.SmsCodeUtils; |
|
|
|
import com.blockchain.server.user.common.utils.SmsCodeUtils; |
|
|
|
import com.blockchain.server.user.controller.api.LoginApi; |
|
|
|
import com.blockchain.server.user.controller.api.LoginApi; |
|
|
|
import com.blockchain.server.user.dto.UserBaseDTO; |
|
|
|
import com.blockchain.server.user.dto.UserBaseDTO; |
|
|
|
|
|
|
|
import com.blockchain.server.user.entity.AssessUser; |
|
|
|
import com.blockchain.server.user.entity.UserMain; |
|
|
|
import com.blockchain.server.user.entity.UserMain; |
|
|
|
import com.blockchain.server.user.entity.YyyfUser; |
|
|
|
|
|
|
|
import com.blockchain.server.user.service.*; |
|
|
|
import com.blockchain.server.user.service.*; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
@ -60,9 +60,8 @@ public class LoginController { |
|
|
|
private SmsCodeUtils smsCodeUtils; |
|
|
|
private SmsCodeUtils smsCodeUtils; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private RedisTemplate redisTemplate; |
|
|
|
private RedisTemplate redisTemplate; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private YyyfUserService yyyfUserService; |
|
|
|
private AssessUserService assessUserService; |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/password") |
|
|
|
@PostMapping("/password") |
|
|
|
@ApiOperation(value = LoginApi.PassWorldLogin.METHOD_NAME, |
|
|
|
@ApiOperation(value = LoginApi.PassWorldLogin.METHOD_NAME, |
|
|
@ -72,7 +71,7 @@ public class LoginController { |
|
|
|
@ApiParam(LoginApi.PassWorldLogin.METHOD_API_CLIENT_ID) @RequestParam(name = "clientId", required = false) String clientId, |
|
|
|
@ApiParam(LoginApi.PassWorldLogin.METHOD_API_CLIENT_ID) @RequestParam(name = "clientId", required = false) String clientId, |
|
|
|
HttpServletRequest request) { |
|
|
|
HttpServletRequest request) { |
|
|
|
UserMain userMain = userLoginService.handleLoginByPassword(tel, password); |
|
|
|
UserMain userMain = userLoginService.handleLoginByPassword(tel, password); |
|
|
|
return handleAppAfterLogin(userMain, clientId, getUserLocale(request), request); |
|
|
|
return handleAppAfterLogin(userMain, clientId, getUserLocale(request)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/loginByCode") |
|
|
|
@PostMapping("/loginByCode") |
|
|
@ -86,7 +85,7 @@ public class LoginController { |
|
|
|
UserMain userMain = userLoginService.handleLoginByPhoneCode(tel); |
|
|
|
UserMain userMain = userLoginService.handleLoginByPhoneCode(tel); |
|
|
|
// userMainService.selectByMobilePhone(tel);
|
|
|
|
// userMainService.selectByMobilePhone(tel);
|
|
|
|
smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_LOGIN); |
|
|
|
smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_LOGIN); |
|
|
|
return handleAppAfterLogin(userMain, clientId, getUserLocale(request), request); |
|
|
|
return handleAppAfterLogin(userMain, clientId, getUserLocale(request)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/register") |
|
|
|
@PostMapping("/register") |
|
|
@ -104,7 +103,9 @@ public class LoginController { |
|
|
|
smsCodeUtils.validateVerifyCode(code, tel, SmsCountEnum.SMS_COUNT_REGISTER); |
|
|
|
smsCodeUtils.validateVerifyCode(code, tel, SmsCountEnum.SMS_COUNT_REGISTER); |
|
|
|
UserMain userMain = userMainService.handleRegister(tel, invitationCode, internationalCode, password, nickName); |
|
|
|
UserMain userMain = userMainService.handleRegister(tel, invitationCode, internationalCode, password, nickName); |
|
|
|
smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_REGISTER); |
|
|
|
smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_REGISTER); |
|
|
|
return handleAppAfterLogin(userMain, clientId, getUserLocale(request), request); |
|
|
|
//处理区块链用户id
|
|
|
|
|
|
|
|
dealBindYyyfAccount(userMain.getId(),request); |
|
|
|
|
|
|
|
return handleAppAfterLogin(userMain, clientId, getUserLocale(request)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/sendLoginCode") |
|
|
|
@PostMapping("/sendLoginCode") |
|
|
@ -169,21 +170,21 @@ public class LoginController { |
|
|
|
@ApiOperation(value = LoginApi.PassWorldLoginPC.METHOD_NAME, |
|
|
|
@ApiOperation(value = LoginApi.PassWorldLoginPC.METHOD_NAME, |
|
|
|
notes = LoginApi.PassWorldLoginPC.METHOD_NOTE) |
|
|
|
notes = LoginApi.PassWorldLoginPC.METHOD_NOTE) |
|
|
|
public ResultDTO loginByPasswordPC(@ApiParam(LoginApi.PassWorldLoginPC.METHOD_API_TEL) @RequestParam(name = "tel") String tel, |
|
|
|
public ResultDTO loginByPasswordPC(@ApiParam(LoginApi.PassWorldLoginPC.METHOD_API_TEL) @RequestParam(name = "tel") String tel, |
|
|
|
@ApiParam(LoginApi.PassWorldLoginPC.METHOD_API_PASS) @RequestParam(name = "password") String password, HttpServletRequest request) { |
|
|
|
@ApiParam(LoginApi.PassWorldLoginPC.METHOD_API_PASS) @RequestParam(name = "password") String password) { |
|
|
|
UserMain userMain = userLoginService.handleLoginByPassword(tel, password); |
|
|
|
UserMain userMain = userLoginService.handleLoginByPassword(tel, password); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue(), request); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/loginByCode2") |
|
|
|
@PostMapping("/loginByCode2") |
|
|
|
@ApiOperation(value = LoginApi.SmsCodeLoginPC.METHOD_NAME, |
|
|
|
@ApiOperation(value = LoginApi.SmsCodeLoginPC.METHOD_NAME, |
|
|
|
notes = LoginApi.SmsCodeLoginPC.METHOD_NOTE) |
|
|
|
notes = LoginApi.SmsCodeLoginPC.METHOD_NOTE) |
|
|
|
public ResultDTO loginBysmsCodePC(@ApiParam(LoginApi.SmsCodeLoginPC.METHOD_API_TEL) @RequestParam(name = "tel") String tel, |
|
|
|
public ResultDTO loginBysmsCodePC(@ApiParam(LoginApi.SmsCodeLoginPC.METHOD_API_TEL) @RequestParam(name = "tel") String tel, |
|
|
|
@ApiParam(LoginApi.SmsCodeLoginPC.METHOD_API_CODE) @RequestParam(name = "code") String code, HttpServletRequest request) { |
|
|
|
@ApiParam(LoginApi.SmsCodeLoginPC.METHOD_API_CODE) @RequestParam(name = "code") String code) { |
|
|
|
smsCodeUtils.validateVerifyCode(code, tel, SmsCountEnum.SMS_COUNT_LOGIN); |
|
|
|
smsCodeUtils.validateVerifyCode(code, tel, SmsCountEnum.SMS_COUNT_LOGIN); |
|
|
|
UserMain userMain = userLoginService.handleLoginByPhoneCode(tel); |
|
|
|
UserMain userMain = userLoginService.handleLoginByPhoneCode(tel); |
|
|
|
// userMainService.selectByMobilePhone(tel);
|
|
|
|
// userMainService.selectByMobilePhone(tel);
|
|
|
|
smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_LOGIN); |
|
|
|
smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_LOGIN); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue(), request); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/register2") |
|
|
|
@PostMapping("/register2") |
|
|
@ -194,13 +195,12 @@ public class LoginController { |
|
|
|
@ApiParam(LoginApi.RegisterPC.METHOD_API_INVITATION_CODE) @RequestParam(value = "invitationCode", required = false) String invitationCode, |
|
|
|
@ApiParam(LoginApi.RegisterPC.METHOD_API_INVITATION_CODE) @RequestParam(value = "invitationCode", required = false) String invitationCode, |
|
|
|
@ApiParam(LoginApi.RegisterPC.METHOD_API_PASSWORD) @RequestParam(value = "password", required = false) String password, |
|
|
|
@ApiParam(LoginApi.RegisterPC.METHOD_API_PASSWORD) @RequestParam(value = "password", required = false) String password, |
|
|
|
@ApiParam(LoginApi.RegisterPC.METHOD_API_INTERNATIONAL_CODE) @RequestParam(value = "internationalCode", required = false, defaultValue = InternationalConstant.DEFAULT_CODE) String internationalCode, |
|
|
|
@ApiParam(LoginApi.RegisterPC.METHOD_API_INTERNATIONAL_CODE) @RequestParam(value = "internationalCode", required = false, defaultValue = InternationalConstant.DEFAULT_CODE) String internationalCode, |
|
|
|
@ApiParam(LoginApi.RegisterPC.METHOD_API_NICK_NAME) @RequestParam(value = "nickName", required = false) String nickName, HttpServletRequest request |
|
|
|
@ApiParam(LoginApi.RegisterPC.METHOD_API_NICK_NAME) @RequestParam(value = "nickName", required = false) String nickName |
|
|
|
) { |
|
|
|
) { |
|
|
|
smsCodeUtils.validateVerifyCode(code, tel, SmsCountEnum.SMS_COUNT_REGISTER); |
|
|
|
smsCodeUtils.validateVerifyCode(code, tel, SmsCountEnum.SMS_COUNT_REGISTER); |
|
|
|
UserMain userMain = userMainService.handleRegister(tel, invitationCode, internationalCode, password, nickName); |
|
|
|
UserMain userMain = userMainService.handleRegister(tel, invitationCode, internationalCode, password, nickName); |
|
|
|
smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_REGISTER); |
|
|
|
smsCodeUtils.removeKey(tel, SmsCountEnum.SMS_COUNT_REGISTER); |
|
|
|
|
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue()); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue(), request); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/loginout2") |
|
|
|
@PostMapping("/loginout2") |
|
|
@ -218,12 +218,11 @@ public class LoginController { |
|
|
|
* @param tel 手机号 |
|
|
|
* @param tel 手机号 |
|
|
|
* @param timestamp 时间撮 |
|
|
|
* @param timestamp 时间撮 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void setUserToRedis(String id, String tel, long timestamp, String tokenType, Integer yyyfUserId) { |
|
|
|
private void setUserToRedis(String id, String tel, long timestamp, String tokenType) { |
|
|
|
SessionUserDTO userDTO = new SessionUserDTO(); |
|
|
|
SessionUserDTO userDTO = new SessionUserDTO(); |
|
|
|
userDTO.setId(id); |
|
|
|
userDTO.setId(id); |
|
|
|
userDTO.setTel(tel); |
|
|
|
userDTO.setTel(tel); |
|
|
|
userDTO.setTimestamp(timestamp); |
|
|
|
userDTO.setTimestamp(timestamp); |
|
|
|
userDTO.setYyyfUserId(yyyfUserId); |
|
|
|
|
|
|
|
SSOHelper.setUser(userDTO, redisTemplate, tokenType); |
|
|
|
SSOHelper.setUser(userDTO, redisTemplate, tokenType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -245,10 +244,10 @@ public class LoginController { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* App登录成功之后的处理 |
|
|
|
* App登录成功之后的处理 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ResultDTO handleAppAfterLogin(UserMain userMain, String clientId, String userLocale, HttpServletRequest request) { |
|
|
|
private ResultDTO handleAppAfterLogin(UserMain userMain, String clientId, String userLocale) { |
|
|
|
//保存用户客户端信息,用于消息通知
|
|
|
|
//保存用户客户端信息,用于消息通知
|
|
|
|
handleAfterLoginToSavePushUser(userMain.getId(), clientId, userLocale); |
|
|
|
handleAfterLoginToSavePushUser(userMain.getId(), clientId, userLocale); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.APP.getValue(), request); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.APP.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
/*** |
|
|
@ -272,11 +271,9 @@ public class LoginController { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 登录成功之后的处理 |
|
|
|
* 登录成功之后的处理 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ResultDTO handleAfterLogin(UserMain userMain, String tokenType, HttpServletRequest request) { |
|
|
|
private ResultDTO handleAfterLogin(UserMain userMain, String tokenType) { |
|
|
|
|
|
|
|
|
|
|
|
String userId = userMain.getId(); |
|
|
|
|
|
|
|
long timestamp = System.currentTimeMillis(); |
|
|
|
long timestamp = System.currentTimeMillis(); |
|
|
|
setUserToRedis(userMain.getId(), userMain.getMobilePhone(), timestamp, tokenType, dealBindYyyfAccount(userId, userMain.getMobilePhone(), request)); |
|
|
|
setUserToRedis(userMain.getId(), userMain.getMobilePhone(), timestamp, tokenType); |
|
|
|
String token = generateToken(userMain.getMobilePhone(), timestamp, tokenType); |
|
|
|
String token = generateToken(userMain.getMobilePhone(), timestamp, tokenType); |
|
|
|
UserBaseDTO userBaseDTO = userMainService.selectUserInfoById(userMain.getId()); |
|
|
|
UserBaseDTO userBaseDTO = userMainService.selectUserInfoById(userMain.getId()); |
|
|
|
userBaseDTO.setToken(token); |
|
|
|
userBaseDTO.setToken(token); |
|
|
@ -317,26 +314,21 @@ public class LoginController { |
|
|
|
return ResultDTO.requstSuccess(); |
|
|
|
return ResultDTO.requstSuccess(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @param [userId, tel, request] |
|
|
|
* @param [userId, request] |
|
|
|
* @return java.lang.String |
|
|
|
* @return java.lang.String |
|
|
|
* @description 处理yyyf账号绑定 |
|
|
|
* @description 处理yyyf账号绑定 |
|
|
|
**/ |
|
|
|
**/ |
|
|
|
private Integer dealBindYyyfAccount(String userId, String tel, HttpServletRequest request) { |
|
|
|
private Integer dealBindYyyfAccount(String userId,HttpServletRequest request) { |
|
|
|
Integer yyyfUserId = null; |
|
|
|
Integer yyyfUserId = null; |
|
|
|
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDto(request, redisTemplate); |
|
|
|
YyyfUserDto yyyfUserDto = YyyfUserDtoUtils.getYyyfUserDto(request, redisTemplate); |
|
|
|
//如果有token,拿到用户信息,与以渔有方进行绑定
|
|
|
|
//如果有token,拿到用户信息,与以渔有方进行绑定
|
|
|
|
if (yyyfUserDto != null) { |
|
|
|
if (yyyfUserDto != null) { |
|
|
|
yyyfUserId = yyyfUserDto.getUserId(); |
|
|
|
AssessUser assessUser = assessUserService.selectAssessUserById(yyyfUserDto.getAssessUserId()); |
|
|
|
YyyfUser yyyfUser = this.yyyfUserService.selectByYyyfUserIdAndTel(yyyfUserId, tel); |
|
|
|
assessUser.setQUserId(userId); |
|
|
|
if (yyyfUser == null) { |
|
|
|
assessUserService.update(assessUser); |
|
|
|
this.yyyfUserService.saveUser(yyyfUserId, userId,tel, yyyfUserDto.getUserName()); |
|
|
|
|
|
|
|
// this.redisTemplate.delete(yyyfTtoken);
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (!yyyfUser.getUserId().equals(userId)) { |
|
|
|
|
|
|
|
throw new UserException(UserEnums.USER_NOT_FORBID_OTHER_USER); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//通过当前用户id与以渔有方用户关联
|
|
|
|
//通过当前用户id与以渔有方用户关联
|
|
|
|
redisTemplate.opsForValue().set(BaseConstant.USER_ID_YYYF_USER_KEY.concat(userId),yyyfUserDto); |
|
|
|
redisTemplate.opsForValue().set(BaseConstant.USER_ID_YYYF_USER_KEY.concat(userId),yyyfUserDto); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|