|
@@ -5,10 +5,7 @@ import cn.iselab.mooctest.user.configure.MailProperties;
|
|
|
import cn.iselab.mooctest.user.constants.VerifyConstants;
|
|
|
import cn.iselab.mooctest.user.constants.ResponseStatus;
|
|
|
import cn.iselab.mooctest.user.data.ResponseResult;
|
|
|
-import cn.iselab.mooctest.user.model.BankAccountInfo;
|
|
|
-import cn.iselab.mooctest.user.model.User;
|
|
|
-import cn.iselab.mooctest.user.model.UserIntegral;
|
|
|
-import cn.iselab.mooctest.user.model.VerifyCode;
|
|
|
+import cn.iselab.mooctest.user.model.*;
|
|
|
import cn.iselab.mooctest.user.service.*;
|
|
|
import cn.iselab.mooctest.user.util.EncryptionUtil;
|
|
|
import cn.iselab.mooctest.user.util.MSUtil;
|
|
@@ -24,6 +21,7 @@ import cn.iselab.mooctest.user.web.wrapper.UserWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
import org.apache.commons.validator.routines.EmailValidator;
|
|
|
+import org.apache.zookeeper.Op;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -668,5 +666,106 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void recordLoginAction(HttpServletRequest request, Long userId, String resource) {
|
|
|
+ OperationRecord record = this.buildUserOperation(request,userId,resource);
|
|
|
+ if(record==null)
|
|
|
+ return;
|
|
|
+ record.setOperation("Login");
|
|
|
+ userService.recordOperation(record);
|
|
|
+ Timestamp current = new Timestamp(System.currentTimeMillis());
|
|
|
+ log.info(String.format("User[%d] Login at [%s] IP(%s)",userId,current.toString(), record.getIp()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void recordLogoutAction(HttpServletRequest request, Long userId, String resource) {
|
|
|
+ OperationRecord userOperation = this.buildUserOperation(request,userId, resource);
|
|
|
+ if(userOperation==null)
|
|
|
+ return;
|
|
|
+ userOperation.setOperation("Logout");
|
|
|
+ userService.recordOperation(userOperation);
|
|
|
+ Timestamp current = new Timestamp(System.currentTimeMillis());
|
|
|
+ log.info(String.format("User[%d] Logout at [%s]",userId,current.toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void recordUserOperation(HttpServletRequest request, Long userId, String operation, String resource) {
|
|
|
+ OperationRecord record = this.buildUserOperation(request, userId, resource);
|
|
|
+ record.setOperation(operation);
|
|
|
+ userService.recordOperation(record);
|
|
|
+ Timestamp current = new Timestamp(System.currentTimeMillis());
|
|
|
+ log.info(String.format("User[%d] [%s] at [%s]", userId, operation,current.toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void recordUserOperation(OperationRecord record) {
|
|
|
+ userService.recordOperation(record);
|
|
|
+ Timestamp current = new Timestamp(System.currentTimeMillis());
|
|
|
+ log.info(String.format("User[%d] [%s] at [%s]",record.getUserId(),record.getOperation(),current.toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void recordUserOperation(String ip, Long userId, String operation, String resource) {
|
|
|
+ OperationRecord record = this.buildUserOperation(ip, userId, resource);
|
|
|
+ record.setOperation(operation);
|
|
|
+ userService.recordOperation(record);
|
|
|
+ Timestamp current = new Timestamp(System.currentTimeMillis());
|
|
|
+ log.info(String.format("User[%d] [%s] at [%s]", userId, operation,current.toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ private OperationRecord buildUserOperation(HttpServletRequest request, Long userId, String resource) {
|
|
|
+ String ip = this.getRequestIp(request);
|
|
|
+ if("101.37.78.167".equals(ip)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ OperationRecord userOperation = new OperationRecord();
|
|
|
+ userOperation.setIp(ip);
|
|
|
+ userOperation.setUserId(userId);
|
|
|
+ userOperation.setResource(resource);
|
|
|
+ return userOperation;
|
|
|
+ }
|
|
|
+
|
|
|
+ private OperationRecord buildUserOperation(String ip, Long userId, String resource) {
|
|
|
+ if("101.37.78.167".equals(ip)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ OperationRecord userOperation = new OperationRecord();
|
|
|
+ userOperation.setIp(ip);
|
|
|
+ userOperation.setUserId(userId);
|
|
|
+ userOperation.setResource(resource);
|
|
|
+ return userOperation;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getRequestIp(HttpServletRequest request){
|
|
|
+ String ip = request.getHeader("x-forwarded-for");
|
|
|
+ if (isNotValidIP(ip)) {
|
|
|
+ ip = request.getHeader("Proxy-Client-IP");
|
|
|
+ }
|
|
|
+ if (isNotValidIP(ip)) {
|
|
|
+ ip = request.getHeader("WL-Proxy-Client-IP");
|
|
|
+ }
|
|
|
+ if (isNotValidIP(ip)) {
|
|
|
+ ip = request.getRemoteAddr();
|
|
|
+ }
|
|
|
+ if (isNotValidIP(ip)) {
|
|
|
+ ip = request.getHeader("http_client_ip");
|
|
|
+ }
|
|
|
+ if (isNotValidIP(ip)) {
|
|
|
+ ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
|
|
+ }
|
|
|
+ if (ip.equals("0:0:0:0:0:0:0:1")) {
|
|
|
+ ip = "127.0.0.1";
|
|
|
+ }
|
|
|
+ if (ip.split(",").length > 1) {
|
|
|
+ ip = ip.split(",")[0];
|
|
|
+ }
|
|
|
+ return ip;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isNotValidIP(String ip) {
|
|
|
+ return ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|