perf:登录调整
This commit is contained in:
@@ -27,30 +27,28 @@ public class DemoWebConfigurer implements TieshengWebConfigurer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LoginConfigurer loginConfigurer() {
|
public TokenBean login(CorePlatformUnique platformUnique) {
|
||||||
return new LoginConfigurer() {
|
TokenBean tokenBean = null;
|
||||||
@Override
|
if (!StrUtil.isEmpty(platformUnique.getUserId())) {
|
||||||
public TokenBean doLogin(CorePlatformUnique platformUnique, String to) {
|
tokenBean = new TokenBean(platformUnique.getUserId(), "", globalConfig.getService());
|
||||||
|
} else {
|
||||||
|
// 获取用户信息判断是否可登录
|
||||||
|
|
||||||
// 默认跳转到mobile
|
}
|
||||||
to = StrUtil.emptyToDefault(to, "mobile");
|
|
||||||
|
|
||||||
TokenBean tokenBean = null;
|
return tokenBean;
|
||||||
if (!StrUtil.isEmpty(platformUnique.getUserId())) {
|
|
||||||
tokenBean = new TokenBean(platformUnique.getUserId(), to, globalConfig.getService());
|
|
||||||
} else {
|
|
||||||
// 获取用户信息判断是否可登录
|
|
||||||
}
|
|
||||||
|
|
||||||
return tokenBean;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void redirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
|
||||||
if (Objects.equals(bean.getEnvironmentType(), "mobile")) {
|
|
||||||
globalConfig.redirect("mobile", "/?token=" + bean.toToken(), response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void redirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
||||||
|
|
||||||
|
// 默认跳转到mobile
|
||||||
|
to = StrUtil.emptyToDefault(to, "mobile");
|
||||||
|
bean.setEnvironmentType(to);
|
||||||
|
|
||||||
|
if (Objects.equals(bean.getEnvironmentType(), "mobile")) {
|
||||||
|
globalConfig.redirect("mobile", "/?token=" + bean.toToken(), response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ public class LoginController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/unique/redirect")
|
@GetMapping("/unique/redirect")
|
||||||
public void uniqueIndex(UniqueIndexDTO dto, HttpServletResponse response) {
|
public void uniqueIndex(UniqueIndexDTO dto, HttpServletResponse response) {
|
||||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("unique_index_web",
|
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("web_unique_redirect",
|
||||||
dto.getNo(), "web", dto.getTo(), dto.getInfo()));
|
dto.getNo(), dto.getPlatform(), dto.getInfo()));
|
||||||
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,8 +72,8 @@ public class LoginController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/unique/index")
|
@PostMapping("/unique/index")
|
||||||
public ApiResp<String> uniqueIndex(@RequestBody UniqueIndexDTO dto) {
|
public ApiResp<String> uniqueIndex(@RequestBody UniqueIndexDTO dto) {
|
||||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("unique_index_web",
|
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo("web_unique_index",
|
||||||
dto.getNo(), "web", dto.getTo(), dto.getInfo()));
|
dto.getNo(), dto.getPlatform(), dto.getInfo()));
|
||||||
if (tokenBean == null) {
|
if (tokenBean == null) {
|
||||||
throw new ApiException("登录失败");
|
throw new ApiException("登录失败");
|
||||||
}
|
}
|
||||||
@@ -120,8 +120,7 @@ public class LoginController {
|
|||||||
String ddUserId = platformDingConfig.getUserIdByCode(service, dto.getCode());
|
String ddUserId = platformDingConfig.getUserIdByCode(service, dto.getCode());
|
||||||
DingUserInfo dingUserInfo = platformDingConfig.topapiV2UserGet(service, ddUserId);
|
DingUserInfo dingUserInfo = platformDingConfig.topapiV2UserGet(service, ddUserId);
|
||||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(dingUserInfo.getAppId(),
|
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(dingUserInfo.getAppId(),
|
||||||
dingUserInfo.getUserid(), "ding", dto.getTo(),
|
dingUserInfo.getUserid(), "ding", JSON.toJSONString(dingUserInfo)));
|
||||||
JSON.toJSONString(dingUserInfo)));
|
|
||||||
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +166,7 @@ public class LoginController {
|
|||||||
public void wxmpOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
|
public void wxmpOauth2(@PathVariable String service, CodeExtraDTO dto, HttpServletResponse response) {
|
||||||
WxUserInfo wxUserInfo = platformWxmpConfig.getOAuth2AccessToken(service, dto.getCode());
|
WxUserInfo wxUserInfo = platformWxmpConfig.getOAuth2AccessToken(service, dto.getCode());
|
||||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(wxUserInfo.getAppId(),
|
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(wxUserInfo.getAppId(),
|
||||||
wxUserInfo.getOpenid(), "wxmp", dto.getTo(), JSON.toJSONString(wxUserInfo)));
|
wxUserInfo.getOpenid(), "wxmp", JSON.toJSONString(wxUserInfo)));
|
||||||
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
tieshengLoginConfigurer.onLoginRedirect(tokenBean, dto.getTo(), dto.getExtra(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +197,7 @@ public class LoginController {
|
|||||||
String openid = platformWxminiConfig.jscode2session(service, code);
|
String openid = platformWxminiConfig.jscode2session(service, code);
|
||||||
WxConfigBean configBean = platformWxminiConfig.getConfigBean(service);
|
WxConfigBean configBean = platformWxminiConfig.getConfigBean(service);
|
||||||
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(configBean.getAppId(),
|
TokenBean tokenBean = tieshengLoginConfigurer.doLogin(new DoLoginInfo(configBean.getAppId(),
|
||||||
openid, "wxmini", "mini", "{}"));
|
openid, "wxmini", "{}"));
|
||||||
|
|
||||||
WxminiLoginVo loginVo = new WxminiLoginVo();
|
WxminiLoginVo loginVo = new WxminiLoginVo();
|
||||||
loginVo.setOpenid(openid);
|
loginVo.setOpenid(openid);
|
||||||
|
|||||||
@@ -5,15 +5,13 @@ public class DoLoginInfo {
|
|||||||
private String appId;
|
private String appId;
|
||||||
private String unique;
|
private String unique;
|
||||||
private String platform;
|
private String platform;
|
||||||
private String to;
|
|
||||||
private String info;
|
private String info;
|
||||||
private String extra;
|
private String extra;
|
||||||
|
|
||||||
public DoLoginInfo(String appId, String unique, String platform, String to, String info) {
|
public DoLoginInfo(String appId, String unique, String platform, String info) {
|
||||||
this.appId = appId;
|
this.appId = appId;
|
||||||
this.unique = unique;
|
this.unique = unique;
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
this.to = to;
|
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,14 +43,6 @@ public class DoLoginInfo {
|
|||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTo() {
|
|
||||||
return to;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTo(String to) {
|
|
||||||
this.to = to;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getInfo() {
|
public String getInfo() {
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public class UniqueIndexDTO extends LoginToInfo {
|
|||||||
private String no;
|
private String no;
|
||||||
private String extra;
|
private String extra;
|
||||||
private String info;
|
private String info;
|
||||||
|
private String platform = "web";
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// setter\getter
|
// setter\getter
|
||||||
@@ -38,4 +39,12 @@ public class UniqueIndexDTO extends LoginToInfo {
|
|||||||
public void setInfo(String info) {
|
public void setInfo(String info) {
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPlatform() {
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlatform(String platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public interface TieshengLoginConfigurer {
|
|||||||
/**
|
/**
|
||||||
* 授权登录回调
|
* 授权登录回调
|
||||||
*
|
*
|
||||||
* @param tokenBean
|
* @param bean
|
||||||
*/
|
*/
|
||||||
void onLoginRedirect(TokenBean bean, String to, String extra, HttpServletResponse response);
|
void onLoginRedirect(TokenBean bean, String to, String extra, HttpServletResponse response);
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
|
|||||||
platformUnique.setInfo(loginInfo.getInfo());
|
platformUnique.setInfo(loginInfo.getInfo());
|
||||||
saveOrUpdate(platformUnique);
|
saveOrUpdate(platformUnique);
|
||||||
|
|
||||||
TokenBean tokenBean = tieshengWebConfigurer.loginConfigurer().doLogin(platformUnique, loginInfo.getTo());
|
TokenBean tokenBean = tieshengWebConfigurer.login(platformUnique);
|
||||||
if (tokenBean != null) {
|
if (tokenBean != null) {
|
||||||
// 添加登录日志
|
// 添加登录日志
|
||||||
coreLogService.addLoginLog(platformUnique, tokenBean);
|
coreLogService.addLoginLog(platformUnique, tokenBean);
|
||||||
@@ -45,7 +45,7 @@ public class CorePlatformUniqueService extends TsServiceBase<CorePlatformUniqueM
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoginRedirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
public void onLoginRedirect(TokenBean bean, String to, String extra, HttpServletResponse response) {
|
||||||
tieshengWebConfigurer.loginConfigurer().redirect(bean, to, extra, response);
|
tieshengWebConfigurer.redirect(bean, to, extra, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,36 +54,22 @@ public interface TieshengWebConfigurer {
|
|||||||
return uploadPath;
|
return uploadPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置登录
|
* 登录逻辑
|
||||||
*
|
*
|
||||||
|
* @param platformUnique
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
LoginConfigurer loginConfigurer();
|
TokenBean login(CorePlatformUnique platformUnique);
|
||||||
|
|
||||||
|
/**
|
||||||
interface LoginConfigurer {
|
* 登录重定向
|
||||||
|
*
|
||||||
/**
|
* @param bean
|
||||||
* 登录逻辑
|
* @param extra
|
||||||
*
|
* @param response
|
||||||
* @param platformUnique
|
*/
|
||||||
* @return
|
void redirect(TokenBean bean, String to, String extra, HttpServletResponse response);
|
||||||
*/
|
|
||||||
TokenBean doLogin(CorePlatformUnique platformUnique, String to);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录重定向
|
|
||||||
*
|
|
||||||
* @param bean
|
|
||||||
* @param extra
|
|
||||||
* @param response
|
|
||||||
*/
|
|
||||||
void redirect(TokenBean bean, String to, String extra, HttpServletResponse response);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user