Commit dfc9ab82 by WeiCong

后台验证码支持集群模式

parent 9c731c0d
...@@ -33,31 +33,32 @@ import java.util.*; ...@@ -33,31 +33,32 @@ import java.util.*;
@Controller @Controller
public class LoginController { public class LoginController {
public static final String ERROR = "error";
private static final Log log = LogFactory.getLog(LoginController.class); private static final Log log = LogFactory.getLog(LoginController.class);
public static final String ERROR="error";
@Autowired @Autowired
private NoUiVersion noUiVersion; private NoUiVersion noUiVersion;
@ResponseBody @ResponseBody
@RequestMapping(value = "/login", method = RequestMethod.POST) @RequestMapping(value = "/login", method = RequestMethod.POST)
public Object login(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) { public Object login(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
// TODO??? NoUiContext context=null;
//System.out.println(dataMap); try {
NoUiRequest noUiRequest = new NoUiRequest(request, "", dataMap); NoUiRequest noUiRequest = new NoUiRequest(request, "", dataMap);
Map<String, Object> map = new HashMap<>();//此map会存储返回错误码 Map<String, Object> map = new HashMap<>();//此map会存储返回错误码
String userId = noUiRequest.getDataMap().get(Constants.USERNAME).toString(); String userId = noUiRequest.getDataMap().get(Constants.USERNAME).toString();
String password = noUiRequest.getDataMap().get(Constants.PASSWORD).toString(); String password = noUiRequest.getDataMap().get(Constants.PASSWORD).toString();
String dncode = noUiRequest.getDataMap().get(Constants.DNCODE)==null?null:noUiRequest.getDataMap().get(Constants.DNCODE).toString(); String dncode = noUiRequest.getDataMap().get(Constants.DNCODE) == null ? null : noUiRequest.getDataMap().get(Constants.DNCODE).toString();
String sendcode = noUiRequest.getDataMap().get(Constants.SENDCODE)==null?null:noUiRequest.getDataMap().get(Constants.SENDCODE).toString(); String sendcode = noUiRequest.getDataMap().get(Constants.SENDCODE) == null ? null : noUiRequest.getDataMap().get(Constants.SENDCODE).toString();
String verifycode = request.getSession().getAttribute(Constants.VERIFYCODE)==null?null:request.getSession().getAttribute(Constants.VERIFYCODE).toString(); // String verifycode = request.getSession().getAttribute(Constants.VERIFYCODE)==null?null:request.getSession().getAttribute(Constants.VERIFYCODE).toString();
Object verifycodeobj = RedisUtil.get(request.getRequestedSessionId());
String verifycode = verifycodeobj == null ? null : verifycodeobj.toString();
map.put("j_username", userId); map.put("j_username", userId);
map.put("j_password", password); map.put("j_password", password);
map.put("j_dncode", dncode); map.put("j_dncode", dncode);
map.put("j_sendcode", sendcode); map.put("j_sendcode", sendcode);
map.put("j_verifycode", verifycode); map.put("j_verifycode", verifycode);
NoUiContext context = NoUiContextManager.createNoUiContext(noUiRequest); context = NoUiContextManager.createNoUiContext(noUiRequest);
try {
if (context.getSession().login(map)) { if (context.getSession().login(map)) {
JwtLogin login = new JwtLogin(); JwtLogin login = new JwtLogin();
...@@ -84,18 +85,18 @@ public class LoginController { ...@@ -84,18 +85,18 @@ public class LoginController {
context.getSession().chain(true, "office"); context.getSession().chain(true, "office");
byte[] sysmodBytes = NoUiPresentationUtil.sysmodToBytes(context); byte[] sysmodBytes = NoUiPresentationUtil.sysmodToBytes(context);
// redis中存储用户相关信息 // redis中存储用户相关信息
RedisLoginInfo redisLoginInfo = new RedisLoginInfo(userId, token, NumericUtil.sessionTimeOut(), sysmodBytes,noUiRequest.getTerminalType()); RedisLoginInfo redisLoginInfo = new RedisLoginInfo(userId, token, NumericUtil.sessionTimeOut(), sysmodBytes, noUiRequest.getTerminalType());
RedisUtil.set(StringUtil.userUniqueId(noUiRequest), redisLoginInfo); RedisUtil.set(StringUtil.userUniqueId(noUiRequest), redisLoginInfo);
//解决初次登陆,超期限登陆 //解决初次登陆,超期限登陆
final Object o = map.get(ERROR); final Object o = map.get(ERROR);
if (Objects.isNull(o)) { if (Objects.isNull(o)) {
return ResultUtil.result(ErrorCodes.SUCCESS, ErrorCodes.SUCCESS_INFO, retDatamap, noUiVersion.getVersion()); return ResultUtil.result(ErrorCodes.SUCCESS, ErrorCodes.SUCCESS_INFO, retDatamap, noUiVersion.getVersion());
}else { } else {
ErrorCode errorCode = (ErrorCode) o; ErrorCode errorCode = (ErrorCode) o;
return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), retDatamap, noUiVersion.getVersion()); return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), retDatamap, noUiVersion.getVersion());
} }
}else { } else {
final ErrorCode errorCode = (ErrorCode) map.get(ERROR); final ErrorCode errorCode = (ErrorCode) map.get(ERROR);
return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), null, noUiVersion.getVersion()); return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), null, noUiVersion.getVersion());
} }
...@@ -104,10 +105,8 @@ public class LoginController { ...@@ -104,10 +105,8 @@ public class LoginController {
//throw new NoUiException("Login command error", e); //throw new NoUiException("Login command error", e);
// return ResultUtil.result(ErrorCodes.ERROR, "login failed with exception", null); // return ResultUtil.result(ErrorCodes.ERROR, "login failed with exception", null);
return ResultUtil.result(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage(), null, noUiVersion.getVersion()); return ResultUtil.result(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage(), null, noUiVersion.getVersion());
} } finally {
finally{ if (context != null) {
if (context != null)
{
//context.getSupport().disconnect(); //context.getSupport().disconnect();
context.dispose(); context.dispose();
} }
...@@ -147,7 +146,6 @@ public class LoginController { ...@@ -147,7 +146,6 @@ public class LoginController {
public Object logout(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) { public Object logout(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
return "ok"; return "ok";
} }
......
...@@ -10,15 +10,14 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -10,15 +10,14 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.sss.presentation.noui.api.response.ErrorCodes; import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.NoUiVersion; import org.sss.presentation.noui.api.response.NoUiVersion;
import org.sss.presentation.noui.api.response.ResultUtil; import org.sss.presentation.noui.api.response.ResultUtil;
import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.util.NoUiUtils; import org.sss.presentation.noui.util.NoUiUtils;
import org.sss.presentation.noui.util.RedisUtil;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
...@@ -67,9 +66,11 @@ public class VerifyCodeCreateController { ...@@ -67,9 +66,11 @@ public class VerifyCodeCreateController {
g.drawString(code, (i * 18) + 10, 30); g.drawString(code, (i * 18) + 10, 30);
codes.append(code); codes.append(code);
} }
request.getSession().setAttribute(Constants.VERIFYCODE, codes.toString()); RedisUtil.set(request.getRequestedSessionId(), codes.toString());
// request.getSession().setAttribute(Constants.VERIFYCODE, codes.toString());
ImageIO.write(bi, "JPG", response.getOutputStream()); ImageIO.write(bi, "JPG", response.getOutputStream());
} catch (IOException e) { } catch (Exception e) {
log.error("绘制登陆验证码异常", e); log.error("绘制登陆验证码异常", e);
} finally { } finally {
if(g!=null){ if(g!=null){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment