for gz
This commit is contained in:
parent
869b534c5e
commit
2d75b41377
|
|
@ -17,6 +17,7 @@ import com.bonus.sgzb.system.api.RemoteUserService;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import com.bonus.sgzb.auth.service.SysLoginService;
|
import com.bonus.sgzb.auth.service.SysLoginService;
|
||||||
import com.bonus.sgzb.common.core.domain.R;
|
import com.bonus.sgzb.common.core.domain.R;
|
||||||
|
|
@ -38,10 +39,8 @@ import java.util.Map;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class TokenController {
|
public class TokenController {
|
||||||
|
|
||||||
private final String USER_PASSWORD = "NwCc@2024*";
|
@Value("${sgzb.customer}")
|
||||||
|
private String customer;
|
||||||
private final String privateKey = "MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKNPuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gAkM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWowcSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99EcvDQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthhYhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3UP8iWi1Qw0Y=";
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TokenService tokenService;
|
private TokenService tokenService;
|
||||||
|
|
@ -64,78 +63,77 @@ public class TokenController {
|
||||||
//web端登录
|
//web端登录
|
||||||
@PostMapping("login")
|
@PostMapping("login")
|
||||||
public R<?> login(@RequestBody LoginBody form) throws Exception {
|
public R<?> login(@RequestBody LoginBody form) throws Exception {
|
||||||
String decryptedData = RsaUtil.decryptByPrivateKey(form.getPassword(), Constants.privateKey);
|
if (Constants.CUSTOMER_GZ.equals(customer)) {
|
||||||
// 用户登录
|
//优先校验图形验证码
|
||||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), decryptedData);
|
String uuid = form.getUuid();
|
||||||
if (decryptedData.equals(Constants.USER_PASSWORD)) {
|
Object cacheObject = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
||||||
userInfo.setCode(1);
|
String captcha = cacheObject == null ? null : cacheObject.toString();
|
||||||
}
|
// 获取后立即删除图形验证码缓存
|
||||||
String uuid = form.getUuid();
|
|
||||||
String captcha = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid).toString();
|
|
||||||
if (StringUtils.isBlank(captcha)) {
|
|
||||||
// 删除验证码缓存
|
|
||||||
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
||||||
return R.fail("验证码超时,请重新刷新");
|
if (StringUtils.isBlank(captcha)) {
|
||||||
}
|
throw new ServiceException("图形验证码失效,请重新刷新获取");
|
||||||
if (form.getCode() != null && form.getCode().equals(captcha)) {
|
}
|
||||||
// 删除验证码缓存
|
if (form.getCode() != null && !form.getCode().equals(captcha)) {
|
||||||
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
throw new ServiceException("图形验证码错误");
|
||||||
// 获取登录token
|
}
|
||||||
return R.ok(tokenService.createToken(userInfo));
|
//根据用户名查询用户信息
|
||||||
|
LoginUser user = sysLoginService.selectByName(form.getUsername());
|
||||||
|
if (StringUtils.isNull(user)) {
|
||||||
|
throw new ServiceException("用户名不存在/密码错误");
|
||||||
|
}
|
||||||
|
//获取查询的用户手机号
|
||||||
|
String phone = user.getSysUser().getPhonenumber();
|
||||||
|
if ("adminBns".equals(form.getUsername())) {
|
||||||
|
if (!StringUtils.isNotBlank(phone)) {
|
||||||
|
throw new ServiceException("手机号为空,请联系管理员!");
|
||||||
|
}
|
||||||
|
//管理员用户需要额外校验手机短信验证码
|
||||||
|
String redisCode = redisService.getCacheObject("code_" + phone);
|
||||||
|
if (StringUtils.isEmpty(redisCode)) {
|
||||||
|
throw new ServiceException("短信验证码失效", 500);
|
||||||
|
}
|
||||||
|
if (!StringUtils.equals(redisCode.split(GlobalConstants.STRING_UNDERLINE)[0], form.getTextCode())) {
|
||||||
|
throw new ServiceException("短信验证码错误", 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String decryptedData = RsaUtil.decryptByPrivateKey(form.getPassword(), Constants.privateKey);
|
||||||
|
// 用户登录
|
||||||
|
LoginUser userInfo = sysLoginService.login(form.getUsername(), decryptedData);
|
||||||
|
if (decryptedData.equals(Constants.DEFAULT_USER_PASSWORD_NW)) {
|
||||||
|
userInfo.setCode(1);
|
||||||
|
}
|
||||||
|
if (form.getCode() != null && form.getCode().equals(captcha)) {
|
||||||
|
redisService.deleteObject("code_" + phone);
|
||||||
|
// 获取登录token
|
||||||
|
return R.ok(tokenService.createToken(userInfo));
|
||||||
|
} else {
|
||||||
|
return R.fail("登录失败,请联系管理员!");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// 删除验证码缓存
|
String decryptedData = RsaUtil.decryptByPrivateKey(form.getPassword(), Constants.privateKey);
|
||||||
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
// 用户登录
|
||||||
return R.fail("验证码错误");
|
LoginUser userInfo = sysLoginService.login(form.getUsername(), decryptedData);
|
||||||
}
|
if (decryptedData.equals(Constants.DEFAULT_USER_PASSWORD_CQ)) {
|
||||||
}
|
userInfo.setCode(1);
|
||||||
|
|
||||||
@PostMapping("gz/login")
|
|
||||||
public R<?> login_GZ(@RequestBody LoginBody form) throws Exception {
|
|
||||||
//优先校验图形验证码
|
|
||||||
String uuid = form.getUuid();
|
|
||||||
Object cacheObject = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
|
||||||
String captcha = cacheObject == null ? null : cacheObject.toString();
|
|
||||||
// 获取后立即删除图形验证码缓存
|
|
||||||
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
|
||||||
if (StringUtils.isBlank(captcha)) {
|
|
||||||
throw new ServiceException("图形验证码失效,请重新刷新获取");
|
|
||||||
}
|
|
||||||
if (form.getCode() != null && !form.getCode().equals(captcha)) {
|
|
||||||
throw new ServiceException("图形验证码错误");
|
|
||||||
}
|
|
||||||
//根据用户名查询用户信息
|
|
||||||
LoginUser user = sysLoginService.selectByName(form.getUsername());
|
|
||||||
if (StringUtils.isNull(user)) {
|
|
||||||
throw new ServiceException("用户名不存在/密码错误");
|
|
||||||
}
|
|
||||||
//获取查询的用户手机号
|
|
||||||
String phone = user.getSysUser().getPhonenumber();
|
|
||||||
if ("adminBns".equals(form.getUsername())) {
|
|
||||||
if (!StringUtils.isNotBlank(phone)) {
|
|
||||||
throw new ServiceException("手机号为空,请联系管理员!");
|
|
||||||
}
|
}
|
||||||
//管理员用户需要额外校验手机短信验证码
|
String uuid = form.getUuid();
|
||||||
String redisCode = redisService.getCacheObject("code_" + phone);
|
String captcha = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid).toString();
|
||||||
if (StringUtils.isEmpty(redisCode)) {
|
if (StringUtils.isBlank(captcha)) {
|
||||||
throw new ServiceException("短信验证码失效", 500);
|
// 删除验证码缓存
|
||||||
|
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
||||||
|
return R.fail("验证码超时,请重新刷新");
|
||||||
}
|
}
|
||||||
if (!StringUtils.equals(redisCode.split(GlobalConstants.STRING_UNDERLINE)[0], form.getTextCode())) {
|
if (form.getCode() != null && form.getCode().equals(captcha)) {
|
||||||
throw new ServiceException("短信验证码错误", 500);
|
// 删除验证码缓存
|
||||||
|
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
||||||
|
// 获取登录token
|
||||||
|
return R.ok(tokenService.createToken(userInfo));
|
||||||
|
} else {
|
||||||
|
// 删除验证码缓存
|
||||||
|
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
||||||
|
return R.fail("验证码错误");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String decryptedData = RsaUtil.decryptByPrivateKey(form.getPassword(), privateKey);
|
|
||||||
// 用户登录
|
|
||||||
LoginUser userInfo = sysLoginService.login(form.getUsername(), decryptedData);
|
|
||||||
if (decryptedData.equals(USER_PASSWORD)) {
|
|
||||||
userInfo.setCode(1);
|
|
||||||
}
|
|
||||||
if (form.getCode() != null && form.getCode().equals(captcha)) {
|
|
||||||
redisService.deleteObject("code_" + phone);
|
|
||||||
// 获取登录token
|
|
||||||
return R.ok(tokenService.createToken(userInfo));
|
|
||||||
} else {
|
|
||||||
return R.fail("登录失败,请联系管理员!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -158,36 +156,35 @@ public class TokenController {
|
||||||
|
|
||||||
@PostMapping("sendCode")
|
@PostMapping("sendCode")
|
||||||
public R<?> sendCode(@RequestBody LoginBody form) {
|
public R<?> sendCode(@RequestBody LoginBody form) {
|
||||||
R<Boolean> sendState = remoteUserService.sendCode(form.getPhone());
|
if (Constants.CUSTOMER_GZ.equals(customer)) {
|
||||||
return sendState;
|
if ("adminBns".equals(form.getUsername())) {
|
||||||
}
|
// 根据用户名查询用户信息
|
||||||
|
LoginUser userInfo = sysLoginService.selectByName(form.getUsername());
|
||||||
@PostMapping("gz/sendCode")
|
//获取查询的用户手机号
|
||||||
public R<?> sendCode_GZ(@RequestBody LoginBody form) {
|
String phone = userInfo.getSysUser().getPhonenumber();
|
||||||
if ("adminBns".equals(form.getUsername())) {
|
if (StringUtils.isBlank(phone)) {
|
||||||
// 根据用户名查询用户信息
|
throw new ServiceException("手机号为空,请联系管理员!");
|
||||||
LoginUser userInfo = sysLoginService.selectByName(form.getUsername());
|
}
|
||||||
//获取查询的用户手机号
|
//图形验证码校验成功,发送短信
|
||||||
String phone = userInfo.getSysUser().getPhonenumber();
|
R<Boolean> sendState = remoteUserService.sendCode(phone);
|
||||||
if (StringUtils.isBlank(phone)) {
|
return sendState;
|
||||||
throw new ServiceException("手机号为空,请联系管理员!");
|
} else {
|
||||||
|
String uuid = form.getUuid();
|
||||||
|
String captcha = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid).toString();
|
||||||
|
if (StringUtils.isBlank(captcha)) {
|
||||||
|
// 删除验证码缓存
|
||||||
|
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
||||||
|
return R.fail("验证码超时,请重新刷新");
|
||||||
|
}
|
||||||
|
if (form.getCode() != null && !form.getCode().equals(captcha)) {
|
||||||
|
// 删除验证码缓存
|
||||||
|
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
||||||
|
return R.fail("验证码错误");
|
||||||
|
}
|
||||||
|
R<Boolean> sendState = remoteUserService.sendCode(form.getPhone());
|
||||||
|
return sendState;
|
||||||
}
|
}
|
||||||
//图形验证码校验成功,发送短信
|
|
||||||
R<Boolean> sendState = remoteUserService.sendCode(phone);
|
|
||||||
return sendState;
|
|
||||||
} else {
|
} else {
|
||||||
String uuid = form.getUuid();
|
|
||||||
String captcha = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid).toString();
|
|
||||||
if (StringUtils.isBlank(captcha)) {
|
|
||||||
// 删除验证码缓存
|
|
||||||
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
|
||||||
return R.fail("验证码超时,请重新刷新");
|
|
||||||
}
|
|
||||||
if (form.getCode() != null && !form.getCode().equals(captcha)) {
|
|
||||||
// 删除验证码缓存
|
|
||||||
redisService.deleteObject(CacheConstants.CAPTCHA_CODE_KEY + uuid);
|
|
||||||
return R.fail("验证码错误");
|
|
||||||
}
|
|
||||||
R<Boolean> sendState = remoteUserService.sendCode(form.getPhone());
|
R<Boolean> sendState = remoteUserService.sendCode(form.getPhone());
|
||||||
return sendState;
|
return sendState;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -150,9 +150,14 @@ public class Constants
|
||||||
"org.springframework", "org.apache", "com.bonus.sgzb.common.core.utils.file" };
|
"org.springframework", "org.apache", "com.bonus.sgzb.common.core.utils.file" };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统初始密码
|
* 重庆系统初始密码
|
||||||
*/
|
*/
|
||||||
public static final String USER_PASSWORD = "CqCc@2024*";
|
public static final String DEFAULT_USER_PASSWORD_CQ = "CqCc@2024*";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 南网系统初始密码
|
||||||
|
*/
|
||||||
|
public static final String DEFAULT_USER_PASSWORD_NW = "NwCc@2024*";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统初始密码
|
* 系统初始密码
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue