瀏覽代碼

修改用户登录为直接查库、登录返回增加返回用户等级

master
zhangyulong 2 年之前
父節點
當前提交
7a3186eba5
共有 3 個文件被更改,包括 76 次插入10 次删除
  1. +11
    -3
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java
  2. +1
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginAckVO.java
  3. +64
    -7
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/LoginHelper.java

+ 11
- 3
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);


+ 1
- 0
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公众用户
}

+ 64
- 7
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<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("账号或者密码出错");
@@ -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<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);


Loading…
取消
儲存