实现对密保问题的设置和加密存储
This commit is contained in:
@@ -4,18 +4,23 @@ import com.fjy.spring.domain.*;
|
||||
import com.fjy.spring.enums.ResultEnum;
|
||||
import com.fjy.spring.exception.UserException;
|
||||
import com.fjy.spring.service.*;
|
||||
import com.fjy.spring.untils.CodingUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
public class DataController {
|
||||
|
||||
@Autowired
|
||||
@@ -43,7 +48,7 @@ public class DataController {
|
||||
private VUserfileService vUserfileService;
|
||||
|
||||
@Resource
|
||||
HttpServletRequest httpServletRequest;
|
||||
private HttpServletRequest httpServletRequest;
|
||||
|
||||
@GetMapping("/home/findAllHomework")
|
||||
public List<VWorkDetail> findAllHomework(){
|
||||
@@ -51,8 +56,7 @@ public class DataController {
|
||||
if (homeworks!=null){
|
||||
return homeworks;
|
||||
}
|
||||
new UserException(ResultEnum.EMPTY_DATA);
|
||||
return null;
|
||||
throw new UserException(ResultEnum.EMPTY_DATA);
|
||||
}
|
||||
|
||||
@GetMapping("/home/findvlog")
|
||||
@@ -61,8 +65,7 @@ public class DataController {
|
||||
if (vlogs!=null){
|
||||
return vlogs;
|
||||
}
|
||||
new UserException(ResultEnum.EMPTY_DATA);
|
||||
return null;
|
||||
throw new UserException(ResultEnum.EMPTY_DATA);
|
||||
}
|
||||
|
||||
@GetMapping("/home/findvfeedback")
|
||||
@@ -71,8 +74,7 @@ public class DataController {
|
||||
if (feedBacks!=null){
|
||||
return feedBacks;
|
||||
}
|
||||
new UserException(ResultEnum.EMPTY_DATA);
|
||||
return null;
|
||||
throw new UserException(ResultEnum.EMPTY_DATA);
|
||||
}
|
||||
|
||||
@GetMapping("/home/findvcourse")
|
||||
@@ -81,8 +83,7 @@ public class DataController {
|
||||
if (vCourses!=null){
|
||||
return vCourses;
|
||||
}
|
||||
new UserException(ResultEnum.EMPTY_DATA);
|
||||
return null;
|
||||
throw new UserException(ResultEnum.EMPTY_DATA);
|
||||
}
|
||||
|
||||
@GetMapping("/home/findalluser")
|
||||
@@ -91,8 +92,7 @@ public class DataController {
|
||||
if (users!=null){
|
||||
return users;
|
||||
}
|
||||
new UserException(ResultEnum.EMPTY_DATA);
|
||||
return null;
|
||||
throw new UserException(ResultEnum.EMPTY_DATA);
|
||||
}
|
||||
|
||||
@GetMapping("/home/findallvhomework")
|
||||
@@ -101,8 +101,7 @@ public class DataController {
|
||||
if (vHomeworks!=null){
|
||||
return vHomeworks;
|
||||
}
|
||||
new UserException(ResultEnum.EMPTY_DATA);
|
||||
return null;
|
||||
throw new UserException(ResultEnum.EMPTY_DATA);
|
||||
}
|
||||
|
||||
@GetMapping("/home/findStudentInCourseFile")
|
||||
@@ -112,8 +111,7 @@ public class DataController {
|
||||
if (files!=null){
|
||||
return files;
|
||||
}
|
||||
new UserException(ResultEnum.EMPTY_DATA);
|
||||
return null;
|
||||
throw new UserException(ResultEnum.EMPTY_DATA);
|
||||
}
|
||||
|
||||
@GetMapping("/home/userinfo")
|
||||
@@ -121,4 +119,17 @@ public class DataController {
|
||||
TbUser user= (TbUser)httpServletRequest.getSession().getAttribute(USER_SESSION_KEY);
|
||||
return userService.findUserInfo(user.getColuserid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储密保问题
|
||||
* @param userque
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/home/adduserque")
|
||||
public boolean adduserque(TbUserque userque)throws Exception{
|
||||
log.info(userque.toString());
|
||||
//对密保问题加密存储
|
||||
userque.setAnswer(new BigInteger(CodingUtil.encryptSHA(userque.getAnswer().getBytes())).toString(32));
|
||||
return userService.addUserQue(userque);
|
||||
}
|
||||
}
|
||||
|
||||
23
src/main/java/com/fjy/spring/domain/TbUserque.java
Normal file
23
src/main/java/com/fjy/spring/domain/TbUserque.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.fjy.spring.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class TbUserque {
|
||||
|
||||
@Id
|
||||
@Column(name = "coluserid")
|
||||
private Integer userid;
|
||||
|
||||
@Column(name = "colquestion")
|
||||
private String question;
|
||||
|
||||
@Column(name = "colanswer")
|
||||
private String answer;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.fjy.spring.repository;
|
||||
|
||||
import com.fjy.spring.domain.TbUserque;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
|
||||
public interface TbUserqueRepository extends JpaRepository<TbUserque,Integer> {
|
||||
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.fjy.spring.service;
|
||||
|
||||
import com.fjy.spring.domain.TbUser;
|
||||
import com.fjy.spring.domain.TbUserque;
|
||||
import com.fjy.spring.domain.VUserinfo;
|
||||
import com.fjy.spring.enums.ResultEnum;
|
||||
import com.fjy.spring.exception.UserException;
|
||||
import com.fjy.spring.repository.TbUserRepository;
|
||||
import com.fjy.spring.repository.TbUserqueRepository;
|
||||
import com.fjy.spring.repository.VUserinfoRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -19,6 +21,9 @@ public class UserService {
|
||||
@Autowired
|
||||
private TbUserRepository tbUserRepository;
|
||||
|
||||
@Autowired
|
||||
private TbUserqueRepository userqueRepository;
|
||||
|
||||
@Autowired
|
||||
private VUserinfoRepository vUserinfoRepository;
|
||||
|
||||
@@ -66,4 +71,11 @@ public class UserService {
|
||||
return tbUserRepository.findByColname(name);
|
||||
}
|
||||
|
||||
public boolean addUserQue(TbUserque userque){
|
||||
TbUserque tbUserque = userqueRepository.save(userque);
|
||||
if (tbUserque!=null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user