|
@@ -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;
|
|
@@ -21,13 +18,16 @@ import cn.iselab.mooctest.user.web.exception.HttpBadRequestException;
|
|
|
import cn.iselab.mooctest.user.web.logic.BaseLogic;
|
|
|
import cn.iselab.mooctest.user.web.logic.UserLogic;
|
|
|
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;
|
|
|
|
|
|
import javax.mail.MessagingException;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.net.URLEncoder;
|
|
@@ -38,6 +38,7 @@ import java.util.List;
|
|
|
* @author sean
|
|
|
* @date 2018-03-04.
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
|
|
@@ -70,11 +71,13 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
|
|
|
@Autowired
|
|
|
private BankAccountInfoService bankAccountInfoService;
|
|
|
+ private String userId;
|
|
|
|
|
|
@Override
|
|
|
public UserDTO getUserByEmail(String s) {
|
|
|
User user = userService.findByEmail(s);
|
|
|
if (user == null) {
|
|
|
+ log.error("There is not this email");
|
|
|
return null;
|
|
|
}
|
|
|
UserDTO dto = userWrapper.wrap(user);
|
|
@@ -326,6 +329,7 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
// LOG.error(result.getMsg());
|
|
|
// return result;
|
|
|
// }
|
|
|
+ System.out.println(userDTO.getEmail());
|
|
|
if (!EmailValidator.getInstance().isValid(userDTO.getEmail())){
|
|
|
result.init(ResponseStatus.FAILED, "邮箱输入非法", receiver);
|
|
|
LOG.error(result.getMsg());
|
|
@@ -419,7 +423,7 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
}
|
|
|
User user = userService.findByMobile(mobile);
|
|
|
if (user == null){
|
|
|
- result.init(ResponseStatus.FAILED, "该手机号未绑定慕测账号", userVO);
|
|
|
+ result.init(ResponseStatus.FAILED, "该手机号未绑定平台账号", userVO);
|
|
|
LOG.error(result.getMsg() + userVO.getMobile());
|
|
|
return result;
|
|
|
}
|
|
@@ -476,7 +480,7 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
}
|
|
|
User user = userService.findByMobile(userVO.getMobile());
|
|
|
if (user == null){
|
|
|
- result.init(ResponseStatus.FAILED, "该手机号未绑定慕测账号", userVO);
|
|
|
+ result.init(ResponseStatus.FAILED, "该手机号未绑定平台账号", userVO);
|
|
|
LOG.error(result.getMsg() + userVO.getMobile());
|
|
|
return result;
|
|
|
}
|
|
@@ -549,7 +553,7 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
@Override
|
|
|
public ResponseResult<UserVO> updateUserPassword(UserVO userVO, HttpServletRequest request){
|
|
|
ResponseResult<UserVO> result = new ResponseResult<>();
|
|
|
- Long userId = (Long) request.getSession().getAttribute("userId");
|
|
|
+ Long userId = Long.parseLong((String) request.getSession().getAttribute("userId"));
|
|
|
try {
|
|
|
if (userId == null)
|
|
|
throw new Exception("用户未登录");
|
|
@@ -581,16 +585,48 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public ResponseResult<UserVO> updateUserPasswordNew(UserVO userVO, HttpServletRequest request){
|
|
|
+ ResponseResult<UserVO> result = new ResponseResult<>();
|
|
|
+ Long userId = userVO.getId();
|
|
|
+ User user = userService.findById(userId);
|
|
|
+ try {
|
|
|
+ if(userId == null)
|
|
|
+ throw new Exception("用户未登录");
|
|
|
+ if (userVO.getPassword().length() > 16 || userVO.getPassword().length() < 6){
|
|
|
+ throw new Exception("密码长度应在6-16位");
|
|
|
+ }
|
|
|
+ if (!EncryptionUtil.encryptMD5(userVO.getOldPassword()).equals(user.getPassword()))
|
|
|
+ throw new Exception("旧密码错误");
|
|
|
+
|
|
|
+ String password = EncryptionUtil.encryptMD5(userVO.getPassword());
|
|
|
+ user.setPassword(password);
|
|
|
+ user = userService.update(user);
|
|
|
+ userVO = userVOWrapper.wrap(user);
|
|
|
+ userVO.setPassword("");
|
|
|
+ userVO.setPassword2("");
|
|
|
+ result.init(ResponseStatus.SUCCESS, "密码修改成功", userVO);
|
|
|
+ LOG.info(result.getMsg()+" userId: "+userVO.getId());
|
|
|
+ request.getSession().removeAttribute("userId");
|
|
|
+ request.getSession().invalidate();
|
|
|
+ } catch (Exception e) {
|
|
|
+ result.init(ResponseStatus.FAILED, e.getMessage(), userVO);
|
|
|
+ LOG.error(result.getMsg(),e);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public ResponseResult<UserVO> updateUserEmail(UserVO userVO, HttpServletRequest request) {
|
|
|
ResponseResult<UserVO> result = new ResponseResult<>();
|
|
|
- Long userId = (Long) request.getSession().getAttribute("userId");
|
|
|
+ Long userId = userVO.getId();
|
|
|
+ User user = userService.findById(userId);
|
|
|
try {
|
|
|
- if (userId == null)
|
|
|
+ if(userId == null || !user.getPassword().equals(userVO.getPassword()))
|
|
|
throw new Exception("用户未登录");
|
|
|
if (!verifyCodeService.validateVerifyCode("email", userVO.getEmail(), userVO.getVerifyCode()))
|
|
|
throw new Exception("验证码或邮箱填写错误");
|
|
|
- User user = userService.findById(userId);
|
|
|
- if (!userVO.getEmail().equals(user.getEmail()) && userService.findByEmail(userVO.getEmail()) != null)
|
|
|
+ if (userVO.getEmail().equals(user.getEmail()) || userService.findByEmail(userVO.getEmail()) != null)
|
|
|
throw new Exception("该邮箱已被注册");
|
|
|
user.setEmail(userVO.getEmail());
|
|
|
userVO = userVOWrapper.wrap(userService.update(user));
|
|
@@ -607,18 +643,18 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
@Override
|
|
|
public ResponseResult<UserVO> updateUserMobile(UserVO userVO, HttpServletRequest request) {
|
|
|
ResponseResult<UserVO> result = new ResponseResult<>();
|
|
|
- Long userId = (Long) request.getSession().getAttribute("userId");
|
|
|
+ Long userId = userVO.getId();
|
|
|
+ User user = userService.findById(userId);
|
|
|
try {
|
|
|
- if (userId == null)
|
|
|
+ if(userId == null || !user.getPassword().equals(userVO.getPassword()))
|
|
|
throw new Exception("用户未登录");
|
|
|
if (!verifyCodeService.validateVerifyCode("mobile", userVO.getMobile(), userVO.getVerifyCode()))
|
|
|
throw new Exception("验证码或手机号填写错误");
|
|
|
- User user = userService.findById(userId);
|
|
|
- if (!userVO.getMobile().equals(user.getMobile()) && userService.findByMobile(userVO.getMobile()) != null)
|
|
|
+ if (userVO.getMobile().equals(user.getMobile()) || userService.findByMobile(userVO.getMobile()) != null)
|
|
|
throw new Exception("该手机号码已被绑定");
|
|
|
user.setMobile(userVO.getMobile());
|
|
|
userVO = userVOWrapper.wrap(userService.update(user));
|
|
|
- result.init(ResponseStatus.SUCCESS, "手机号修改成功", userVO);
|
|
|
+ result.init(ResponseStatus.SUCCESS, "手机号绑定成功", userVO);
|
|
|
LOG.info(result.getMsg() + " userId: "+ userVO.getId() + " mobile: " + userVO.getMobile());
|
|
|
} catch (Exception e){
|
|
|
result.init(ResponseStatus.FAILED, e.getMessage(), userVO);
|
|
@@ -629,6 +665,28 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public ResponseResult<UserVO> verifyOldMobile(UserVO userVO, HttpServletRequest request) {
|
|
|
+ ResponseResult<UserVO> result = new ResponseResult<>();
|
|
|
+ Long userId = userVO.getId();
|
|
|
+ User user = userService.findById(userId);
|
|
|
+ try {
|
|
|
+ if(userId == null || !user.getPassword().equals(userVO.getPassword()))
|
|
|
+ throw new Exception("用户未登录");
|
|
|
+ if (!verifyCodeService.validateVerifyCode("mobile", userVO.getMobile(), userVO.getVerifyCode()))
|
|
|
+ throw new Exception("验证码或手机号填写错误");
|
|
|
+ if (!userVO.getMobile().equals(user.getMobile()))
|
|
|
+ throw new Exception("此手机号不是用户绑定的手机号");
|
|
|
+ LOG.info(result.getMsg() + "旧手机验证成功 userId: "+ userVO.getId() + " mobile: " + userVO.getMobile());
|
|
|
+ result.init(ResponseStatus.SUCCESS, "验证成功", userVO);
|
|
|
+ } catch (Exception e){
|
|
|
+ result.init(ResponseStatus.FAILED, e.getMessage(), userVO);
|
|
|
+ LOG.info(result.getMsg(), e);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public ResponseResult<Object> setBankInfo(BankAccountInfoVO infoVO, HttpServletRequest request) {
|
|
|
try {
|
|
|
infoVO.setId_card_front_url(ossUtil.upload(infoVO.getID_card_front(), OSSUtil.FileDirType.BANKINFO));
|
|
@@ -636,7 +694,7 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
}catch (Exception e){
|
|
|
return new ResponseResult<Object>(ResponseStatus.FAILED, "上传失败,请稍后再试",null);
|
|
|
}
|
|
|
- infoVO.setUser_id((Long) request.getSession().getAttribute("userId"));
|
|
|
+ infoVO.setUser_id(Long.parseLong((String) request.getSession().getAttribute("userId")));
|
|
|
BankAccountInfo info = bankAccountInfoService.setBankAccountInfo(bankAccountInfoVOWrapper.unwrap(infoVO));
|
|
|
if (info==null){
|
|
|
return new ResponseResult<Object>(ResponseStatus.FAILED, "上传出错,请稍后再试",null);
|
|
@@ -664,5 +722,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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|