Commit c0ed0630 by 朱淼

平台端小程序-登录

parent c8f76b4a
package com.makeit.config;
import com.makeit.global.inteceptor.RequestIdInterceptor;
import com.makeit.global.inteceptor.SaasAuthenticationInterceptor;
import com.makeit.global.inteceptor.SaasAuthorizationInterceptor;
import com.makeit.global.inteceptor.PlatAuthenticationInterceptor;
import com.makeit.global.inteceptor.PlatAuthorizationInterceptor;
import com.makeit.global.inteceptor.*;
import com.makeit.utils.old.StringUtils;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -34,6 +30,9 @@ public class WebInterceptorConfig implements WebMvcConfigurer {
@Autowired
private SaasAuthorizationInterceptor saasAuthorizationInterceptor;
@Autowired
private WechatAuthenticationInterceptor wechatAuthenticationInterceptor;
private String authenticationSaasPath;
private String authenticationSaasPathIgnore;
......@@ -48,6 +47,9 @@ public class WebInterceptorConfig implements WebMvcConfigurer {
private String authorizationTntPath;
private String authorizationTntPathIgnore;
private String authenticationWechatPath;
private String authenticationWechatPathIgnore;
@Override
public void addInterceptors(InterceptorRegistry registry) {
......@@ -62,6 +64,8 @@ public class WebInterceptorConfig implements WebMvcConfigurer {
addInterceptor(registry.addInterceptor(saasAuthenticationInterceptor), authenticationSaasPath, authenticationSaasPathIgnore);
//saas 授权
addInterceptor(registry.addInterceptor(saasAuthorizationInterceptor), authorizationSaasPath, authorizationSaasPathIgnore);
//微信 认证
addInterceptor(registry.addInterceptor(wechatAuthenticationInterceptor), authenticationWechatPath, authenticationWechatPathIgnore);
}
......
......@@ -69,6 +69,7 @@ public enum CodeMessageEnum {
SYSTEM_ERROR_AUTH_USER_PAY_PASSWORD_BLANK(500, "SYSTEM.ERROR.AUTH.USER.PAY.PASSWORD.BLANK"),
SYSTEM_ERROR_WECHAT_USER_NOT_EXIST(520, "SYSTEM.ERROR.WECHAT.USER.NOT.EXIST"),
SYSTEM_ERROR_AUTH_USER_MAIL_NOT_SET(500, "SYSTEM.ERROR.AUTH.USER.MAIL.NOT.SET"),
SYSTEM_ERROR_AUTH_USER_PASSWORD_NOT_EQUALS(500, "SYSTEM.ERROR.AUTH.USER.PASSWORD.NOT.EQUALS"),
SYSTEM_ERROR_EXCEL_UPLOAD_EXIT(10001, "SYSTEM.ERROR.EXCEL.UPLOAD.EXIT"),
SYSTEM_ERROR_EXCEL_NOT_DATA(10002, "SYSTEM.ERROR.EXCEL.NOT.DATA"),
......
......@@ -65,6 +65,7 @@ SYSTEM.ERROR.AUTH.USER.ACCOUNT.PASSWORD=账号或者密码错误!
SYSTEM.ERROR.AUTH.USER.PASSWORD=密码错误
SYSTEM.ERROR.AUTH.USER.PAY.PASSWORD.BLANK=支付密码未设置
SYSTEM.ERROR.AUTH.USER.MAIL.NOT.SET=邮箱未设置
SYSTEM.ERROR.AUTH.USER.PASSWORD.NOT.EQUALS=新密码与确认密码不一致
SYSTEM.ERROR.WECHAT.USER.NOT.EXIST=该企微账号对应的用户不存在
......
package com.makeit.module.controller.wechat.auth;
import com.makeit.common.dto.LoginDTO;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.module.admin.vo.plat.PlatUserLoginVO;
import com.makeit.service.platform.auth.PlatUserService;
import com.makeit.service.wechat.PlatLoginWechatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Controller
*
* @author zm
* @version 2023/9/6
*/
@Api(tags = "平台端小程序-登录")
@RestController
@RequestMapping("/wechat/plat/login")
public class PlatLoginWechatController {
@Autowired
private PlatLoginWechatService platLoginWechatService;
@ApiOperation("登录")
@PostMapping("login")
public ApiResponseEntity<PlatUserLoginVO> login(@RequestBody LoginDTO loginDTO) {
return ApiResponseUtils.success(platLoginWechatService.wechatLogin(loginDTO));
}
}
package com.makeit.module.controller.wechat.auth;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.dto.platform.auth.PlatUserChangePasswordDTO;
import com.makeit.service.wechat.PlatUserWechatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Controller
*
* @author zm
* @version 2023/9/7
*/
@Api(tags = "平台端小程序-我的")
@RestController
@RequestMapping("/wechat/plat/user")
public class PlatUserWechatController {
@Autowired
private PlatUserWechatService platUserWechatService;
@ApiOperation("修改密码")
@PostMapping("changePassword")
public ApiResponseEntity<Void> changePassword(@RequestBody PlatUserChangePasswordDTO dto) {
platUserWechatService.changePassword(dto);
return ApiResponseUtils.success();
}
}
package com.makeit.dto.platform.auth;
import com.makeit.common.dto.BaseIdDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* Controller
*
* @author zm
* @version 2023/9/7
*/
@ApiModel("平台端小程序修改密码DTO")
@Data
public class PlatUserChangePasswordDTO extends BaseIdDTO {
@NotBlank(message = "旧密码不能为空")
@ApiModelProperty(value = "旧密码")
private String oldPassword;
@NotBlank(message = "新密码不能为空")
@ApiModelProperty(value = "新密码")
private String newPassword;
@NotBlank(message = "确认密码不能为空")
@ApiModelProperty(value = "确认密码")
private String queryPassword;
}
......@@ -50,6 +50,8 @@ public interface PlatUserService extends IService<PlatUser> {
PlatUserLoginVO login(LoginDTO loginDTO);
void setTenantList(PlatUserLoginVO tntUserLoginVO);
void logout();
List<PlatMenu> getMenuListByTenantId(String tenantId);
......
......@@ -308,7 +308,8 @@ public class PlatUserServiceImpl extends ServiceImpl<PlatUserMapper, PlatUser>
updateById(user);
}
private void setTenantList(PlatUserLoginVO tntUserLoginVO) {
@Override
public void setTenantList(PlatUserLoginVO tntUserLoginVO) {
if (IsTenantAccountEnum.YES.getValue().equals(tntUserLoginVO.getIsTenant())) {
List<PlatTenant> tntTenantList = platTenantService.list(new QueryWrapper<PlatTenant>().lambda()
.eq(PlatTenant::getStatus, CommonEnum.YES.getValue())
......
package com.makeit.service.wechat;
import com.makeit.common.dto.LoginDTO;
import com.makeit.module.admin.vo.plat.PlatUserLoginVO;
/**
* Controller
*
* @author zm
* @version 2023/9/7
*/
public interface PlatLoginWechatService {
PlatUserLoginVO wechatLogin(LoginDTO loginDTO);
}
package com.makeit.service.wechat;
import com.makeit.dto.platform.auth.PlatUserChangePasswordDTO;
/**
* Controller
*
* @author zm
* @version 2023/9/7
*/
public interface PlatUserWechatService {
void changePassword(PlatUserChangePasswordDTO dto);
}
package com.makeit.service.wechat.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.makeit.common.dto.LoginDTO;
import com.makeit.entity.platform.auth.PlatUser;
import com.makeit.enums.CodeMessageEnum;
import com.makeit.enums.CommonEnum;
import com.makeit.exception.BusinessException;
import com.makeit.global.aspect.tenant.TenantIdIgnore;
import com.makeit.module.admin.vo.plat.PlatUserLoginVO;
import com.makeit.service.platform.auth.PlatUserService;
import com.makeit.service.wechat.PlatLoginWechatService;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.id.IdGen;
import com.makeit.utils.user.PasswordUtils;
import com.makeit.utils.user.TokenUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Controller
*
* @author zm
* @version 2023/9/7
*/
@Service
public class PlatLoginWechatServiceImpl implements PlatLoginWechatService {
@Autowired
private PlatUserService platUserService;
@Override
@TenantIdIgnore
public PlatUserLoginVO wechatLogin(LoginDTO loginDTO) {
if (StringUtils.isBlank(loginDTO.getAccount())) {
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR);
}
if (StringUtils.isBlank(loginDTO.getPassword())) {
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR);
}
PlatUser platUser = platUserService.getOne(new QueryWrapper<PlatUser>().lambda()
.eq(PlatUser::getAccount, loginDTO.getAccount())
.or()
.eq(PlatUser::getMobile, loginDTO.getAccount())
);
if (platUser == null) {
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR_AUTH_USER_PASSWORD);
}
if (CommonEnum.NO.getValue().equals(platUser.getStatus())) {
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR_AUTH_USER_HAS_DISABLED);
}
if (!PasswordUtils.validatePassword(loginDTO.getPassword(), platUser.getPassword())) {
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR_AUTH_USER_PASSWORD);
}
PlatUserLoginVO userLoginVO = BeanDtoVoUtils.convert(platUser, PlatUserLoginVO.class);
String token = IdGen.getUUID();
userLoginVO.setToken(token);
TokenUtil.wechatLogin(token, userLoginVO);
platUserService.setTenantList(userLoginVO);
return userLoginVO;
}
}
package com.makeit.service.wechat.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.makeit.dto.platform.auth.PlatUserChangePasswordDTO;
import com.makeit.entity.platform.auth.PlatUser;
import com.makeit.enums.CodeMessageEnum;
import com.makeit.exception.BusinessException;
import com.makeit.service.platform.auth.PlatUserService;
import com.makeit.service.wechat.PlatUserWechatService;
import com.makeit.utils.user.PasswordUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* Controller
*
* @author zm
* @version 2023/9/7
*/
@Service
public class PlatUserWechatServiceImpl implements PlatUserWechatService {
@Autowired
private PlatUserService platUserService;
@Override
@Transactional
public void changePassword(PlatUserChangePasswordDTO dto) {
PlatUser platUser = platUserService.getById(dto.getId());
if (platUser == null) {
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR_AUTH_USER_PASSWORD);
}
if (!PasswordUtils.validatePassword(dto.getOldPassword(), platUser.getPassword())) {
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR_AUTH_USER_PASSWORD);
}
if(dto.getNewPassword()!=null && !dto.getNewPassword().equals(dto.getQueryPassword())){
throw new BusinessException(CodeMessageEnum.SYSTEM_ERROR_AUTH_USER_PASSWORD_NOT_EQUALS);
}
platUser.setPassword(dto.getNewPassword());
platUserService.setPassword(platUser);
platUserService.updateById(platUser);
}
}
......@@ -110,11 +110,11 @@ sa-token:
interceptor:
## 登录拦截路径
authenticationTntPath: /**
authenticationTntPathIgnore: /error,/swagger-resources/**,/v2/api-docs/**,/doc.html,/plat/login/**,/sys/dictionaryCategory/getDictionaryCategoryByList,/children/**,/saas/**
authenticationTntPathIgnore: /error,/swagger-resources/**,/v2/api-docs/**,/doc.html,/plat/login/**,/sys/dictionaryCategory/getDictionaryCategoryByList,/children/**,/saas/**,/wechat/**
## 权限拦截路径
authorizationTntPath: /**
authorizationTntPathIgnore: /error,/swagger-resources/**,/v2/api-docs/**,/doc.html,/plat/login/**,/sys/dictionaryCategory/getDictionaryCategoryByList,/children/**,/saas/**
authorizationTntPathIgnore: /error,/swagger-resources/**,/v2/api-docs/**,/doc.html,/plat/login/**,/sys/dictionaryCategory/getDictionaryCategoryByList,/children/**,/saas/**,/wechat/**
## saas端登录拦截路径
authenticationSaasPath: /saas/**
......@@ -124,8 +124,8 @@ interceptor:
authorizationSaasPath: /saas/**
authorizationSaasPathIgnore: /saas/login/login
authenticationWechatPath: /children/**
authenticationWechatPathIgnore: /children/login/login
authenticationWechatPath: /children/**,/wechat/**
authenticationWechatPathIgnore: /children/login/login,/wechat/plat/login/login
sign:
flag: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment