1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-01 22:53:29 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

用户反馈书籍失效,下载书籍,以及登录注册时记录用户浏览器指纹(获取不到浏览器指纹的使用浏览器UA代替)

This commit is contained in:
2022-04-19 22:49:31 +08:00
parent fe23b88427
commit 26af60e472
16 changed files with 3131 additions and 25 deletions

View File

@@ -19,10 +19,7 @@ import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Config.QCloudCosConfig;
import plus.bookshelf.Controller.VO.FileObjectVO;
import plus.bookshelf.Controller.VO.FileVO;
import plus.bookshelf.Service.Impl.FailureFeedbackServiceImpl;
import plus.bookshelf.Service.Impl.FileObjectServiceImpl;
import plus.bookshelf.Service.Impl.FileServiceImpl;
import plus.bookshelf.Service.Impl.UserServiceImpl;
import plus.bookshelf.Service.Impl.*;
import plus.bookshelf.Service.Model.FailureFeedbackModel;
import plus.bookshelf.Service.Model.FileModel;
import plus.bookshelf.Service.Model.FileObjectModel;
@@ -55,6 +52,9 @@ public class FileController extends BaseController {
@Autowired
FailureFeedbackServiceImpl failureFeedbackService;
@Autowired
VisitorFingerprintLogServiceImpl visitorFingerprintLogService;
@ApiOperation(value = "书籍下载页面获取文件提供的下载方式", notes = "")
@RequestMapping(value = "getFile", method = {RequestMethod.GET})
@ResponseBody
@@ -106,7 +106,9 @@ public class FileController extends BaseController {
public CommonReturnType failureFeedback(@RequestParam(value = "token", required = false) String token,
@RequestParam(value = "bookId", required = false) Integer bookId,
@RequestParam(value = "fileId", required = false) Integer fileId,
@RequestParam(value = "fileObjectId", required = false) Integer fileObjectId) throws BusinessException {
@RequestParam(value = "fileObjectId", required = false) Integer fileObjectId,
@RequestParam(value = "visitorId", required = true) String visitorFingerprint) throws BusinessException {
Integer userId = null;
if (token != null) {
try {
@@ -117,6 +119,10 @@ public class FileController extends BaseController {
}
}
if (!visitorFingerprintLogService.saveFingerprint("Failure Feedback", userId, visitorFingerprint)) {
throw new BusinessException(BusinessErrorCode.OPERATION_NOT_ALLOWED, "参数错误,请联系管理员处理");
}
FailureFeedbackModel failureFeedbackModel = new FailureFeedbackModel();
failureFeedbackModel.setBookId(bookId);
failureFeedbackModel.setFileId(fileId);
@@ -229,7 +235,8 @@ public class FileController extends BaseController {
@RequestParam(value = "fileId", required = false) Integer fileId, // 关联的文件ID创建新文件则为0
// 以下为 GET 请求必传参数
@RequestParam(value = "fileNameAndExt", required = false) String fileNameAndExt
@RequestParam(value = "fileNameAndExt", required = false) String fileNameAndExt,
@RequestParam(value = "visitorId", required = false) String visitorFingerprint
) throws BusinessException, InvocationTargetException, IllegalAccessException {
if (expireMinute == null) {
expireMinute = 30;
@@ -270,6 +277,9 @@ public class FileController extends BaseController {
break;
case GET:
if (!isExist) throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "文件不存在");
if (visitorFingerprint == null || !visitorFingerprintLogService.saveFingerprint("FailureFeedback", userModel.getId(), visitorFingerprint)) {
throw new BusinessException(BusinessErrorCode.OPERATION_NOT_ALLOWED, "参数错误,请联系管理员处理");
}
url = qCloudCosUtils.generatePresignedUrlForGET(userModel.getId(), bookSaveFolder, fileSha1, expireMinute, urlGUID, fileNameAndExt);
break;
case DELETE:

View File

@@ -15,6 +15,7 @@ import plus.bookshelf.Common.Error.BusinessException;
import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Controller.VO.UserVO;
import plus.bookshelf.Service.Impl.UserServiceImpl;
import plus.bookshelf.Service.Impl.VisitorFingerprintLogServiceImpl;
import plus.bookshelf.Service.Model.UserModel;
@Api(tags = "用户操作")
@@ -25,6 +26,9 @@ public class UserController extends BaseController {
@Autowired
UserServiceImpl userService;
@Autowired
VisitorFingerprintLogServiceImpl visitorFingerprintService;
@ApiOperation(value = "用户登录", notes = "传入用户名以及密码明文后台计算密码SHA1值进行登录")
// @ApiImplicitParams(value = {
// @ApiImplicitParam(name = "username", value = "用户名", example = "username1", paramType = "form", dataType = "String", required = true, dataTypeClass = String.class),
@@ -33,8 +37,9 @@ public class UserController extends BaseController {
@RequestMapping(value = "login", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
@ResponseBody
public CommonReturnType login(@RequestParam(value = "username") String username,
@RequestParam(value = "password") String password) throws BusinessException {
if (username == null || password == null) {
@RequestParam(value = "password") String password,
@RequestParam(value = "visitorId") String visitorFingerprint) throws BusinessException {
if (username == null || password == null || visitorFingerprint == null) {
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR);
}
String encryptPwd = DigestUtils.sha1Hex(password);
@@ -43,8 +48,15 @@ public class UserController extends BaseController {
UserVO userVO = convertFromService(userModel);
if (userModel != null) {
if (!visitorFingerprintService.saveFingerprint("Login Success", userModel.getId(), visitorFingerprint)) {
throw new BusinessException(BusinessErrorCode.OPERATION_NOT_ALLOWED, "参数错误,请联系管理员处理");
}
String token = onLogin(userModel);
userVO.setToken(token); // token 仅在用户登录时传一次,后面获取用户状态接口中不重复返回 token 信息
} else {
if (!visitorFingerprintService.saveFingerprint("Login Failed", null, visitorFingerprint)) {
throw new BusinessException(BusinessErrorCode.OPERATION_NOT_ALLOWED, "参数错误,请联系管理员处理");
}
}
return CommonReturnType.create(userVO);
}
@@ -53,7 +65,8 @@ public class UserController extends BaseController {
@RequestMapping(value = "register", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
@ResponseBody
public CommonReturnType register(@RequestParam(value = "username") String username,
@RequestParam(value = "password") String password) throws BusinessException {
@RequestParam(value = "password") String password,
@RequestParam(value = "visitorId") String visitorFingerprint) throws BusinessException {
if (username == null || password == null) {
return null;
}
@@ -62,8 +75,9 @@ public class UserController extends BaseController {
if (!userService.userRegister(username, encryptPwd)) {
throw new BusinessException(BusinessErrorCode.UNKNOWN_ERROR, "未知错误,注册失败");
}
// 注册成功后,进行登录
return login(username, password);
return login(username, password, visitorFingerprint);
}
@ApiOperation(value = "【用户|管理员】用户登出", notes = "用户退出登录")
@@ -102,7 +116,7 @@ public class UserController extends BaseController {
// 已经在 getUserByToken 方法中判断了 token 为空、不合法;用户不存在情况,此处无需再判断
UserModel userModel = userService.getUserByToken(redisTemplate, token);
if(password == null || "".equals(password)){
if (password == null || "".equals(password)) {
throw new BusinessException(BusinessErrorCode.PARAMETER_VALIDATION_ERROR, "参数不合法,缺少密码");
}

View File

@@ -0,0 +1,170 @@
package plus.bookshelf.Dao.DO;
import java.util.Date;
public class VisitorFingerprintLogDO {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column visitor_fingerprint_log.id
*
* @mbg.generated
*/
private Integer id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column visitor_fingerprint_log.visitor_id
*
* @mbg.generated
*/
private String visitorId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column visitor_fingerprint_log.user_id
*
* @mbg.generated
*/
private Integer userId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column visitor_fingerprint_log.create_at
*
* @mbg.generated
*/
private Date createAt;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column visitor_fingerprint_log.action
*
* @mbg.generated
*/
private String action;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column visitor_fingerprint_log.id
*
* @return the value of visitor_fingerprint_log.id
*
* @mbg.generated
*/
public Integer getId() {
return id;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column visitor_fingerprint_log.id
*
* @param id the value for visitor_fingerprint_log.id
*
* @mbg.generated
*/
public void setId(Integer id) {
this.id = id;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column visitor_fingerprint_log.visitor_id
*
* @return the value of visitor_fingerprint_log.visitor_id
*
* @mbg.generated
*/
public String getVisitorId() {
return visitorId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column visitor_fingerprint_log.visitor_id
*
* @param visitorId the value for visitor_fingerprint_log.visitor_id
*
* @mbg.generated
*/
public void setVisitorId(String visitorId) {
this.visitorId = visitorId == null ? null : visitorId.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column visitor_fingerprint_log.user_id
*
* @return the value of visitor_fingerprint_log.user_id
*
* @mbg.generated
*/
public Integer getUserId() {
return userId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column visitor_fingerprint_log.user_id
*
* @param userId the value for visitor_fingerprint_log.user_id
*
* @mbg.generated
*/
public void setUserId(Integer userId) {
this.userId = userId;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column visitor_fingerprint_log.create_at
*
* @return the value of visitor_fingerprint_log.create_at
*
* @mbg.generated
*/
public Date getCreateAt() {
return createAt;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column visitor_fingerprint_log.create_at
*
* @param createAt the value for visitor_fingerprint_log.create_at
*
* @mbg.generated
*/
public void setCreateAt(Date createAt) {
this.createAt = createAt;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column visitor_fingerprint_log.action
*
* @return the value of visitor_fingerprint_log.action
*
* @mbg.generated
*/
public String getAction() {
return action;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column visitor_fingerprint_log.action
*
* @param action the value for visitor_fingerprint_log.action
*
* @mbg.generated
*/
public void setAction(String action) {
this.action = action == null ? null : action.trim();
}
}

View File

@@ -0,0 +1,55 @@
package plus.bookshelf.Dao.Mapper;
import org.springframework.stereotype.Repository;
import plus.bookshelf.Dao.DO.VisitorFingerprintLogDO;
@Repository // 添加这个注解Autowired的时候idea就不会报错了
public interface VisitorFingerprintLogDOMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table visitor_fingerprint_log
*
* @mbg.generated
*/
int deleteByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table visitor_fingerprint_log
*
* @mbg.generated
*/
int insert(VisitorFingerprintLogDO row);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table visitor_fingerprint_log
*
* @mbg.generated
*/
int insertSelective(VisitorFingerprintLogDO row);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table visitor_fingerprint_log
*
* @mbg.generated
*/
VisitorFingerprintLogDO selectByPrimaryKey(Integer id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table visitor_fingerprint_log
*
* @mbg.generated
*/
int updateByPrimaryKeySelective(VisitorFingerprintLogDO row);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table visitor_fingerprint_log
*
* @mbg.generated
*/
int updateByPrimaryKey(VisitorFingerprintLogDO row);
}

View File

@@ -0,0 +1,41 @@
package plus.bookshelf.Service.Impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import plus.bookshelf.Dao.DO.VisitorFingerprintLogDO;
import plus.bookshelf.Dao.Mapper.VisitorFingerprintLogDOMapper;
import plus.bookshelf.Service.Service.VisitorFingerprintLogService;
import java.util.Calendar;
@Service
public class VisitorFingerprintLogServiceImpl implements VisitorFingerprintLogService {
@Autowired
VisitorFingerprintLogDOMapper visitorFingerprintLogDOMapper;
/**
* 将用户指纹信息存入数据库
*
* @param action
* @param userId
* @param fingerprint
* @return
*/
@Override
public Boolean saveFingerprint(String action, Integer userId, String fingerprint) {
VisitorFingerprintLogDO visitorFingerprintLogDO = new VisitorFingerprintLogDO();
visitorFingerprintLogDO.setCreateAt(Calendar.getInstance().getTime());
visitorFingerprintLogDO.setAction(action);
visitorFingerprintLogDO.setUserId(userId);
visitorFingerprintLogDO.setVisitorId(fingerprint);
if (visitorFingerprintLogDO == null) {
return false;
} else {
int affectRows = visitorFingerprintLogDOMapper.insertSelective(visitorFingerprintLogDO);
return affectRows > 0;
}
}
}

View File

@@ -0,0 +1,13 @@
package plus.bookshelf.Service.Service;
public interface VisitorFingerprintLogService {
/**
* 将用户指纹信息存入数据库
*
* @param action
* @param userId
* @param fingerprint
* @return
*/
Boolean saveFingerprint(String action, Integer userId, String fingerprint);
}