Commit dfc9ab82 by WeiCong

后台验证码支持集群模式

parent 9c731c0d
......@@ -33,31 +33,32 @@ import java.util.*;
@Controller
public class LoginController {
public static final String ERROR = "error";
private static final Log log = LogFactory.getLog(LoginController.class);
public static final String ERROR="error";
@Autowired
private NoUiVersion noUiVersion;
@ResponseBody
@RequestMapping(value = "/login", method = RequestMethod.POST)
public Object login(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
// TODO???
//System.out.println(dataMap);
NoUiContext context=null;
try {
NoUiRequest noUiRequest = new NoUiRequest(request, "", dataMap);
Map<String, Object> map = new HashMap<>();//此map会存储返回错误码
String userId = noUiRequest.getDataMap().get(Constants.USERNAME).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 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 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 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_password", password);
map.put("j_dncode", dncode);
map.put("j_sendcode", sendcode);
map.put("j_verifycode", verifycode);
NoUiContext context = NoUiContextManager.createNoUiContext(noUiRequest);
try {
context = NoUiContextManager.createNoUiContext(noUiRequest);
if (context.getSession().login(map)) {
JwtLogin login = new JwtLogin();
......@@ -84,18 +85,18 @@ public class LoginController {
context.getSession().chain(true, "office");
byte[] sysmodBytes = NoUiPresentationUtil.sysmodToBytes(context);
// 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);
//解决初次登陆,超期限登陆
final Object o = map.get(ERROR);
if (Objects.isNull(o)) {
return ResultUtil.result(ErrorCodes.SUCCESS, ErrorCodes.SUCCESS_INFO, retDatamap, noUiVersion.getVersion());
}else {
} else {
ErrorCode errorCode = (ErrorCode) o;
return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), retDatamap, noUiVersion.getVersion());
}
}else {
} else {
final ErrorCode errorCode = (ErrorCode) map.get(ERROR);
return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), null, noUiVersion.getVersion());
}
......@@ -104,10 +105,8 @@ public class LoginController {
//throw new NoUiException("Login command error", e);
// return ResultUtil.result(ErrorCodes.ERROR, "login failed with exception", null);
return ResultUtil.result(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage(), null, noUiVersion.getVersion());
}
finally{
if (context != null)
{
} finally {
if (context != null) {
//context.getSupport().disconnect();
context.dispose();
}
......@@ -147,7 +146,6 @@ public class LoginController {
public Object logout(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
return "ok";
}
......
......@@ -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.NoUiVersion;
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.RedisUtil;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
......@@ -67,9 +66,11 @@ public class VerifyCodeCreateController {
g.drawString(code, (i * 18) + 10, 30);
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());
} catch (IOException e) {
} catch (Exception e) {
log.error("绘制登陆验证码异常", e);
} finally {
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