|
|
@@ -1,6 +1,9 @@ |
|
|
package com.simple.controller; |
|
|
package com.simple.controller; |
|
|
|
|
|
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
|
|
import com.google.code.kaptcha.Constants; |
|
|
|
|
|
import com.google.code.kaptcha.Producer; |
|
|
|
|
|
import com.simple.common.ErrorCode; |
|
|
import com.simple.common.ResultData; |
|
|
import com.simple.common.ResultData; |
|
|
import com.simple.domain.po.MallRolePermission; |
|
|
import com.simple.domain.po.MallRolePermission; |
|
|
import com.simple.domain.po.MallUserInfo; |
|
|
import com.simple.domain.po.MallUserInfo; |
|
|
@@ -8,8 +11,10 @@ import com.simple.domain.po.MallUserRole; |
|
|
import com.simple.service.MallRolePermissionService; |
|
|
import com.simple.service.MallRolePermissionService; |
|
|
import com.simple.service.MallUserRoleService; |
|
|
import com.simple.service.MallUserRoleService; |
|
|
import com.simple.shiro.UserSession; |
|
|
import com.simple.shiro.UserSession; |
|
|
|
|
|
import com.simple.utils.ShiroUtils; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
import org.apache.shiro.SecurityUtils; |
|
|
import org.apache.shiro.SecurityUtils; |
|
|
import org.apache.shiro.authc.UsernamePasswordToken; |
|
|
import org.apache.shiro.authc.UsernamePasswordToken; |
|
|
import org.apache.shiro.subject.Subject; |
|
|
import org.apache.shiro.subject.Subject; |
|
|
@@ -17,10 +22,14 @@ import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO; |
|
|
|
|
|
import javax.servlet.ServletException; |
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RestController |
|
|
@RestController |
|
|
@@ -28,15 +37,43 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
public class HomeController { |
|
|
public class HomeController { |
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private Producer producer; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private MallUserRoleService mallUserRoleService; |
|
|
private MallUserRoleService mallUserRoleService; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private MallRolePermissionService mallRolePermissionService; |
|
|
private MallRolePermissionService mallRolePermissionService; |
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/captcha.jpg") |
|
|
|
|
|
public void captcha(HttpServletResponse response)throws ServletException, IOException { |
|
|
|
|
|
response.setHeader("Cache-Control", "no-store, no-cache"); |
|
|
|
|
|
response.setContentType("image/jpeg"); |
|
|
|
|
|
|
|
|
|
|
|
//生成文字验证码 |
|
|
|
|
|
String text = producer.createText(); |
|
|
|
|
|
//生成图片验证码 |
|
|
|
|
|
BufferedImage image = producer.createImage(text); |
|
|
|
|
|
//保存到shiro session |
|
|
|
|
|
ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text); |
|
|
|
|
|
|
|
|
|
|
|
ServletOutputStream out = response.getOutputStream(); |
|
|
|
|
|
ImageIO.write(image, "jpg", out); |
|
|
|
|
|
IOUtils.closeQuietly(out); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ApiOperation("登录") |
|
|
@ApiOperation("登录") |
|
|
@PostMapping("/doLogin") |
|
|
@PostMapping("/doLogin") |
|
|
public ResultData login(@RequestBody MallUserInfo user) { |
|
|
|
|
|
|
|
|
public ResultData login(@RequestBody MallUserInfo user, String captcha) { |
|
|
|
|
|
if (captcha != null) { |
|
|
|
|
|
String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY); |
|
|
|
|
|
if(!captcha.equalsIgnoreCase(kaptcha)){ |
|
|
|
|
|
return new ResultData(ErrorCode.KAPCHA_NOT_EQUAL); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
ResultData data = new ResultData(); |
|
|
ResultData data = new ResultData(); |
|
|
if (StringUtils.isEmpty(user.getUsername()) || StringUtils.isEmpty(user.getPassword())) { |
|
|
if (StringUtils.isEmpty(user.getUsername()) || StringUtils.isEmpty(user.getPassword())) { |
|
|
// throw new SystemException(ErrorCode.LOGIN_USER_OR_PWD_ERROR); |
|
|
// throw new SystemException(ErrorCode.LOGIN_USER_OR_PWD_ERROR); |
|
|
|