zouxuan 5 years ago
parent
commit
6af62c1a32

+ 5 - 0
mec-web/pom.xml

@@ -51,6 +51,11 @@
 			<groupId>com.ym</groupId>
 			<groupId>com.ym</groupId>
 			<artifactId>mec-biz</artifactId>
 			<artifactId>mec-biz</artifactId>
 		</dependency>
 		</dependency>
+		<dependency>
+			<groupId>com.github.penggle</groupId>
+			<artifactId>kaptcha</artifactId>
+			<version>2.3.2</version>
+		</dependency>
 
 
 	</dependencies>
 	</dependencies>
 	<build>
 	<build>

+ 66 - 0
mec-web/src/main/java/com/ym/mec/web/controller/SmsCodeController.java

@@ -1,5 +1,8 @@
 package com.ym.mec.web.controller;
 package com.ym.mec.web.controller;
 
 
+import com.google.code.kaptcha.Constants;
+import com.google.code.kaptcha.Producer;
+import com.google.code.kaptcha.servlet.KaptchaServlet;
 import com.ym.mec.biz.service.SmsCodeService;
 import com.ym.mec.biz.service.SmsCodeService;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.security.SecurityConstants;
 import com.ym.mec.common.security.SecurityConstants;
@@ -9,10 +12,18 @@ import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
 
 
+import javax.imageio.ImageIO;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
+import java.util.concurrent.TimeUnit;
+
 @RestController
 @RestController
 @RequestMapping("code")
 @RequestMapping("code")
 @Api(tags = "验证码服务")
 @Api(tags = "验证码服务")
@@ -20,6 +31,10 @@ public class SmsCodeController extends BaseController {
 
 
     @Autowired
     @Autowired
     private SmsCodeService smsCodeService;
     private SmsCodeService smsCodeService;
+    @Autowired
+    private Producer captchaProducer;
+    @Autowired
+    private RedisTemplate<String,String> redisTemplate;
 
 
     @ApiOperation(value = "发送登录短信验证码")
     @ApiOperation(value = "发送登录短信验证码")
     @ApiImplicitParam(name = "mobile", value = "手机号", required = true, dataType = "String")
     @ApiImplicitParam(name = "mobile", value = "手机号", required = true, dataType = "String")
@@ -42,4 +57,55 @@ public class SmsCodeController extends BaseController {
         }
         }
         return failed();
         return failed();
     }
     }
+
+    @PostMapping(value = "/verifyLoginImage")
+    @ApiOperation("校验登录图形验证码")
+    @ApiImplicitParams({ @ApiImplicitParam(name = "phone", value = "手机号", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "code", value = "验证码", required = true, dataType = "String") })
+    public Object verifyImageCode(String phone,String code){
+        if(StringUtils.isEmpty(phone) || StringUtils.isEmpty(code)){
+            return failed(SecurityConstants.PARAM_VERIFY_EXCEPTION);
+        }
+        String redisKey = Constants.KAPTCHA_SESSION_KEY + phone;
+        if(redisTemplate.hasKey(redisKey)){
+            if(StringUtils.equalsIgnoreCase(redisTemplate.opsForValue().get(redisKey),code)){
+                return succeed();
+            }
+        }
+        return failed(SecurityConstants.VERIFY_FAILURE);
+    }
+
+    @GetMapping(value = "/getLoginImage")
+    @ApiOperation("获取登录图片验证码")
+    @ApiImplicitParam(name = "phone", value = "手机号", required = true, dataType = "String")
+    public void getKaptchaImage(HttpServletResponse response, String phone) throws Exception {
+        if(StringUtils.isEmpty(phone)){
+            return;
+        }
+        response.setDateHeader("Expires", 0);
+
+        // Set standard HTTP/1.1 no-cache headers.
+        response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
+        // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
+        response.addHeader("Cache-Control", "post-check=0, pre-check=0");
+        // Set standard HTTP/1.0 no-cache header.
+        response.setHeader("Pragma", "no-cache");
+        // return a jpeg
+        response.setContentType("image/jpeg");
+        // create the text for the image
+        String capText = captchaProducer.createText();
+
+        redisTemplate.opsForValue().set(Constants.KAPTCHA_SESSION_KEY + phone,capText,3, TimeUnit.MINUTES);
+        // create the image with the text
+        BufferedImage bi = captchaProducer.createImage(capText);
+        KaptchaServlet kaptchaServlet = new KaptchaServlet();
+        kaptchaServlet.init();
+        ServletOutputStream out = response.getOutputStream();
+        try {
+            ImageIO.write(bi, "jpg", out);
+            out.flush();
+        } finally {
+            out.close();
+        }
+    }
 }
 }

+ 5 - 0
mec-web/src/main/java/com/ym/mec/web/controller/education/ImController.java

@@ -8,6 +8,7 @@ import com.ym.mec.common.controller.BaseController;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
@@ -26,6 +27,7 @@ public class ImController extends BaseController {
 
 
     @ApiOperation(value = "获取教务所有聊天群组")
     @ApiOperation(value = "获取教务所有聊天群组")
     @GetMapping("/queryEmployeeGroups")
     @GetMapping("/queryEmployeeGroups")
+    @PreAuthorize("@pcs.hasPermissions('im/queryEmployeeGroups')")
     public Object queryEmployeeGroups(String search){
     public Object queryEmployeeGroups(String search){
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         if(sysUser == null){
         if(sysUser == null){
@@ -36,6 +38,7 @@ public class ImController extends BaseController {
 
 
     @ApiOperation(value = "获取当前教务通讯录列表")
     @ApiOperation(value = "获取当前教务通讯录列表")
     @GetMapping("/queryGroupStudents")
     @GetMapping("/queryGroupStudents")
+    @PreAuthorize("@pcs.hasPermissions('im/queryGroupStudents')")
     public Object queryGroupStudents(String search){
     public Object queryGroupStudents(String search){
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         if(sysUser == null){
         if(sysUser == null){
@@ -46,6 +49,7 @@ public class ImController extends BaseController {
 
 
     @ApiOperation(value = "根据群编号,获取群组基本信息")
     @ApiOperation(value = "根据群编号,获取群组基本信息")
     @GetMapping("/findGroupById")
     @GetMapping("/findGroupById")
+    @PreAuthorize("@pcs.hasPermissions('im/findGroupById')")
     public Object findGroupById(Integer groupId){
     public Object findGroupById(Integer groupId){
         if(null == groupId){
         if(null == groupId){
             return failed("参数校验错误");
             return failed("参数校验错误");
@@ -55,6 +59,7 @@ public class ImController extends BaseController {
 
 
     @ApiOperation(value = "根据群编号,获取群组所有成员基本信息")
     @ApiOperation(value = "根据群编号,获取群组所有成员基本信息")
     @GetMapping("/findGroupUsers")
     @GetMapping("/findGroupUsers")
+    @PreAuthorize("@pcs.hasPermissions('im/findGroupUsers')")
     public Object findGroupUsers(Integer groupId) {
     public Object findGroupUsers(Integer groupId) {
         if (groupId == null) {
         if (groupId == null) {
             return failed("参数校验错误");
             return failed("参数校验错误");