From 7a3186eba5d2bf076b364a27883d931bf9b2bd22 Mon Sep 17 00:00:00 2001 From: zhangyulong Date: Tue, 6 Sep 2022 17:42:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E4=B8=BA=E7=9B=B4=E6=8E=A5=E6=9F=A5=E5=BA=93=E3=80=81?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=BF=94=E5=9B=9E=E5=A2=9E=E5=8A=A0=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=94=A8=E6=88=B7=E7=AD=89=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smtweb/system/bpm/web/login/AuthService.java | 14 ++++- .../cc/smtweb/system/bpm/web/login/LoginAckVO.java | 1 + .../smtweb/system/bpm/web/login/LoginHelper.java | 71 +++++++++++++++++++--- 3 files changed, 76 insertions(+), 10 deletions(-) diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java index 68e8a86..e7bc3c7 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java @@ -47,9 +47,17 @@ public class AuthService { @SwPerm(SwPerm.NONE) public R login(@SwBody LoginVO loginPO) { SwMap data = new SwMap(); + User user = null; UserSession userSession = null; try { - userSession = LoginHelper.login(loginPO); + if ("admin".equals(loginPO.getUsername())) { + userSession = new UserSession(1); +// user=new User(); +// return new UserSession(1); + }else{ + user= LoginHelper.login(loginPO); + userSession=new UserSession(user.getId()); + } } catch (BizException e) { data.put("isOk", false); data.put("msg", e.getMessage()); @@ -60,7 +68,7 @@ public class AuthService { return R.success(data); } userSession.setSiteId(1); - User user = UserCache.getInstance().get(userSession.getUserId()); +// UserCache.getInstance().get(userSession.getUserId()); if (user == null) { if (1 != userSession.getUserId()) { data.put("isOk", false); @@ -79,7 +87,7 @@ public class AuthService { loginAckVO.setAvatar(""); loginAckVO.setDesc(user.getSign()); loginAckVO.setToken(sessionManager.login(userSession)); - + loginAckVO.setUserLevel(user.getLevel()+""); data.put("user", loginAckVO); data.put("token", loginAckVO.getToken()); data.put("isOk", true); diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginAckVO.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginAckVO.java index 90908c3..bddd953 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginAckVO.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginAckVO.java @@ -11,4 +11,5 @@ public class LoginAckVO { private String avatar; private String desc; private String token; + private String userLevel; //102100内部用户/102101外部用户/102102公众用户 } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java index b304517..6f481ac 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java @@ -1,8 +1,10 @@ package cc.smtweb.system.bpm.web.login; +import cc.smtweb.framework.core.annotation.SwParam; import cc.smtweb.framework.core.cache.redis.RedisManager; import cc.smtweb.framework.core.common.SwConsts; import cc.smtweb.framework.core.common.SwEnum; +import cc.smtweb.framework.core.db.DbEngine; import cc.smtweb.framework.core.exception.BizException; import cc.smtweb.framework.core.session.UserSession; import cc.smtweb.system.bpm.web.sys.user.user.User; @@ -10,6 +12,8 @@ import cc.smtweb.system.bpm.web.sys.user.user.UserCache; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; +import java.util.List; + /** * Created with IntelliJ IDEA. * User: AKhh @@ -20,7 +24,7 @@ public class LoginHelper { private static final String PWD_SALT = "goodpj"; - public static UserSession login(LoginVO loginPO) { + public static User login(LoginVO loginPO) { String key = loginPO.getUuid() + "_" + SwConsts.LOGIN_VERIFY_CODE; //先提取验证码 String verifyCode = RedisManager.getInstance().get(key, String.class); @@ -30,9 +34,7 @@ public class LoginHelper { throw new BizException("账号不能为空"); } - if ("admin".equals(loginPO.getUsername())) { - return new UserSession(1); - } + if (StringUtils.isBlank(loginPO.getPassword())) { throw new BizException("密码不能为空"); @@ -46,10 +48,16 @@ public class LoginHelper { throw new BizException("验证码错误"); } - User user = UserCache.getInstance().getByKey(loginPO.getUsername()); - if (user == null) { + //查询数据库 + List userObjList = DbEngine.getInstance().findDao(User.ENTITY_NAME).queryWhere(" sur_code=? or sur_tel=?", loginPO.getUsername(), loginPO.getUsername()); +// User user = UserCache.getInstance().getByKey(loginPO.getUsername()); + if(null == userObjList || userObjList.size()<=0){ throw new BizException("账号或者密码出错"); } + User user =userObjList.get(0); +// if (user == null) { +// throw new BizException("账号或者密码出错"); +// } if (!verifyPwd(user, loginPO.getPassword())) { throw new BizException("账号或者密码出错"); @@ -59,10 +67,59 @@ public class LoginHelper { throw new BizException("账户状态异常"); } - return new UserSession(user.getId()); + return user; } +// public static UserSession login(LoginVO loginPO) { +// String key = loginPO.getUuid() + "_" + SwConsts.LOGIN_VERIFY_CODE; +// //先提取验证码 +// String verifyCode = RedisManager.getInstance().get(key, String.class); +// RedisManager.getInstance().del(key); +// +// if (StringUtils.isBlank(loginPO.getUsername())) { +// throw new BizException("账号不能为空"); +// } +// +// if ("admin".equals(loginPO.getUsername())) { +// return new UserSession(1); +// } +// +// if (StringUtils.isBlank(loginPO.getPassword())) { +// throw new BizException("密码不能为空"); +// } +// +// if (StringUtils.isBlank(loginPO.getVerifyCode())) { +// throw new BizException("验证码不能为空"); +// } +// +// if (!loginPO.getVerifyCode().equalsIgnoreCase(verifyCode)) { +// throw new BizException("验证码错误"); +// } +// +// //查询数据库 +// List userObjList = DbEngine.getInstance().findDao(User.ENTITY_NAME).queryWhere(" sur_code=? or sur_tel=?", loginPO.getUsername(), loginPO.getUsername()); +//// User user = UserCache.getInstance().getByKey(loginPO.getUsername()); +// if(null == userObjList || userObjList.size()<=0){ +// throw new BizException("账号或者密码出错"); +// } +// User user =userObjList.get(0); +//// if (user == null) { +//// throw new BizException("账号或者密码出错"); +//// } +// +// if (!verifyPwd(user, loginPO.getPassword())) { +// throw new BizException("账号或者密码出错"); +// } +// +// if (SwEnum.UserStatu.NORMAL.value != user.getStatu()) { +// throw new BizException("账户状态异常"); +// } +// +// return new UserSession(user.getId()); +// } + + //密码加密(登录时以密文比较) public static String encodePwd(long user_id, String pwd) { return DigestUtils.md5Hex(PWD_SALT + user_id + pwd);