|
@@ -1,24 +1,15 @@
|
|
package io.renren.modules.sys.controller;
|
|
package io.renren.modules.sys.controller;
|
|
|
|
|
|
-import com.google.code.kaptcha.Constants;
|
|
|
|
-import com.google.code.kaptcha.Producer;
|
|
|
|
import io.renren.common.utils.R;
|
|
import io.renren.common.utils.R;
|
|
-import io.renren.common.utils.ShiroUtils;
|
|
|
|
import io.renren.modules.sys.entity.SysUserEntity;
|
|
import io.renren.modules.sys.entity.SysUserEntity;
|
|
import io.renren.modules.sys.service.SysUserService;
|
|
import io.renren.modules.sys.service.SysUserService;
|
|
import io.renren.modules.sys.service.SysUserTokenService;
|
|
import io.renren.modules.sys.service.SysUserTokenService;
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.shiro.crypto.hash.Sha256Hash;
|
|
import org.apache.shiro.crypto.hash.Sha256Hash;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-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;
|
|
import java.io.IOException;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -32,39 +23,15 @@ import java.util.Map;
|
|
@RestController
|
|
@RestController
|
|
public class SysLoginController extends AbstractController {
|
|
public class SysLoginController extends AbstractController {
|
|
@Autowired
|
|
@Autowired
|
|
- private Producer producer;
|
|
|
|
- @Autowired
|
|
|
|
private SysUserService sysUserService;
|
|
private SysUserService sysUserService;
|
|
@Autowired
|
|
@Autowired
|
|
private SysUserTokenService sysUserTokenService;
|
|
private SysUserTokenService sysUserTokenService;
|
|
|
|
|
|
- @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);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 登录
|
|
* 登录
|
|
*/
|
|
*/
|
|
@RequestMapping(value = "/sys/login", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/sys/login", method = RequestMethod.POST)
|
|
- public Map<String, Object> login(String username, String password, String captcha)throws IOException {
|
|
|
|
- String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
|
|
|
|
- if(!captcha.equalsIgnoreCase(kaptcha)){
|
|
|
|
- return R.error("验证码不正确");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ public Map<String, Object> login(String username, String password)throws IOException {
|
|
//用户信息
|
|
//用户信息
|
|
SysUserEntity user = sysUserService.queryByUserName(username);
|
|
SysUserEntity user = sysUserService.queryByUserName(username);
|
|
|
|
|