|
|
@@ -1,270 +1,269 @@
|
|
|
-package cn.tr.module.sys.oauth2.psw.operator;
|
|
|
-
|
|
|
-import cn.dev33.satoken.stp.StpLogic;
|
|
|
-import cn.dev33.satoken.stp.StpUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.http.useragent.UserAgent;
|
|
|
-import cn.hutool.http.useragent.UserAgentUtil;
|
|
|
-import cn.tr.core.annotation.TenantIgnore;
|
|
|
-import cn.tr.core.enums.LoginScopeType;
|
|
|
-import cn.tr.core.exception.ServiceException;
|
|
|
-import cn.tr.core.exception.TRExcCode;
|
|
|
-import cn.tr.core.utils.IpUtil;
|
|
|
-import cn.tr.core.utils.PswUtils;
|
|
|
-import cn.tr.core.utils.ServletUtils;
|
|
|
-import cn.tr.module.api.sys.log.enums.LoginType;
|
|
|
-import cn.tr.module.sys.config.SysConfigManager;
|
|
|
-import cn.tr.module.sys.config.SysConfigProperties;
|
|
|
-import cn.tr.module.sys.oauth2.config.CaptchaOperator;
|
|
|
-import cn.tr.module.sys.oauth2.dto.AccountUserInfoDTO;
|
|
|
-import cn.tr.module.sys.oauth2.dto.AccountUserInfoEditDTO;
|
|
|
-import cn.tr.module.sys.oauth2.mapper.OAuth2Mapper;
|
|
|
-import cn.tr.module.sys.oauth2.dto.OAuth2PswReqDTO;
|
|
|
-import cn.tr.module.sys.tenant.dto.SysTenantCommonDTO;
|
|
|
-import cn.tr.module.sys.tenant.service.ISysTenantService;
|
|
|
-import cn.tr.module.sys.user.dto.SysOrgDTO;
|
|
|
-import cn.tr.module.sys.user.dto.SysPositionDTO;
|
|
|
-import cn.tr.module.sys.user.dto.SysRoleDTO;
|
|
|
-import cn.tr.module.sys.user.dto.SysUserDTO;
|
|
|
-import cn.tr.module.sys.user.enums.UserStatusEnum;
|
|
|
-import cn.tr.module.sys.user.mapper.SysOrgMapper;
|
|
|
-import cn.tr.module.sys.user.mapper.SysPositionMapper;
|
|
|
-import cn.tr.module.sys.user.mapper.SysRoleMapper;
|
|
|
-import cn.tr.module.sys.user.po.SysUserPO;
|
|
|
-import cn.tr.module.sys.user.repository.SysUserRepository;
|
|
|
-import cn.tr.module.sys.user.service.ISysOrgService;
|
|
|
-import cn.tr.module.sys.user.service.ISysPositionService;
|
|
|
-import cn.tr.module.sys.user.service.ISysRoleService;
|
|
|
-import cn.tr.module.sys.user.service.ISysUserService;
|
|
|
-import cn.tr.plugin.security.bo.UserLoginInfoBO;
|
|
|
-import cn.tr.plugin.security.constant.SecurityConstant;
|
|
|
-import cn.tr.plugin.security.context.LoginUserContextHolder;
|
|
|
-import cn.tr.plugin.security.utils.SaTokenUtils;
|
|
|
-import jakarta.annotation.Resource;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.context.annotation.Lazy;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
-
|
|
|
-/**
|
|
|
- * 默认账号体系登录操作
|
|
|
- *
|
|
|
- * @author lf
|
|
|
- * @date 2023/11/06 10:12
|
|
|
- */
|
|
|
-@Component
|
|
|
-public class LoginOAuth2PswUserOperator extends AbstractOAuth2PswUserOperator{
|
|
|
- @Resource
|
|
|
- @Lazy
|
|
|
- private LoginOAuth2PswUserOperator self;
|
|
|
- @Resource
|
|
|
- private ISysUserService sysUserService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private SysUserRepository sysUserRepository;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private ISysTenantService tenantService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private SysConfigManager configManager;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private CaptchaOperator captchaOperator;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private ISysOrgService orgService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private ISysRoleService roleService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- private ISysPositionService positionService;
|
|
|
-
|
|
|
- @Value("${tr.tenant.enable}")
|
|
|
- private Boolean tenantEnable;
|
|
|
-
|
|
|
- @Override
|
|
|
- @TenantIgnore
|
|
|
- public String auth(OAuth2PswReqDTO source) {
|
|
|
- validate(source);
|
|
|
- String username = source.getUsername();
|
|
|
- String psw = source.getPassword();
|
|
|
- //对账号进行校验
|
|
|
- SysUserDTO user = sysUserService.selectUserByUsername(username);
|
|
|
- if(user==null){
|
|
|
- //账户不存在
|
|
|
- throw new ServiceException(TRExcCode.USER_ERROR_A0201);
|
|
|
- }
|
|
|
- //对密码进行校验
|
|
|
- if(!PswUtils.matchesPassword(psw, user.getPassword())){
|
|
|
- throw new ServiceException(TRExcCode.USER_ERROR_A0210);
|
|
|
- }
|
|
|
- //查看用户是否被禁用
|
|
|
- if(!StrUtil.equals(UserStatusEnum.normal.getValue(), user.getStatus())){
|
|
|
- //用户都被禁用
|
|
|
- throw new ServiceException(TRExcCode.USER_ERROR_A0202);
|
|
|
- }
|
|
|
- if(Boolean.TRUE.equals(tenantEnable)){
|
|
|
- //查看租户是否被禁用
|
|
|
- String tenantId = user.getTenantId();
|
|
|
- SysTenantCommonDTO tenant = tenantService.selectSysTenantById(tenantId);
|
|
|
- if(tenant==null){
|
|
|
- throw new ServiceException(TRExcCode.USER_ERROR_A0205);
|
|
|
- }
|
|
|
- if (Boolean.TRUE.equals(tenant.getDisable())) {
|
|
|
- throw new ServiceException(TRExcCode.USER_ERROR_A0204);
|
|
|
- }
|
|
|
- }
|
|
|
- //验证码校验
|
|
|
- SysConfigProperties current = configManager.getCurrent();
|
|
|
- if (Boolean.TRUE.equals(current.getCaptchaOpen())) {
|
|
|
- String captchaCode = source.getCaptchaCode();
|
|
|
- if(StrUtil.isEmpty(captchaCode)){
|
|
|
- throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"验证码不能为空");
|
|
|
- }
|
|
|
- if(!captchaOperator.ver(source.getCaptchaKey(),source.getCaptchaCode())){
|
|
|
- throw new ServiceException(TRExcCode.USER_ERROR_A0240);
|
|
|
- }
|
|
|
- }
|
|
|
- StpLogic stpUtil = SaTokenUtils.getStpUtil();
|
|
|
- stpUtil.login(user.getId());
|
|
|
- String tokenValue = stpUtil.getTokenValue();
|
|
|
- Date loginTime = new Date();
|
|
|
- //更新最后登录信息
|
|
|
- String ip = ServletUtils.getClientIP();
|
|
|
- String cityInfo = IpUtil.getCityInfo(ip);
|
|
|
- SysUserDTO updateUser = new SysUserDTO();
|
|
|
- updateUser.setId(user.getId());
|
|
|
- updateUser.setLastLoginDate(loginTime);
|
|
|
- updateUser.setLastLoginIp(ip);
|
|
|
- updateUser.setLastLoginAddress(cityInfo);
|
|
|
- sysUserService.updateLastLoginInfo(user.getId(),loginTime,ip,cityInfo);
|
|
|
- //清除缓存
|
|
|
- self.delUserLoginInfoCache(user.getId());
|
|
|
-
|
|
|
- UserAgent userAgent = Optional.ofNullable(UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"))).orElse(new UserAgent());
|
|
|
- String browser = ObjectUtil.isEmpty(userAgent.getBrowser()) ? "未知" : userAgent.getBrowser().getName();
|
|
|
- String os = ObjectUtil.isEmpty(userAgent.getOs()) ? "未知" : userAgent.getOs().getName();
|
|
|
-
|
|
|
- UserLoginInfoBO loginInfo = UserLoginInfoBO.builder()
|
|
|
- .userId(user.getId())
|
|
|
- .nickname(user.getNickname())
|
|
|
- .username(username)
|
|
|
- .tenantId(user.getTenantId())
|
|
|
- .token(tokenValue)
|
|
|
- .loginType(StpUtil.TYPE)
|
|
|
- .loginIp(updateUser.getLastLoginIp())
|
|
|
- .loginLocation(cityInfo)
|
|
|
- .loginTime(loginTime)
|
|
|
- .browser(browser)
|
|
|
- .os(os)
|
|
|
- .signature(user.getSignature())
|
|
|
- .build();
|
|
|
- setSessionUser(tokenValue,loginInfo);
|
|
|
- return tokenValue;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean updatePsw(String oldPsw, String newPsw) {
|
|
|
- return sysUserService.updatePsw(LoginUserContextHolder.getUser().getUserId(),oldPsw,newPsw);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Object getUserLoginInfo() {
|
|
|
- String loginId =String.valueOf( SaTokenUtils.getStpUtil().getLoginId());
|
|
|
- return OAuth2Mapper.INSTANCE.toPswLoginInfo(sysUserService.selectSysUserById(loginId));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public AccountUserInfoDTO getAccountInfo() {
|
|
|
- AccountUserInfoDTO result = new AccountUserInfoDTO();
|
|
|
- String loginId =String.valueOf( SaTokenUtils.getStpUtil().getLoginId());
|
|
|
- SysUserDTO user = sysUserService.selectSysUserById(loginId);
|
|
|
-
|
|
|
- AccountUserInfoDTO.BasicInfo basicInfo = AccountUserInfoDTO.BasicInfo.builder()
|
|
|
- .userId(user.getId())
|
|
|
- .avatar(user.getAvatar())
|
|
|
- .username(user.getUsername())
|
|
|
- .nickname(user.getNickname())
|
|
|
- .gender(user.getGender())
|
|
|
- .phone(user.getPhone())
|
|
|
- .email(user.getEmail())
|
|
|
- .createTime(user.getCreateTime())
|
|
|
- .lastLoginIp(user.getLastLoginIp())
|
|
|
- .lastLoginAddress(user.getLastLoginAddress())
|
|
|
- .lastLoginDate(user.getLastLoginDate())
|
|
|
- .signature(user.getSignature())
|
|
|
- .build();
|
|
|
- //填充角色信息
|
|
|
- List<SysRoleDTO> roles = roleService.selectSysRoleByIds(user.getRoleIds());
|
|
|
- basicInfo.setRoles(SysRoleMapper.INSTANCE.convertSmallList(roles));
|
|
|
- //填充岗位信息
|
|
|
- List<SysPositionDTO> positions = positionService.selectSysPositionByIds(user.getPostIds());
|
|
|
- basicInfo.setPositions(SysPositionMapper.INSTANCE.convertSmallList(positions));
|
|
|
- //填充机构信息
|
|
|
- SysOrgDTO sysOrgDTO = orgService.selectSysOrgById(user.getOrgId());
|
|
|
- basicInfo.setOrg(SysOrgMapper.INSTANCE.convertSmall(sysOrgDTO));
|
|
|
- result.setBasicInfo(basicInfo);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void updateAccountUserInfo(String userId, AccountUserInfoEditDTO source) {
|
|
|
- if(StrUtil.isBlank(source.getAvatar())
|
|
|
- &&StrUtil.isBlank(source.getNickname())
|
|
|
- &&StrUtil.isBlank(source.getGender())
|
|
|
- &&StrUtil.isBlank(source.getPhone())
|
|
|
- &&StrUtil.isBlank(source.getEmail())
|
|
|
- &&StrUtil.isBlank(source.getSignature())){
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- SysUserPO sysUserPO = OAuth2Mapper.INSTANCE.toSysUser(source);
|
|
|
- sysUserPO.setId(userId);
|
|
|
- UserLoginInfoBO user = LoginUserContextHolder.getUser();
|
|
|
- user.setAvatar(source.getAvatar());
|
|
|
- user.setNickname(source.getNickname());
|
|
|
- user.setSignature(source.getSignature());
|
|
|
- sysUserRepository.updateById(sysUserPO);
|
|
|
- sysUserService.delUserIdAndNickNameCache();
|
|
|
- SaTokenUtils.set(SecurityConstant.LOGIN_USER,user);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String matchLoginType() {
|
|
|
- return LoginScopeType.LOGIN_SCOPE_TYPE_NORMAL;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 验证用户名和密码的有效性
|
|
|
- * @throws IllegalArgumentException 当验证失败时抛出
|
|
|
- */
|
|
|
- public void validate(OAuth2PswReqDTO source) throws IllegalArgumentException {
|
|
|
- // 验证用户名
|
|
|
- if (source.getUsername() == null || source.getUsername() .trim().isEmpty()) {
|
|
|
- throw new IllegalArgumentException("账号不能为空");
|
|
|
- }
|
|
|
-
|
|
|
- if (source.getUsername() .length() < 4 || source.getUsername() .length() > 16) {
|
|
|
- throw new IllegalArgumentException("账号长度为 4-16 位");
|
|
|
- }
|
|
|
-
|
|
|
- if (!source.getUsername() .matches("^[A-Za-z0-9]+$")) {
|
|
|
- throw new IllegalArgumentException("账号格式为数字以及字母");
|
|
|
- }
|
|
|
-
|
|
|
- // 验证密码
|
|
|
- if (source.getPassword() == null || source.getPassword().trim().isEmpty()) {
|
|
|
- throw new IllegalArgumentException("密码不能为空");
|
|
|
- }
|
|
|
-
|
|
|
- if (source.getPassword().length() < 4 || source.getPassword().length() > 16) {
|
|
|
- throw new IllegalArgumentException("密码长度为 4-16 位");
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+//package cn.tr.module.sys.oauth2.psw.operator;
|
|
|
+//
|
|
|
+//import cn.dev33.satoken.stp.StpLogic;
|
|
|
+//import cn.dev33.satoken.stp.StpUtil;
|
|
|
+//import cn.hutool.core.util.ObjectUtil;
|
|
|
+//import cn.hutool.core.util.StrUtil;
|
|
|
+//import cn.hutool.http.useragent.UserAgent;
|
|
|
+//import cn.hutool.http.useragent.UserAgentUtil;
|
|
|
+//import cn.tr.core.annotation.TenantIgnore;
|
|
|
+//import cn.tr.core.enums.LoginScopeType;
|
|
|
+//import cn.tr.core.exception.ServiceException;
|
|
|
+//import cn.tr.core.exception.TRExcCode;
|
|
|
+//import cn.tr.core.utils.IpUtil;
|
|
|
+//import cn.tr.core.utils.PswUtils;
|
|
|
+//import cn.tr.core.utils.ServletUtils;
|
|
|
+//import cn.tr.module.sys.config.SysConfigManager;
|
|
|
+//import cn.tr.module.sys.config.SysConfigProperties;
|
|
|
+//import cn.tr.module.sys.oauth2.config.CaptchaOperator;
|
|
|
+//import cn.tr.module.sys.oauth2.dto.AccountUserInfoDTO;
|
|
|
+//import cn.tr.module.sys.oauth2.dto.AccountUserInfoEditDTO;
|
|
|
+//import cn.tr.module.sys.oauth2.mapper.OAuth2Mapper;
|
|
|
+//import cn.tr.module.sys.oauth2.dto.OAuth2PswReqDTO;
|
|
|
+//import cn.tr.module.sys.tenant.dto.SysTenantCommonDTO;
|
|
|
+//import cn.tr.module.sys.tenant.service.ISysTenantService;
|
|
|
+//import cn.tr.module.sys.user.dto.SysOrgDTO;
|
|
|
+//import cn.tr.module.sys.user.dto.SysPositionDTO;
|
|
|
+//import cn.tr.module.sys.user.dto.SysRoleDTO;
|
|
|
+//import cn.tr.module.sys.user.dto.SysUserDTO;
|
|
|
+//import cn.tr.module.sys.user.enums.UserStatusEnum;
|
|
|
+//import cn.tr.module.sys.user.mapper.SysOrgMapper;
|
|
|
+//import cn.tr.module.sys.user.mapper.SysPositionMapper;
|
|
|
+//import cn.tr.module.sys.user.mapper.SysRoleMapper;
|
|
|
+//import cn.tr.module.sys.user.po.SysUserPO;
|
|
|
+//import cn.tr.module.sys.user.repository.SysUserRepository;
|
|
|
+//import cn.tr.module.sys.user.service.ISysOrgService;
|
|
|
+//import cn.tr.module.sys.user.service.ISysPositionService;
|
|
|
+//import cn.tr.module.sys.user.service.ISysRoleService;
|
|
|
+//import cn.tr.module.sys.user.service.ISysUserService;
|
|
|
+//import cn.tr.plugin.security.bo.UserLoginInfoBO;
|
|
|
+//import cn.tr.plugin.security.constant.SecurityConstant;
|
|
|
+//import cn.tr.plugin.security.context.LoginUserContextHolder;
|
|
|
+//import cn.tr.plugin.security.utils.SaTokenUtils;
|
|
|
+//import jakarta.annotation.Resource;
|
|
|
+//import org.springframework.beans.factory.annotation.Value;
|
|
|
+//import org.springframework.context.annotation.Lazy;
|
|
|
+//import org.springframework.stereotype.Component;
|
|
|
+//import java.util.Date;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.Optional;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * 默认账号体系登录操作
|
|
|
+// *
|
|
|
+// * @author lf
|
|
|
+// * @date 2023/11/06 10:12
|
|
|
+// */
|
|
|
+//@Component
|
|
|
+//public class LoginOAuth2PswUserOperator extends AbstractOAuth2PswUserOperator{
|
|
|
+// @Resource
|
|
|
+// @Lazy
|
|
|
+// private LoginOAuth2PswUserOperator self;
|
|
|
+// @Resource
|
|
|
+// private ISysUserService sysUserService;
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private SysUserRepository sysUserRepository;
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private ISysTenantService tenantService;
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private SysConfigManager configManager;
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private CaptchaOperator captchaOperator;
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private ISysOrgService orgService;
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private ISysRoleService roleService;
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// private ISysPositionService positionService;
|
|
|
+//
|
|
|
+// @Value("${tr.tenant.enable}")
|
|
|
+// private Boolean tenantEnable;
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// @TenantIgnore
|
|
|
+// public String auth(OAuth2PswReqDTO source) {
|
|
|
+// validate(source);
|
|
|
+// String username = source.getUsername();
|
|
|
+// String psw = source.getPassword();
|
|
|
+// //对账号进行校验
|
|
|
+// SysUserDTO user = sysUserService.selectUserByUsername(username);
|
|
|
+// if(user==null){
|
|
|
+// //账户不存在
|
|
|
+// throw new ServiceException(TRExcCode.USER_ERROR_A0201);
|
|
|
+// }
|
|
|
+// //对密码进行校验
|
|
|
+// if(!PswUtils.matchesPassword(psw, user.getPassword())){
|
|
|
+// throw new ServiceException(TRExcCode.USER_ERROR_A0210);
|
|
|
+// }
|
|
|
+// //查看用户是否被禁用
|
|
|
+// if(!StrUtil.equals(UserStatusEnum.normal.getValue(), user.getStatus())){
|
|
|
+// //用户都被禁用
|
|
|
+// throw new ServiceException(TRExcCode.USER_ERROR_A0202);
|
|
|
+// }
|
|
|
+// if(Boolean.TRUE.equals(tenantEnable)){
|
|
|
+// //查看租户是否被禁用
|
|
|
+// String tenantId = user.getTenantId();
|
|
|
+// SysTenantCommonDTO tenant = tenantService.selectSysTenantById(tenantId);
|
|
|
+// if(tenant==null){
|
|
|
+// throw new ServiceException(TRExcCode.USER_ERROR_A0205);
|
|
|
+// }
|
|
|
+// if (Boolean.TRUE.equals(tenant.getDisable())) {
|
|
|
+// throw new ServiceException(TRExcCode.USER_ERROR_A0204);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //验证码校验
|
|
|
+// SysConfigProperties current = configManager.getCurrent();
|
|
|
+// if (Boolean.TRUE.equals(current.getCaptchaOpen())) {
|
|
|
+// String captchaCode = source.getCaptchaCode();
|
|
|
+// if(StrUtil.isEmpty(captchaCode)){
|
|
|
+// throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"验证码不能为空");
|
|
|
+// }
|
|
|
+// if(!captchaOperator.ver(source.getCaptchaKey(),source.getCaptchaCode())){
|
|
|
+// throw new ServiceException(TRExcCode.USER_ERROR_A0240);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// StpLogic stpUtil = SaTokenUtils.getStpUtil();
|
|
|
+// stpUtil.login(user.getId());
|
|
|
+// String tokenValue = stpUtil.getTokenValue();
|
|
|
+// Date loginTime = new Date();
|
|
|
+// //更新最后登录信息
|
|
|
+// String ip = ServletUtils.getClientIP();
|
|
|
+// String cityInfo = IpUtil.getCityInfo(ip);
|
|
|
+// SysUserDTO updateUser = new SysUserDTO();
|
|
|
+// updateUser.setId(user.getId());
|
|
|
+// updateUser.setLastLoginDate(loginTime);
|
|
|
+// updateUser.setLastLoginIp(ip);
|
|
|
+// updateUser.setLastLoginAddress(cityInfo);
|
|
|
+// sysUserService.updateLastLoginInfo(user.getId(),loginTime,ip,cityInfo);
|
|
|
+// //清除缓存
|
|
|
+// self.delUserLoginInfoCache(user.getId());
|
|
|
+//
|
|
|
+// UserAgent userAgent = Optional.ofNullable(UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent"))).orElse(new UserAgent());
|
|
|
+// String browser = ObjectUtil.isEmpty(userAgent.getBrowser()) ? "未知" : userAgent.getBrowser().getName();
|
|
|
+// String os = ObjectUtil.isEmpty(userAgent.getOs()) ? "未知" : userAgent.getOs().getName();
|
|
|
+//
|
|
|
+// UserLoginInfoBO loginInfo = UserLoginInfoBO.builder()
|
|
|
+// .userId(user.getId())
|
|
|
+// .nickname(user.getNickname())
|
|
|
+// .username(username)
|
|
|
+// .tenantId(user.getTenantId())
|
|
|
+// .token(tokenValue)
|
|
|
+// .loginType(StpUtil.TYPE)
|
|
|
+// .loginIp(updateUser.getLastLoginIp())
|
|
|
+// .loginLocation(cityInfo)
|
|
|
+// .loginTime(loginTime)
|
|
|
+// .browser(browser)
|
|
|
+// .os(os)
|
|
|
+// .signature(user.getSignature())
|
|
|
+// .build();
|
|
|
+// setSessionUser(tokenValue,loginInfo);
|
|
|
+// return tokenValue;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public boolean updatePsw(String oldPsw, String newPsw) {
|
|
|
+// return sysUserService.updatePsw(LoginUserContextHolder.getUser().getUserId(),oldPsw,newPsw);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Object getUserLoginInfo() {
|
|
|
+// String loginId =String.valueOf( SaTokenUtils.getStpUtil().getLoginId());
|
|
|
+// return OAuth2Mapper.INSTANCE.toPswLoginInfo(sysUserService.selectSysUserById(loginId));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public AccountUserInfoDTO getAccountInfo() {
|
|
|
+// AccountUserInfoDTO result = new AccountUserInfoDTO();
|
|
|
+// String loginId =String.valueOf( SaTokenUtils.getStpUtil().getLoginId());
|
|
|
+// SysUserDTO user = sysUserService.selectSysUserById(loginId);
|
|
|
+//
|
|
|
+// AccountUserInfoDTO.BasicInfo basicInfo = AccountUserInfoDTO.BasicInfo.builder()
|
|
|
+// .userId(user.getId())
|
|
|
+// .avatar(user.getAvatar())
|
|
|
+// .username(user.getUsername())
|
|
|
+// .nickname(user.getNickname())
|
|
|
+// .gender(user.getGender())
|
|
|
+// .phone(user.getPhone())
|
|
|
+// .email(user.getEmail())
|
|
|
+// .createTime(user.getCreateTime())
|
|
|
+// .lastLoginIp(user.getLastLoginIp())
|
|
|
+// .lastLoginAddress(user.getLastLoginAddress())
|
|
|
+// .lastLoginDate(user.getLastLoginDate())
|
|
|
+// .signature(user.getSignature())
|
|
|
+// .build();
|
|
|
+// //填充角色信息
|
|
|
+// List<SysRoleDTO> roles = roleService.selectSysRoleByIds(user.getRoleIds());
|
|
|
+// basicInfo.setRoles(SysRoleMapper.INSTANCE.convertSmallList(roles));
|
|
|
+// //填充岗位信息
|
|
|
+// List<SysPositionDTO> positions = positionService.selectSysPositionByIds(user.getPostIds());
|
|
|
+// basicInfo.setPositions(SysPositionMapper.INSTANCE.convertSmallList(positions));
|
|
|
+// //填充机构信息
|
|
|
+// SysOrgDTO sysOrgDTO = orgService.selectSysOrgById(user.getOrgId());
|
|
|
+// basicInfo.setOrg(SysOrgMapper.INSTANCE.convertSmall(sysOrgDTO));
|
|
|
+// result.setBasicInfo(basicInfo);
|
|
|
+// return result;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public void updateAccountUserInfo(String userId, AccountUserInfoEditDTO source) {
|
|
|
+// if(StrUtil.isBlank(source.getAvatar())
|
|
|
+// &&StrUtil.isBlank(source.getNickname())
|
|
|
+// &&StrUtil.isBlank(source.getGender())
|
|
|
+// &&StrUtil.isBlank(source.getPhone())
|
|
|
+// &&StrUtil.isBlank(source.getEmail())
|
|
|
+// &&StrUtil.isBlank(source.getSignature())){
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// SysUserPO sysUserPO = OAuth2Mapper.INSTANCE.toSysUser(source);
|
|
|
+// sysUserPO.setId(userId);
|
|
|
+// UserLoginInfoBO user = LoginUserContextHolder.getUser();
|
|
|
+// user.setAvatar(source.getAvatar());
|
|
|
+// user.setNickname(source.getNickname());
|
|
|
+// user.setSignature(source.getSignature());
|
|
|
+// sysUserRepository.updateById(sysUserPO);
|
|
|
+// sysUserService.delUserIdAndNickNameCache();
|
|
|
+// SaTokenUtils.set(SecurityConstant.LOGIN_USER,user);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public String matchLoginType() {
|
|
|
+// return LoginScopeType.LOGIN_SCOPE_TYPE_NORMAL;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 验证用户名和密码的有效性
|
|
|
+// * @throws IllegalArgumentException 当验证失败时抛出
|
|
|
+// */
|
|
|
+// public void validate(OAuth2PswReqDTO source) throws IllegalArgumentException {
|
|
|
+// // 验证用户名
|
|
|
+// if (source.getUsername() == null || source.getUsername() .trim().isEmpty()) {
|
|
|
+// throw new IllegalArgumentException("账号不能为空");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (source.getUsername() .length() < 4 || source.getUsername() .length() > 16) {
|
|
|
+// throw new IllegalArgumentException("账号长度为 4-16 位");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (!source.getUsername() .matches("^[A-Za-z0-9]+$")) {
|
|
|
+// throw new IllegalArgumentException("账号格式为数字以及字母");
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 验证密码
|
|
|
+// if (source.getPassword() == null || source.getPassword().trim().isEmpty()) {
|
|
|
+// throw new IllegalArgumentException("密码不能为空");
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (source.getPassword().length() < 4 || source.getPassword().length() > 16) {
|
|
|
+// throw new IllegalArgumentException("密码长度为 4-16 位");
|
|
|
+// }
|
|
|
+// }
|
|
|
+//}
|