|
|
@@ -1,5 +1,6 @@ |
|
|
|
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; |
|
|
@@ -11,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 |
|
|
@@ -21,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); |
|
|
@@ -31,9 +34,7 @@ public class LoginHelper { |
|
|
|
throw new BizException("账号不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if ("admin".equals(loginPO.getUsername())) { |
|
|
|
return UserSession.createSys(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(loginPO.getPassword())) { |
|
|
|
throw new BizException("密码不能为空"); |
|
|
@@ -47,10 +48,16 @@ public class LoginHelper { |
|
|
|
throw new BizException("验证码错误"); |
|
|
|
} |
|
|
|
|
|
|
|
User user = UserCache.getInstance().getByKey(loginPO.getUsername()); |
|
|
|
if (user == null) { |
|
|
|
//查询数据库 |
|
|
|
List<User> 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("账号或者密码出错"); |
|
|
@@ -60,7 +67,7 @@ public class LoginHelper { |
|
|
|
throw new BizException("账户状态异常"); |
|
|
|
} |
|
|
|
|
|
|
|
return new UserSession(user.getId()); |
|
|
|
return user; |
|
|
|
} |
|
|
|
public static UserSession simpleLogin(long useId){ |
|
|
|
User user = UserCache.getInstance().get(useId); |
|
|
@@ -70,6 +77,55 @@ public class LoginHelper { |
|
|
|
return new UserSession(user.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
// 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<User> 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); |
|
|
@@ -79,12 +135,6 @@ public class LoginHelper { |
|
|
|
return DigestUtils.md5Hex(PWD_SALT + user.getId() + pwd).equals(user.getPwd()); |
|
|
|
} |
|
|
|
|
|
|
|
public static void resetUserPwd(User user, String pwd) { |
|
|
|
user.setPwd(LoginHelper.encodePwd(user.getId(), pwd)); |
|
|
|
DbEngine.getInstance().findDao(User.ENTITY_NAME).updateEntity(user); |
|
|
|
UserCache.getInstance().put(user); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验密码是否符合规定 |
|
|
|
* |
|
|
|