satoken增加获取用户名方法
This commit is contained in:
parent
5a78919b9b
commit
62b05eb0f3
|
|
@ -38,7 +38,7 @@ public class UserAuthorizationController {
|
|||
*/
|
||||
@PostMapping("/test")
|
||||
public CzgResult<String> login() {
|
||||
StpKit.USER.login(1L, null, MyStpLogic.LoginType.USER, false);
|
||||
// StpKit.USER.login(1L, null, MyStpLogic.LoginType.USER, false);
|
||||
return CzgResult.success(StpKit.USER.getTokenValue());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,18 +44,28 @@ public class MyStpLogic {
|
|||
* @param loginType 登录类型枚举
|
||||
* @param isAdmin 是否为管理员账号
|
||||
*/
|
||||
public void login(Long id, Long shopId, LoginType loginType, boolean isAdmin) {
|
||||
public void login(Long id, String account, Long shopId, LoginType loginType, boolean isAdmin) {
|
||||
StpLogic logic = getLogic();
|
||||
logic.login(id);
|
||||
if (loginType.equals(LoginType.MANAGER) && shopId == null) {
|
||||
throw new ApiNotPrintException("管理端登录必须传递店铺id");
|
||||
}
|
||||
SaSession session = logic.getSession().set("userId", id).set("isAdmin", isAdmin).set("isManager", loginType.equals(LoginType.MANAGER)).set("loginType", loginType);
|
||||
SaSession session = logic.getSession().set("userId", id).set("isAdmin", isAdmin).set("isManager", loginType.equals(LoginType.MANAGER))
|
||||
.set("loginType", loginType).set("account", account);
|
||||
if (shopId != null) {
|
||||
session.set("shopId", shopId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录账号名称 管理端为用户账号 客户端为openId
|
||||
* @return 账号或openId
|
||||
*/
|
||||
public String getAccount() {
|
||||
StpLogic logic = getLogic();
|
||||
return (String) logic.getSession().get("account");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺id
|
||||
*
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public class AuthorizationServiceImpl implements AuthorizationService {
|
|||
}
|
||||
}
|
||||
|
||||
StpKit.USER.login(user.getId(), shopInfo.getId(), isStaff ? MyStpLogic.LoginType.STAFF :MyStpLogic.LoginType.MANAGER, user.getIsAdmin());
|
||||
StpKit.USER.login(user.getId(), user.getAccount(), shopInfo.getId(), isStaff ? MyStpLogic.LoginType.STAFF :MyStpLogic.LoginType.MANAGER, user.getIsAdmin());
|
||||
// 查询角色
|
||||
List<SysRole> roleList = sysRoleService.getByUserId(user.getId());
|
||||
List<String> roleNames = roleList.stream().map(SysRole::getName).collect(Collectors.toList());
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class UserAuthorizationServiceImpl implements UserAuthorizationService {
|
|||
userInfo.setLastLoginTime(DateUtil.date().toLocalDateTime());
|
||||
userInfoService.saveOrUpdate(userInfo);
|
||||
// StpKit.USER.login(userInfo.getId());
|
||||
StpKit.USER.login(userInfo.getId(), null, MyStpLogic.LoginType.USER, false);
|
||||
StpKit.USER.login(userInfo.getId(), openId, null, MyStpLogic.LoginType.USER, false);
|
||||
return new LoginTokenDTO(StpKit.USER.getTokenValue(), userInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue