临时提交

This commit is contained in:
墨大叔 2024-07-27 14:30:08 +08:00
parent 7fbf87ff3f
commit 1ff3807725
9 changed files with 100 additions and 25 deletions

View File

@ -119,10 +119,11 @@ public class LoginUser implements UserDetails
this.permissions = permissions;
}
public LoginUser(Long userId, SmUser smUser) {
public LoginUser(Long userId, SmUser smUser, Set<String> permissions) {
this.loginType = LoginType.FRONT;
this.userId = userId;
this.smUser = smUser;
this.permissions = permissions;
}
public Long getUserId()

View File

@ -114,7 +114,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 过滤请求
.authorizeRequests()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/register","/app/**", "/captchaImage").permitAll()
.antMatchers("/login", "/register","/app/**", "/captchaImage", "/userLogin").permitAll()
// 静态资源可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()

View File

@ -11,6 +11,7 @@ import com.ruoyi.common.constant.CacheConstants;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.framework.security.domain.AccessLoginUser;
import com.ruoyi.framework.web.service.SysPermissionService;
import com.ruoyi.ss.access.domain.AccessVO;
import com.ruoyi.ss.access.service.AccessService;
import com.ruoyi.ss.user.domain.SmUserVo;
@ -42,9 +43,13 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
@Autowired
private ISmUserService userService;
@Autowired
private RedisCache redisCache;
@Autowired
private SysPermissionService permissionService;
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws ServletException, IOException
@ -98,7 +103,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
if (user == null) {
return null;
}
LoginUser loginUser = new LoginUser(user.getUserId(), user);
LoginUser loginUser = new LoginUser(user.getUserId(), user, permissionService.getMenuPermission(user));
accessLoginUser.setLoginUser(loginUser);
// 放入缓存中

View File

@ -360,4 +360,11 @@ public class SysLoginService
WxMaPhoneNumberInfo wxMaPhoneNumberInfo = JSONObject.parseObject(phoneInfo, WxMaPhoneNumberInfo.class);
return wxMaPhoneNumberInfo.getPhoneNumber();
}
public String userLogin(String username, String password, String code, String uuid) {
// 验证码校验
validateCaptcha(username, code, uuid);
// 登录
return this.appLogin(username, password);
}
}

View File

@ -3,6 +3,8 @@ package com.ruoyi.framework.web.service;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.ruoyi.common.core.domain.entity.SmUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
@ -46,6 +48,17 @@ public class SysPermissionService
return roles;
}
/**
* 获取角色数据权限
*
* @param user 用户信息
* @return 角色权限信息
*/
public Set<String> getRolePermission(SmUser user) {
return new HashSet<>();
}
/**
* 获取菜单数据权限
*
@ -80,4 +93,14 @@ public class SysPermissionService
}
return perms;
}
public Set<String> getMenuPermission(SmUser user) {
Set<String> perms = new HashSet<String>();
// 若是商户则有商户后台权限
if (user.getIsMch() != null && user.getIsMch()) {
perms.add("mch:*:*");
}
return perms;
}
}

View File

@ -127,6 +127,6 @@ public class UserDetailsServiceImpl implements UserDetailsService
}
public UserDetails createLoginUser(SmUser user) {
return new LoginUser(user.getUserId(), user);
return new LoginUser(user.getUserId(), user, permissionService.getMenuPermission(user));
}
}

View File

@ -330,6 +330,12 @@ public class TransactionBillServiceImpl implements TransactionBillService {
ServiceUtil.assertion(suit == null, "套餐不存在");
order.setSuitName(suit.getName());
// 用户信息
SmUserVo user = userService.selectSmUserByUserId(data.getUserId());
ServiceUtil.assertion(user == null, "用户不存在");
ServiceUtil.assertion(user.getWxOpenId() == null, "用户微信openId为空");
order.setAccountNo(user.getWxOpenId());
// 支付过期时间
long expireTime = TimeUnit.MILLISECONDS.convert(Constants.BILL_UNPAID_TIMEOUT, Constants.BILL_UNPAID_TIMEUNIT) + System.currentTimeMillis();
order.setExpireTime(new Date(expireTime));

View File

@ -108,10 +108,6 @@ public class WxPayService implements IWxPayService {
ServiceUtil.assertion(!TransactionBillStatus.UNPAID.getStatus().equals(bill.getStatus()), "只能支付未支付的订单");
ServiceUtil.assertion(!TransactionBillType.RECHARGE.getType().equals(bill.getType()), "只能支付充值订单");
SmUserVo user = smUserService.selectSmUserByUserId(bill.getUserId());
ServiceUtil.assertion(user == null, "用户不存在");
ServiceUtil.assertion(user.getWxOpenId() == null, "用户微信openId为空");
// 获取JSAPI所需参数
// PrepayRequest request = new PrepayRequest();
// request.setAmount(getAmount(bill.getMoney()));

View File

@ -3,6 +3,9 @@ package com.ruoyi.web.controller.system;
import java.util.List;
import java.util.Set;
import com.ruoyi.common.core.domain.entity.SmUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.LoginType;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -19,6 +22,8 @@ import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.framework.web.service.SysPermissionService;
import com.ruoyi.system.service.ISysMenuService;
import static oshi.util.UserGroupInfo.getUser;
/**
* 登录验证
*
@ -53,6 +58,23 @@ public class SysLoginController
return ajax;
}
/**
* 普通用户登录方法
*
* @param loginBody 登录信息
* @return 结果
*/
@PostMapping("/userLogin")
public AjaxResult userLogin(@RequestBody LoginBody loginBody)
{
AjaxResult ajax = AjaxResult.success();
// 生成令牌
String token = loginService.userLogin(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
loginBody.getUuid());
ajax.put(Constants.TOKEN, token);
return ajax;
}
/**
* 获取用户信息
*
@ -61,15 +83,30 @@ public class SysLoginController
@GetMapping("getInfo")
public AjaxResult getInfo()
{
SysUser user = SecurityUtils.getLoginUser().getUser();
// 角色集合
Set<String> roles = permissionService.getRolePermission(user);
// 权限集合
Set<String> permissions = permissionService.getMenuPermission(user);
AjaxResult ajax = AjaxResult.success();
ajax.put("user", user);
LoginUser loginUser = SecurityUtils.getLoginUser();
// 角色集合
Set<String> roles = null;
// 权限集合
Set<String> permissions = null;
// 管理员
if (LoginType.ADMIN.equals(loginUser.getLoginType())) {
SysUser user = loginUser.getUser();
roles = permissionService.getRolePermission(user);
permissions = permissionService.getMenuPermission(user);
ajax.put("user", user);
}
// 普通用户
else {
SmUser user = loginUser.getSmUser();
roles = permissionService.getRolePermission(user);
permissions = permissionService.getMenuPermission(user);
ajax.put("user", user);
}
ajax.put("roles", roles);
ajax.put("permissions", permissions);
ajax.put("userType", loginUser.getLoginType().getType());
return ajax;
}