Skip to content

Commit

Permalink
HRManagement登录验证码,个人资料信息修改开发完成。
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexYY0 committed Mar 4, 2020
1 parent fff265d commit 2020c5f
Show file tree
Hide file tree
Showing 19 changed files with 1,382 additions and 104 deletions.
145 changes: 61 additions & 84 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.security.web.access.intercept.FilterSecurityInterceptor;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
Expand All @@ -42,6 +43,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
CustomFilterInvocationSecurityMetadataSource customFilterInvocationSecurityMetadataSource;
@Autowired
CustomUrlDecisionManager customUrlDecisionManager;
@Autowired
VerificationCodeFilter verificationCodeFilter;

@Bean
PasswordEncoder passwordEncoder() {
Expand All @@ -55,11 +58,12 @@ protected void configure(AuthenticationManagerBuilder auth) throws Exception {

@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/login","/css/**","/js/**","/index.html","/img/**","/fonts/**","/favicon.ico");
web.ignoring().antMatchers("/login","/css/**","/js/**","/index.html","/img/**","/fonts/**","/favicon.ico","/verifyCode");
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http.addFilterBefore(verificationCodeFilter, UsernamePasswordAuthenticationFilter.class);
http.authorizeRequests()
.withObjectPostProcessor(new ObjectPostProcessor<FilterSecurityInterceptor>() {
@Override
Expand Down
114 changes: 114 additions & 0 deletions src/main/java/com/emperorws/hrmanagement/config/VerificationCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.emperorws.hrmanagement.config;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;

/**
* @Author: EmperorWS
* @Date: 2020/3/4 15:59
* @Description: 生成验证码的工具类
**/
public class VerificationCode {

private int width = 100;// 生成验证码图片的宽度
private int height = 30;// 生成验证码图片的高度
private String[] fontNames = { "宋体", "楷体", "隶书", "微软雅黑" };
private Color bgColor = new Color(255, 255, 255);// 定义验证码图片的背景颜色为白色
private Random random = new Random();
private String codes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
private String text;// 记录随机字符串

/**
* 获取一个随意颜色
*
* @return
*/
private Color randomColor() {
int red = random.nextInt(150);
int green = random.nextInt(150);
int blue = random.nextInt(150);
return new Color(red, green, blue);
}

/**
* 获取一个随机字体
*
* @return
*/
private Font randomFont() {
String name = fontNames[random.nextInt(fontNames.length)];
int style = random.nextInt(4);
int size = random.nextInt(5) + 24;
return new Font(name, style, size);
}

/**
* 获取一个随机字符
*
* @return
*/
private char randomChar() {
return codes.charAt(random.nextInt(codes.length()));
}

/**
* 创建一个空白的BufferedImage对象
*
* @return
*/
private BufferedImage createImage() {
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D) image.getGraphics();
g2.setColor(bgColor);// 设置验证码图片的背景颜色
g2.fillRect(0, 0, width, height);
return image;
}

public BufferedImage getImage() {
BufferedImage image = createImage();
Graphics2D g2 = (Graphics2D) image.getGraphics();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < 4; i++) {
String s = randomChar() + "";
sb.append(s);
g2.setColor(randomColor());
g2.setFont(randomFont());
float x = i * width * 1.0f / 4;
g2.drawString(s, x, height - 8);
}
this.text = sb.toString();
drawLine(image);
return image;
}

/**
* 绘制干扰线
*
* @param image
*/
private void drawLine(BufferedImage image) {
Graphics2D g2 = (Graphics2D) image.getGraphics();
int num = 5;
for (int i = 0; i < num; i++) {
int x1 = random.nextInt(width);
int y1 = random.nextInt(height);
int x2 = random.nextInt(width);
int y2 = random.nextInt(height);
g2.setColor(randomColor());
g2.setStroke(new BasicStroke(1.5f));
g2.drawLine(x1, y1, x2, y2);
}
}

public String getText() {
return text;
}

public static void output(BufferedImage image, OutputStream out) throws IOException {
ImageIO.write(image, "JPEG", out);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.emperorws.hrmanagement.config;

import com.emperorws.hrmanagement.model.RespBean;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
* @Author: EmperorWS
* @Date: 2020/3/4 16:29
* @Description: 登陆前校验验证码
**/
@Component
public class VerificationCodeFilter extends GenericFilter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) servletRequest;
HttpServletResponse resp = (HttpServletResponse) servletResponse;
if ("POST".equals(req.getMethod()) && "/doLogin".equals(req.getServletPath())) {
//登录请求
String code = req.getParameter("code");
String verify_code = (String) req.getSession().getAttribute("verify_code");
if (code == null || verify_code == null || "".equals(code) || !verify_code.toLowerCase().equals(code.toLowerCase())) {
//验证码不正确
resp.setContentType("application/json;charset=utf-8");
PrintWriter out = resp.getWriter();
out.write(new ObjectMapper().writeValueAsString(RespBean.error("验证码错误")));
out.flush();
out.close();
return;
} else {
filterChain.doFilter(req, resp);
}
} else {
filterChain.doFilter(req, resp);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.emperorws.hrmanagement.controller;

import com.emperorws.hrmanagement.config.VerificationCode;
import com.emperorws.hrmanagement.model.RespBean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
* @Author: EmperorWS
* @Date: 2020/3/4 16:05
* @Description: 用户登录控制层
**/
@RestController
public class LoginController {
@GetMapping("/login")
public RespBean login() {
return RespBean.error("尚未登录,请登录!");
}

@GetMapping("/verifyCode")
public void verifyCode(HttpSession session, HttpServletResponse resp) throws IOException {
VerificationCode code = new VerificationCode();
BufferedImage image = code.getImage();
String text = code.getText();
session.setAttribute("verify_code", text);
VerificationCode.output(image,resp.getOutputStream());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.emperorws.hrmanagement.controller;

import com.emperorws.hrmanagement.model.RespBean;
import com.emperorws.hrmanagement.model.User;
import com.emperorws.hrmanagement.service.UserService;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
* @Author: EmperorWS
* @Date: 2020/3/4 12:49
* @Description: 员工修改个人信息控制层
**/
@RestController
@RequestMapping("/user")
public class UserInfoController {
@Autowired
UserService userService;

@GetMapping("/info")
public User getCurrentUser(Authentication authentication) {
return ((User) authentication.getPrincipal());
}

@PutMapping("/info")
public RespBean updateHr(@RequestBody User user, Authentication authentication) {
if (userService.updateUser(user) == 1) {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(user, authentication.getCredentials(), authentication.getAuthorities()));
return RespBean.ok("更新成功!");
}
return RespBean.error("更新失败!");
}

@PutMapping("/password")
public RespBean updateUserPassword(@RequestBody Map<String, Object> info) {
String oldpassword = (String) info.get("oldpassword");
String password = (String) info.get("password");
Integer userid = (Integer) info.get("userid");
if (userService.updateUserPassword(oldpassword, password, userid)) {
return RespBean.ok("更新成功!");
}
return RespBean.error("更新失败!");
}

@GetMapping("/check/username/{username}")
public Boolean getUserByUsername(@PathVariable String username){
return userService.getUserByUsername(username);
}

@GetMapping("/check/password")
public Boolean getUserByPassword(String password,Integer userid){
return userService.getUserByPassword(password,userid);
}

@GetMapping("/token")
public String getToken(){
String accessKey = "HHpVv8wj2T-IGv8JrjZFArdSUy6QGMxuo10k7Hnd";
String secretKey = "qoAkFOku7m6wouAwum45Ef-SiCTrOarj5QTgZQ3y";
String bucket = "emperorws";
Auth auth = Auth.create(accessKey, secretKey);
String upToken = auth.uploadToken(bucket);
return upToken;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @Author: EmperorWS
* @Date: 2020/2/22 16:22
* @Description:
* @Description: 员工合同管理控制层
**/
@RestController
@RequestMapping("/employee/basic/contractinfo")
Expand All @@ -33,14 +33,4 @@ public RespBean addContractinfo(@RequestBody Contractinfo contractinfo) {
}
return RespBean.error("添加失败!");
}

@GetMapping("/token")
public String getToken(){
String accessKey = "HHpVv8wj2T-IGv8JrjZFArdSUy6QGMxuo10k7Hnd";
String secretKey = "qoAkFOku7m6wouAwum45Ef-SiCTrOarj5QTgZQ3y";
String bucket = "emperorws";
Auth auth = Auth.create(accessKey, secretKey);
String upToken = auth.uploadToken(bucket);
return upToken;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.emperorws.hrmanagement.controller.salary;

import com.emperorws.hrmanagement.model.Employee;
import com.emperorws.hrmanagement.model.RespPageBean;
import com.emperorws.hrmanagement.model.Salaryinfo;
import com.emperorws.hrmanagement.service.SalaryinfoService;
import com.emperorws.hrmanagement.utils.SalInfoPOIUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
* @Author: EmperorWS
* @Date: 2020/3/3 17:15
* @Description: 员工历史薪资信息控制层
**/
@RestController
@RequestMapping("/salary/information")
public class SalaryinfoController {
@Autowired
SalaryinfoService salaryinfoService;

@GetMapping("/")
public RespPageBean getSalaryinfoByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size, Employee employee, Date[] payoffdata) {
return salaryinfoService.getSalaryinfoByPage(page, size, employee, payoffdata);
}

@PostMapping("/export")
public ResponseEntity<byte[]> exportData(@RequestBody List<Salaryinfo> list) {
return SalInfoPOIUtils.salaryinfo2Excel(list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ public RespBean deleteUserById(@PathVariable Integer userid) {
return RespBean.error("删除失败!");
}

@GetMapping("/find/{username}")
public Boolean getUserByUsername(@PathVariable String username){
return userService.getUserByUsername(username);
}

@GetMapping("/find")
public Boolean getUserByWorkid(Integer workid){
return userService.getUserByWorkid(workid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<association property="welfare" javaType="com.emperorws.hrmanagement.model.Welfare">
<id column="welid" property="welid"/>
<result column="welname" property="welname"/>
<result column="traffic" property="traffic"/>
<result column="catering" property="catering"/>
<result column="communication" property="communication"/>
<result column="bonus" property="bonus"/>
<result column="other" property="other"/>
</association>
<association property="speadd1" javaType="com.emperorws.hrmanagement.model.Speadd">
<id column="sadid1" property="sadid"/>
Expand Down Expand Up @@ -67,7 +72,8 @@
select * from employeeSalary where workId=#{workid}
</select>
<select id="getEmployeesalaryByPage" resultMap="AllEmployeesalaryInfo">
SELECT e.*,d.depName as depname,emp.empName as empname,w.welName as welname,s1.`sadName` as sadname1,s2.`sadName` as sadname2,s3.`sadName` as sadname3,s4.`sadName` as sadname4,s5.`sadName` as sadname5,s6.`sadName` as sadname6
SELECT e.*,d.depName as depname,emp.empName as empname,w.welName as welname,w.traffic as traffic,w.catering as catering,w.communication as communication,w.bonus as bonus,w.other as other,
s1.`sadName` as sadname1,s2.`sadName` as sadname2,s3.`sadName` as sadname3,s4.`sadName` as sadname4,s5.`sadName` as sadname5,s6.`sadName` as sadname6
FROM employee emp,department d,employeeSalary e,welfare w,specialAdditionalDeduction s1,specialAdditionalDeduction s2,specialAdditionalDeduction s3,specialAdditionalDeduction s4,specialAdditionalDeduction s5,specialAdditionalDeduction s6
WHERE e.welId=w.welId
AND e.childEdu=s1.`sadId`
Expand Down
Loading

0 comments on commit 2020c5f

Please sign in to comment.