|
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
@@ -579,7 +580,7 @@ public class TAdminController {
|
|
@ApiOperation(value = "登录")
|
|
@ApiOperation(value = "登录")
|
|
@PostMapping("/login")
|
|
@PostMapping("/login")
|
|
@Audit(type = AuditEnum.LOGIN, content = "#username + '请求登录'")
|
|
@Audit(type = AuditEnum.LOGIN, content = "#username + '请求登录'")
|
|
- public ResponseModel<UserDetailBO> login(String username, String password, String hostName) {
|
|
|
|
|
|
+ public ResponseModel<UserDetailBO> login(String username, String password, String hostName, HttpServletRequest request) {
|
|
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
|
|
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
|
|
return R.fail(ResponseCodesEnum.A0001, "参数有空");
|
|
return R.fail(ResponseCodesEnum.A0001, "参数有空");
|
|
}
|
|
}
|
|
@@ -619,8 +620,22 @@ public class TAdminController {
|
|
if (StringUtils.isEmpty(tAdmin.getManagerId())) {
|
|
if (StringUtils.isEmpty(tAdmin.getManagerId())) {
|
|
String managerId = AdminUtils.encrypt(false, tAdmin.getId());
|
|
String managerId = AdminUtils.encrypt(false, tAdmin.getId());
|
|
tAdmin.setManagerId(managerId);
|
|
tAdmin.setManagerId(managerId);
|
|
- tAdminService.updateById(tAdmin);
|
|
|
|
}
|
|
}
|
|
|
|
+ // 设置登录时间
|
|
|
|
+ tAdmin.setLoginDate(new Date());
|
|
|
|
+ // 登录IP
|
|
|
|
+ String ipAddress = null;
|
|
|
|
+ // 获取通过代理服务器传递的真实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();
|
|
|
|
+ }
|
|
|
|
+ tAdmin.setLoginIp(ipAddress);
|
|
|
|
+ tAdminService.updateById(tAdmin);
|
|
UserDetailBO userDetailBO = tAdminService.getUserDetailBO(tAdmin);
|
|
UserDetailBO userDetailBO = tAdminService.getUserDetailBO(tAdmin);
|
|
return R.ok(userDetailBO);
|
|
return R.ok(userDetailBO);
|
|
}
|
|
}
|