|
@@ -1510,5 +1510,121 @@ public class TAdminController {
|
|
|
return R.fail(ResponseCodesEnum.R0007);
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation(value = "发送登录验证码")
|
|
|
+ @PostMapping("/sentLoginCode")
|
|
|
+ public ResponseModel<?> sentLoginCode(@RequestBody LoginParam param) {
|
|
|
+ String phoneOrEmail = param.getPhoneOrEmail();
|
|
|
+ String hostName = param.getHostName();
|
|
|
+ // 定义国内手机号和邮箱的正则表达式
|
|
|
+ String phoneReg = "^1[3-9]\\d{9}$";
|
|
|
+ String emailReg = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
|
|
|
+
|
|
|
+ // 判断 phoneOrEmail 是手机号还是邮箱
|
|
|
+ if (Pattern.matches(phoneReg, phoneOrEmail)) {
|
|
|
+ //检测是否已有手机号注册
|
|
|
+ LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TAdmin::getPhone, phoneOrEmail);
|
|
|
+ TAdmin admin = tAdminService.getOne(query);
|
|
|
+ if (admin == null) {
|
|
|
+ // 说明手机未注册
|
|
|
+ return R.fail(ResponseCodesEnum.R0010);
|
|
|
+ }
|
|
|
+ // 判断是为申泽用户还是七云用户
|
|
|
+ String companyType = admin.getCompanyType();
|
|
|
+ String sZ = "Sunzee";
|
|
|
+ String sC = "Sevencloud";
|
|
|
+
|
|
|
+ // 如果不为管理员
|
|
|
+ if (admin.getType() >= 1) {
|
|
|
+ if (sZ.equals(hostName)) {
|
|
|
+ // 如果companyType不为空,且不等于“0”
|
|
|
+ if (StringUtils.isNotEmpty(companyType) && !companyType.equals("0")) {
|
|
|
+ return R.fail(ResponseCodesEnum.R0010);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sC.equals(hostName)) {
|
|
|
+ // 如果companyType为空,或者不等于“1”
|
|
|
+ if (StringUtils.isEmpty(companyType) || !(companyType.equals("1"))) {
|
|
|
+ return R.fail(ResponseCodesEnum.R0010);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //国内发送短信
|
|
|
+ String result = tMessageCodeService.sentLoginMessage(phoneOrEmail, admin.getCompanyType());
|
|
|
+ return R.ok(result);
|
|
|
+ } else if (Pattern.matches(emailReg, phoneOrEmail)) {
|
|
|
+ //检测是否已有邮箱注册
|
|
|
+ LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TAdmin::getEmail, phoneOrEmail);
|
|
|
+ TAdmin admin = tAdminService.getOne(query);
|
|
|
+ if (admin == null) {
|
|
|
+ // 邮箱未注册
|
|
|
+ return R.fail(ResponseCodesEnum.R0011);
|
|
|
+ }
|
|
|
+ // 判断是为申泽用户还是七云用户
|
|
|
+ String companyType = admin.getCompanyType();
|
|
|
+ String sZ = "Sunzee";
|
|
|
+ String sC = "Sevencloud";
|
|
|
+
|
|
|
+ // 如果不为管理员
|
|
|
+ if (admin.getType() >= 1) {
|
|
|
+ if (sZ.equals(hostName)) {
|
|
|
+ // 如果companyType不为空,且不等于“0”
|
|
|
+ if (StringUtils.isNotEmpty(companyType) && !companyType.equals("0")) {
|
|
|
+ return R.fail(ResponseCodesEnum.R0011);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sC.equals(hostName)) {
|
|
|
+ // 如果companyType为空,或者不等于“1”
|
|
|
+ if (StringUtils.isEmpty(companyType) || !(companyType.equals("1"))) {
|
|
|
+ return R.fail(ResponseCodesEnum.R0011);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 发邮件
|
|
|
+ String result = tMessageCodeService.sentLoginEmail(phoneOrEmail, hostName);
|
|
|
+ return R.ok(result);
|
|
|
+ }
|
|
|
+ return R.fail(ResponseCodesEnum.R0004);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "验证码登录")
|
|
|
+ @PostMapping("/loginByCode")
|
|
|
+ public ResponseModel<?> loginByCode(@RequestBody LoginParam param, HttpServletRequest request) {
|
|
|
+ String phoneOrEmail = param.getPhoneOrEmail();
|
|
|
+ String code = param.getCode();
|
|
|
+
|
|
|
+ String loginCode = tokenManager.getLoginCode(phoneOrEmail);
|
|
|
+ if (loginCode != null && loginCode.equals(code)) {
|
|
|
+ tokenManager.deleteLoginCode(phoneOrEmail);
|
|
|
+ LambdaQueryWrapper<TAdmin> query = Wrappers.lambdaQuery();
|
|
|
+ query.eq(TAdmin::getPhone, phoneOrEmail).or().eq(TAdmin::getEmail, phoneOrEmail);
|
|
|
+ TAdmin admin = tAdminService.getOne(query);
|
|
|
+ // 添加系统id
|
|
|
+ if (StringUtils.isEmpty(admin.getManagerId())) {
|
|
|
+ String managerId = AdminUtils.encrypt(false, admin.getId());
|
|
|
+ admin.setManagerId(managerId);
|
|
|
+ }
|
|
|
+ // 设置登录时间
|
|
|
+ admin.setLoginDate(new Date());
|
|
|
+ // 登录IP
|
|
|
+ String ipAddress;
|
|
|
+ // 获取通过代理服务器传递的真实IP地址
|
|
|
+ String xForwardedForHeader = request.getHeader("X-Forwarded-For");
|
|
|
+ if (xForwardedForHeader == null) {
|
|
|
+ ipAddress = request.getRemoteAddr();
|
|
|
+ } else {
|
|
|
+ // 多次反向代理后会有多个IP值,第一个IP才是真实IP
|
|
|
+ String[] ips = xForwardedForHeader.split(",");
|
|
|
+ ipAddress = ips[0].trim();
|
|
|
+ }
|
|
|
+ admin.setLoginIp(ipAddress);
|
|
|
+ tAdminService.updateById(admin);
|
|
|
+ UserDetailBO userDetailBO = tAdminService.getUserDetailBO(admin);
|
|
|
+ return R.ok(userDetailBO);
|
|
|
+ }
|
|
|
+ return R.fail(ResponseCodesEnum.R0007);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|