APP登录接口
This commit is contained in:
parent
724ac17f35
commit
f4071abcdc
|
|
@ -40,4 +40,24 @@ public interface RemoteUserService
|
|||
*/
|
||||
@PostMapping("/user/register")
|
||||
public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 注册用户信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param source 请求来源
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/menu/getAppRouters")
|
||||
public R getAppRouters(@RequestBody Long userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 获取APP用户信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param source 请求来源
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/user/getAppUserInfo")
|
||||
public R getAppUserInfo(@RequestBody Long userId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,16 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
{
|
||||
return R.fail("注册用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R getAppRouters(Long userId, String source) {
|
||||
return R.fail("APP菜单获取失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R getAppUserInfo(Long userId, String source) {
|
||||
return R.fail("获取APP用户信息:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ package com.bonus.auth.controller;
|
|||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.bonus.common.core.constant.BusinessConstants;
|
||||
import com.bonus.common.core.constant.SecurityConstants;
|
||||
import com.bonus.common.core.utils.global.SystemGlobal;
|
||||
import com.bonus.system.api.RemoteUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
|
|
@ -20,6 +23,9 @@ import com.bonus.common.security.service.TokenService;
|
|||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
import com.bonus.system.api.model.LoginUser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* token 控制
|
||||
*
|
||||
|
|
@ -35,6 +41,9 @@ public class TokenController
|
|||
@Autowired
|
||||
private SysLoginService sysLoginService;
|
||||
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
|
||||
@PostMapping("login")
|
||||
public R<?> login(@RequestBody LoginBody form) {
|
||||
// 用户登录
|
||||
|
|
@ -43,6 +52,31 @@ public class TokenController
|
|||
return R.ok(tokenService.createToken(userInfo));
|
||||
}
|
||||
|
||||
@PostMapping("appLogin")
|
||||
public R<?> appLogin(@RequestBody LoginBody form) {
|
||||
Map<String, Object> map = new HashMap<>(3);
|
||||
// APP用户登录
|
||||
LoginUser userInfo = sysLoginService.appLogin(form.getUsername(), form.getPassword());
|
||||
Map<String, Object> tokenMap = tokenService.createToken(userInfo);
|
||||
map.put("access_token",tokenMap.get("access_token"));
|
||||
map.put("expires_in",tokenMap.get("expires_in"));
|
||||
// 获取app菜单
|
||||
R result = remoteUserService.getAppRouters(userInfo.getSysUser().getUserId(), SecurityConstants.INNER);
|
||||
if(result.getCode() == BusinessConstants.SUCCESS_CODE){
|
||||
map.put("menuList",result.getData());
|
||||
}
|
||||
// 获取APP用户信息
|
||||
R result2 = remoteUserService.getAppUserInfo(userInfo.getSysUser().getUserId(), SecurityConstants.INNER);
|
||||
if(result2.getCode() == BusinessConstants.SUCCESS_CODE){
|
||||
Map<String, Object> userMap = (Map<String, Object>) result2.getData();
|
||||
map.put("user",userMap.get("user"));
|
||||
map.put("roles",userMap.get("roles"));
|
||||
map.put("permissions",userMap.get("permissions"));
|
||||
}
|
||||
// 获取登录token
|
||||
return R.ok(map);
|
||||
}
|
||||
|
||||
@DeleteMapping("logout")
|
||||
public R<?> logout(HttpServletRequest request) {
|
||||
try{
|
||||
|
|
|
|||
|
|
@ -139,4 +139,52 @@ public class SysLoginService
|
|||
}
|
||||
recordLogService.recordLogininfor(username, Constants.REGISTER, "注册成功");
|
||||
}
|
||||
|
||||
public LoginUser appLogin(String username, String password) {
|
||||
// 用户名或密码为空 错误
|
||||
long startTime = System.currentTimeMillis();
|
||||
if (StringUtils.isAnyBlank(username, password)) {
|
||||
recordLogService.saveLogs(username, startTime, "用户名/密码为空","用户名/密码必须填写",null,null);
|
||||
throw new ServiceException("用户名/密码必须填写");
|
||||
}
|
||||
// 密码如果不在指定范围内 错误
|
||||
if (password.length() < ValidateUtils.MIN_LENGTH
|
||||
|| password.length() > ValidateUtils.MAX_LENGTH) {
|
||||
recordLogService.saveLogs(username,startTime, "密码格式不正确","用户名/密码格式不正确",null,null);
|
||||
throw new ServiceException("用户名/密码格式不正确");
|
||||
}
|
||||
// 用户名不在指定范围内 错误
|
||||
if (username.length() < UserConstants.USERNAME_MIN_LENGTH
|
||||
|| username.length() > UserConstants.USERNAME_MAX_LENGTH) {
|
||||
recordLogService.saveLogs(username, startTime, "用户名格式不正确","用户名/密码格式不正确",null,null);
|
||||
throw new ServiceException("用户名/密码格式不正确");
|
||||
}
|
||||
// 查询用户信息
|
||||
R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
|
||||
if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) {
|
||||
recordLogService.saveLogs(username,startTime, "登录用户不存在","用户名/密码错误",null,null);
|
||||
throw new ServiceException("用户名/密码错误");
|
||||
}
|
||||
if (R.FAIL == userResult.getCode()) {
|
||||
recordLogService.saveLogs(username, startTime, "系统错误",userResult.getMsg(),null,null);
|
||||
throw new ServiceException(userResult.getMsg());
|
||||
}
|
||||
LoginUser userInfo = userResult.getData();
|
||||
SysUser user = userResult.getData().getSysUser();
|
||||
if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) {
|
||||
recordLogService.saveLogs(username, startTime, "账号已被删除","用户不存在",null,null);
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
if (UserStatus.DISABLE.getCode().equals(user.getStatus())) {
|
||||
recordLogService.saveLogs(username, startTime, "用户已停用","用户不存在",null,null);
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
if(StringUtils.isEmpty(user.getLoginType()) || !user.getLoginType().contains(SecurityConstants.LOGIN_APP)){
|
||||
recordLogService.saveLogs(username, startTime, "当前账号无登录APP权限","当前账号无登录APP权限",null,null);
|
||||
throw new ServiceException("当前账号无登录APP权限");
|
||||
}
|
||||
passwordService.validate(user, password,startTime);
|
||||
recordLogService.saveLogs(username, startTime, "APP登陆成功","APP登陆成功",user.getUserId().toString(),"APP登陆成功");
|
||||
return userInfo;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,4 +46,12 @@ public class SecurityConstants
|
|||
* 角色权限
|
||||
*/
|
||||
public static final String ROLE_PERMISSION = "role_permission";
|
||||
/**
|
||||
* APP登录权限
|
||||
*/
|
||||
public static final String LOGIN_APP = "2";
|
||||
/**
|
||||
* 后台登录权限
|
||||
*/
|
||||
public static final String LOGIN_BACKSTAGE = "1";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,4 +76,9 @@ public class UserConstants {
|
|||
public static final int PASSWORD_MIN_LENGTH = 5;
|
||||
|
||||
public static final int PASSWORD_MAX_LENGTH = 20;
|
||||
|
||||
/**
|
||||
* APP菜单表示
|
||||
*/
|
||||
public static final String APP_NAME = "App子系统";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,6 +92,9 @@ public class CraneMonitorServiceImpl implements ICraneMonitorService {
|
|||
if (CollectionUtils.isEmpty(configItems)) {
|
||||
return AjaxResult.error("配置项不能为空");
|
||||
}
|
||||
if(configItems.size() > 10){
|
||||
return AjaxResult.error("设备配置项不能超过十个");
|
||||
}
|
||||
Set<JdConfigVo.ConfigItems> itemsHashSet = new HashSet<>(configItems);
|
||||
if (itemsHashSet.size() != configItems.size()) {
|
||||
return AjaxResult.error("配置项存在相同数据");
|
||||
|
|
|
|||
|
|
@ -273,6 +273,9 @@ public class ConsControlServiceImpl implements IConsControlService {
|
|||
return AjaxResult.error("时间格式错误(HH:MM)");
|
||||
}
|
||||
}
|
||||
if(timeArr.length > 0){
|
||||
return AjaxResult.error("固定时间验证不能超过时间配置项");
|
||||
}
|
||||
} else if (Objects.equals(vo.getConfigType(), BusinessConstants.CONFIG_TYPE2)) {
|
||||
// 间隔时间验证
|
||||
if (!TimeValidator.isValidTime2(vo.getTime())) {
|
||||
|
|
@ -475,6 +478,9 @@ public class ConsControlServiceImpl implements IConsControlService {
|
|||
if (CollectionUtils.isEmpty(configItems)) {
|
||||
return AjaxResult.error("配置项不能为空");
|
||||
}
|
||||
if(configItems.size() > 10){
|
||||
return AjaxResult.error("设备配置项不能超过十个");
|
||||
}
|
||||
Set<JdConfigVo.ConfigItems> itemsHashSet = new HashSet<>(configItems);
|
||||
if (itemsHashSet.size() != configItems.size()) {
|
||||
return AjaxResult.error("配置项存在相同数据");
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.bonus.system.controller;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.bonus.common.log.annotation.SysLog;
|
||||
import com.bonus.common.log.enums.OperaType;
|
||||
import com.bonus.common.security.annotation.InnerAuth;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
|
@ -181,6 +183,27 @@ public class SysMenuController extends BaseController
|
|||
try{
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
|
||||
// 去除app菜单
|
||||
menus.removeIf(menu -> Objects.equals(menu.getMenuName(),UserConstants.APP_NAME));
|
||||
return success(menuService.buildMenus(menus));
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return error("系统异常");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取App路由信息
|
||||
*
|
||||
* @return 路由信息
|
||||
*/
|
||||
@PostMapping("getAppRouters")
|
||||
@InnerAuth
|
||||
public AjaxResult getAppRouters(@RequestBody Long userId) {
|
||||
try{
|
||||
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
|
||||
// 去除后台菜单
|
||||
menus.removeIf(menu -> !Objects.equals(menu.getMenuName(),UserConstants.APP_NAME));
|
||||
return success(menuService.buildMenus(menus));
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
package com.bonus.system.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
|
@ -186,6 +183,31 @@ public class SysUserController extends BaseController {
|
|||
return error("系统异常,请联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取APP用户信息
|
||||
*
|
||||
* @return 用户信息
|
||||
*/
|
||||
@PostMapping("getAppUserInfo")
|
||||
@InnerAuth
|
||||
public AjaxResult getAppUserInfo(@RequestBody Long userId) {
|
||||
try {
|
||||
Map<Object, Object> map = new HashMap<>(3);
|
||||
SysUser user = userService.selectUserById(userId);
|
||||
// 角色集合
|
||||
Set<String> roles = permissionService.getRolePermission(user);
|
||||
// 权限集合
|
||||
Set<String> permissions = permissionService.getMenuPermission(user);
|
||||
map.put("user",user);
|
||||
map.put("roles",roles);
|
||||
map.put("permissions",permissions);
|
||||
return AjaxResult.success(map);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
}
|
||||
return error("系统异常,请联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户编号获取详细信息
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue