|
|
@ -5,6 +5,7 @@ import com.blockchain.common.base.constant.TokenTypeEnums; |
|
|
|
import com.blockchain.common.base.dto.ResultDTO; |
|
|
|
import com.blockchain.common.base.dto.ResultDTO; |
|
|
|
import com.blockchain.common.base.dto.SessionUserDTO; |
|
|
|
import com.blockchain.common.base.dto.SessionUserDTO; |
|
|
|
import com.blockchain.common.base.dto.TokenDTO; |
|
|
|
import com.blockchain.common.base.dto.TokenDTO; |
|
|
|
|
|
|
|
import com.blockchain.common.base.dto.YyyfUserDto; |
|
|
|
import com.blockchain.common.base.util.HttpRequestUtil; |
|
|
|
import com.blockchain.common.base.util.HttpRequestUtil; |
|
|
|
import com.blockchain.common.base.util.RSACoderUtils; |
|
|
|
import com.blockchain.common.base.util.RSACoderUtils; |
|
|
|
import com.blockchain.common.base.util.SSOHelper; |
|
|
|
import com.blockchain.common.base.util.SSOHelper; |
|
|
@ -18,14 +19,10 @@ 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.UserMain; |
|
|
|
import com.blockchain.server.user.entity.UserMain; |
|
|
|
import com.blockchain.server.user.service.PushUserService; |
|
|
|
import com.blockchain.server.user.service.*; |
|
|
|
import com.blockchain.server.user.service.SmsCountService; |
|
|
|
|
|
|
|
import com.blockchain.server.user.service.UserLoginService; |
|
|
|
|
|
|
|
import com.blockchain.server.user.service.UserMainService; |
|
|
|
|
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
|
import org.apache.commons.lang3.RandomStringUtils; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -34,7 +31,6 @@ import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author huangxl |
|
|
|
* @author huangxl |
|
|
@ -63,6 +59,9 @@ public class LoginController { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private RedisTemplate redisTemplate; |
|
|
|
private RedisTemplate redisTemplate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private YyyfUserService yyyfUserService; |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/password") |
|
|
|
@PostMapping("/password") |
|
|
|
@ApiOperation(value = LoginApi.PassWorldLogin.METHOD_NAME, |
|
|
|
@ApiOperation(value = LoginApi.PassWorldLogin.METHOD_NAME, |
|
|
|
notes = LoginApi.PassWorldLogin.METHOD_NOTE) |
|
|
|
notes = LoginApi.PassWorldLogin.METHOD_NOTE) |
|
|
@ -71,7 +70,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)); |
|
|
|
return handleAppAfterLogin(userMain, clientId, getUserLocale(request), request); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/loginByCode") |
|
|
|
@PostMapping("/loginByCode") |
|
|
@ -85,7 +84,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)); |
|
|
|
return handleAppAfterLogin(userMain, clientId, getUserLocale(request), request); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/register") |
|
|
|
@PostMapping("/register") |
|
|
@ -103,7 +102,7 @@ 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)); |
|
|
|
return handleAppAfterLogin(userMain, clientId, getUserLocale(request), request); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/sendLoginCode") |
|
|
|
@PostMapping("/sendLoginCode") |
|
|
@ -168,21 +167,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) { |
|
|
|
@ApiParam(LoginApi.PassWorldLoginPC.METHOD_API_PASS) @RequestParam(name = "password") String password, HttpServletRequest request) { |
|
|
|
UserMain userMain = userLoginService.handleLoginByPassword(tel, password); |
|
|
|
UserMain userMain = userLoginService.handleLoginByPassword(tel, password); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue()); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue(), request); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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) { |
|
|
|
@ApiParam(LoginApi.SmsCodeLoginPC.METHOD_API_CODE) @RequestParam(name = "code") String code, HttpServletRequest request) { |
|
|
|
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()); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.PC.getValue(), request); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/register2") |
|
|
|
@PostMapping("/register2") |
|
|
@ -193,12 +192,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 |
|
|
|
@ApiParam(LoginApi.RegisterPC.METHOD_API_NICK_NAME) @RequestParam(value = "nickName", required = false) String nickName, HttpServletRequest request |
|
|
|
) { |
|
|
|
) { |
|
|
|
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") |
|
|
@ -216,11 +215,12 @@ public class LoginController { |
|
|
|
* @param tel 手机号 |
|
|
|
* @param tel 手机号 |
|
|
|
* @param timestamp 时间撮 |
|
|
|
* @param timestamp 时间撮 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void setUserToRedis(String id, String tel, long timestamp, String tokenType) { |
|
|
|
private void setUserToRedis(String id, String tel, long timestamp, String tokenType, Integer yyyfUserId) { |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -242,10 +242,10 @@ public class LoginController { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* App登录成功之后的处理 |
|
|
|
* App登录成功之后的处理 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ResultDTO handleAppAfterLogin(UserMain userMain, String clientId, String userLocale) { |
|
|
|
private ResultDTO handleAppAfterLogin(UserMain userMain, String clientId, String userLocale, HttpServletRequest request) { |
|
|
|
//保存用户客户端信息,用于消息通知
|
|
|
|
//保存用户客户端信息,用于消息通知
|
|
|
|
handleAfterLoginToSavePushUser(userMain.getId(), clientId, userLocale); |
|
|
|
handleAfterLoginToSavePushUser(userMain.getId(), clientId, userLocale); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.APP.getValue()); |
|
|
|
return handleAfterLogin(userMain, TokenTypeEnums.APP.getValue(), request); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
/*** |
|
|
@ -269,12 +269,31 @@ public class LoginController { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 登录成功之后的处理 |
|
|
|
* 登录成功之后的处理 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ResultDTO handleAfterLogin(UserMain userMain, String tokenType) { |
|
|
|
private ResultDTO handleAfterLogin(UserMain userMain, String tokenType, HttpServletRequest request) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integer yyyfUserId = null; |
|
|
|
|
|
|
|
String yyyfTtoken = request.getHeader(BaseConstant.YYYF_TOKEN_HEADER); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//如果有token,拿到用户信息,与以渔有方进行绑定
|
|
|
|
|
|
|
|
if (redisTemplate.hasKey(yyyfTtoken)) { |
|
|
|
|
|
|
|
YyyfUserDto yyyfUserDto = (YyyfUserDto) redisTemplate.opsForValue().get(yyyfTtoken); |
|
|
|
|
|
|
|
yyyfUserId = yyyfUserDto.getId(); |
|
|
|
|
|
|
|
String userId =userMain.getId(); |
|
|
|
|
|
|
|
int count = this.yyyfUserService.selectCountByYyyfUserIdAndUserId(yyyfUserId, userId); |
|
|
|
|
|
|
|
if (count == 0) { |
|
|
|
|
|
|
|
this.yyyfUserService.saveUser(yyyfUserId, userId, yyyfUserDto.getName()); |
|
|
|
|
|
|
|
this.redisTemplate.delete(yyyfTtoken); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
long timestamp = System.currentTimeMillis(); |
|
|
|
long timestamp = System.currentTimeMillis(); |
|
|
|
setUserToRedis(userMain.getId(), userMain.getMobilePhone(), timestamp, tokenType); |
|
|
|
setUserToRedis(userMain.getId(), userMain.getMobilePhone(), timestamp, tokenType, yyyfUserId); |
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
return ResultDTO.requstSuccess(userBaseDTO); |
|
|
|
return ResultDTO.requstSuccess(userBaseDTO); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|