Parcourir la source

新增:登录事件(用户映射,登录成功之后)

4.0
FLYPHT il y a 2 ans
Parent
révision
715a83dfee
4 fichiers modifiés avec 63 ajouts et 18 suppressions
  1. +53
    -18
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java
  2. +2
    -0
      smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/MappingUserParam.java
  3. +7
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/container/base/SwReturn.java
  4. +1
    -0
      smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionUtil.java

+ 53
- 18
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/AuthService.java Voir le fichier

@@ -8,6 +8,7 @@ import cc.smtweb.framework.core.common.R;
import cc.smtweb.framework.core.common.SwConsts;
import cc.smtweb.framework.core.common.SwMap;
import cc.smtweb.framework.core.container.base.SwParameter;
import cc.smtweb.framework.core.container.base.SwReturn;
import cc.smtweb.framework.core.container.factory.ListenerFactory;
import cc.smtweb.framework.core.db.DbEngine;
import cc.smtweb.framework.core.exception.BizException;
@@ -16,6 +17,7 @@ import cc.smtweb.framework.core.session.UserSession;
import cc.smtweb.system.bpm.web.sys.user.party.Party;
import cc.smtweb.system.bpm.web.sys.user.party.PartyCache;
import cc.smtweb.system.bpm.web.sys.user.user.User;
import cc.smtweb.system.bpm.web.sys.user.user.UserCache;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
@@ -44,7 +46,41 @@ public class AuthService {
}
return R.success(list);
}

// 映射登录
public R mappingLogin(@SwBody MappingUserParam mappingUserParam){
SwMap data = new SwMap();
try {
SwParameter parameter = new SwParameter();
parameter.setSingleParam(mappingUserParam);
SwReturn result = new SwReturn();
ListenerFactory.fireListener(SwConsts.EventConst.LOGIN_MAPPING,parameter,result);
MappingUserRet mappingUserRet = (MappingUserRet)result.getSingleResult();
User user = UserCache.getInstance().get(mappingUserRet.getUserId());
if(user==null){
data.put("isOk", false);
data.put("msg", "映射登录失败!");
return R.success(data);
}
UserSession userSession = LoginHelper.simpleLogin(mappingUserRet.getUserId());
LoginAckVO loginAckVO = createLoginAckVO(user,userSession);
data.put("user", loginAckVO);
data.put("token", loginAckVO.getToken());
data.put("isOk", true);
data.put("msg", "");
// 发布登录成功事件
SwParameter parameter1 = new SwParameter();
LoginSuccessParam loginSuccessParam = new LoginSuccessParam();
loginSuccessParam.setUs(userSession);
loginSuccessParam.setExtra(mappingUserParam.getExtra());
parameter.setSingleParam(loginSuccessParam);
ListenerFactory.fireListenerAsyc(SwConsts.EventConst.LOGIN_SUCCESS,parameter1);
return R.success(data);
}catch (Exception e){
data.put("isOk", false);
data.put("msg", "映射登录失败!");
return R.success(data);
}
}
public R login(@SwBody LoginVO loginPO) {
SwMap data = new SwMap();
User user = null;
@@ -79,17 +115,7 @@ public class AuthService {
user.setId(1);
user.setName("系统管理员");
}
LoginAckVO loginAckVO = new LoginAckVO();
loginAckVO.setUserId(user.getId());
loginAckVO.setUserName(user.getName());
loginAckVO.setRealName(user.getName());
loginAckVO.setPartyId(userSession.getPartyId());
loginAckVO.setAvatar("");
loginAckVO.setDesc(user.getSign());
loginAckVO.setToken(sessionManager.login(userSession));
loginAckVO.setUserLevel(user.getLevel() + "");
loginAckVO.setUserNicky(user.getNicky());
loginAckVO.setUserTel(user.getTel());
LoginAckVO loginAckVO = createLoginAckVO(user,userSession);
data.put("user", loginAckVO);
data.put("token", loginAckVO.getToken());
data.put("isOk", true);
@@ -128,10 +154,19 @@ public class AuthService {
return R.success();
}

// defaultRun 命名的函数是默认函数
// @SwPerm(SwPerm.NONE)
// public R defaultRun(@SwPathParam String path) {
// return R.success(path).put("dao", authDao);
// }

// 创建前端登录对象值对象
private LoginAckVO createLoginAckVO(User user,UserSession userSession){
LoginAckVO loginAckVO = new LoginAckVO();
loginAckVO.setUserId(user.getId());
loginAckVO.setUserName(user.getName());
loginAckVO.setRealName(user.getName());
loginAckVO.setPartyId(userSession.getPartyId());
loginAckVO.setAvatar("");
loginAckVO.setDesc(user.getSign());
loginAckVO.setToken(sessionManager.login(userSession));
loginAckVO.setUserLevel(user.getLevel() + "");
loginAckVO.setUserNicky(user.getNicky());
loginAckVO.setUserTel(user.getTel());
return loginAckVO;
}
}

+ 2
- 0
smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/login/MappingUserParam.java Voir le fichier

@@ -14,6 +14,8 @@ import java.io.Serializable;
public class MappingUserParam implements Serializable {
// 来源
private String source;
// 令牌
private String tk;
// 其他信息
private SwMap extra;
}

+ 7
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/container/base/SwReturn.java Voir le fichier

@@ -23,7 +23,14 @@ public class SwReturn {
* 执行结果参数
*/
private Map<String, Object> map = new HashMap<>();
private Object singleResult;
public <T> T getSingleResult() {
return (T)singleResult;
}

public void setSingleResult(Object singleResult) {
this.singleResult = singleResult;
}
/**
* @param isSuccess
* @param message


+ 1
- 0
smtweb-framework/core/src/main/java/cc/smtweb/framework/core/session/SessionUtil.java Voir le fichier

@@ -48,6 +48,7 @@ public class SessionUtil {
static {
notLoginUrl.add("/api/getVerifyCode");
notLoginUrl.add("/api/bpm/auth/login");
notLoginUrl.add("/api/bpm/auth/mappingLogin");
notLoginUrl.add("/fs/static/*");
notLoginUrl.add("/static/*");
notLoginUrl.add("/custdb/*.do");


Chargement…
Annuler
Enregistrer