|
|
@@ -1,5 +1,6 @@
|
|
|
package com.coffee.framework.web.service.impl;
|
|
|
|
|
|
+import cn.dev33.satoken.spring.SpringMVCUtil;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
@@ -23,12 +24,16 @@ import com.coffee.system.common.vo.*;
|
|
|
import com.coffee.system.entity.SysMenu;
|
|
|
import com.coffee.system.entity.SysRole;
|
|
|
import com.coffee.system.entity.SysUser;
|
|
|
+import com.coffee.system.properties.CaptchaProperties;
|
|
|
import com.coffee.system.service.ISysMenuService;
|
|
|
import com.coffee.system.service.ISysRoleService;
|
|
|
import com.coffee.system.service.ISysUserService;
|
|
|
+import com.coffee.system.utils.CaptchaTool;
|
|
|
import com.google.common.collect.Sets;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.ServletRequestUtils;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
@@ -44,11 +49,18 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
+@EnableConfigurationProperties(CaptchaProperties.class)
|
|
|
public class UserServiceImpl implements IUserService {
|
|
|
|
|
|
@Resource
|
|
|
private ISysMenuService sysMenuService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private CaptchaTool captchaTool;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CaptchaProperties captchaProperties;
|
|
|
+
|
|
|
@Resource
|
|
|
private ISysUserService sysUserService;
|
|
|
|
|
|
@@ -71,6 +83,14 @@ public class UserServiceImpl implements IUserService {
|
|
|
if (StrUtil.isBlank(req.getPassword())) {
|
|
|
throw new CustomException("密码不能为空");
|
|
|
}
|
|
|
+ if(captchaProperties.isEnable()){
|
|
|
+ HttpServletRequest request = SpringMVCUtil.getRequest();
|
|
|
+ String requestFrom = request.getHeader("RequestFrom");
|
|
|
+ //来自app的请求不需要验证码
|
|
|
+ if(!"TuoRenApp".equals(requestFrom)){
|
|
|
+ captchaTool.ver(req.getCodeKey(),req.getCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
sysUser = sysUserService.getOne(Wrappers.lambdaQuery(SysUser.class).eq(SysUser::getAccount, req.getUsername()));
|
|
|
if (Objects.isNull(sysUser)) {
|
|
|
log.info("登录用户:{}不存在", req.getUsername());
|