com.ruoyi.system.domain.SysUser Java Examples
The following examples show how to use
com.ruoyi.system.domain.SysUser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogoutFilter.java From RuoYi with Apache License 2.0 | 6 votes |
@Override protected boolean preHandle(ServletRequest request, ServletResponse response){ try { Subject subject = getSubject(request, response); String redirectUrl = getRedirectUrl(request, response, subject); SysUser user = ShiroUtils.getSysUser(); if (ObjectUtil.isNotNull(user)) { String loginName = user.getLoginName(); // 记录用户退出日志 AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success"))); // 清理缓存 cache.remove(loginName); } // 退出登录 subject.logout(); issueRedirect(request, response, redirectUrl); } catch (Exception e) { log.error("Encountered session exception during logout. This can generally safely be ignored." , e); } return false; }
Example #2
Source File: SysUserServiceImpl.java From supplierShop with MIT License | 6 votes |
/** * 修改保存用户信息 * * @param user 用户信息 * @return 结果 */ @Override @Transactional public int updateUser(SysUser user) { Long userId = user.getUserId(); // 删除用户与角色关联 userRoleMapper.deleteUserRoleByUserId(userId); // 新增用户与角色管理 insertUserRole(user); // 删除用户与岗位关联 userPostMapper.deleteUserPostByUserId(userId); // 新增用户与岗位管理 insertUserPost(user); return userMapper.updateUser(user); }
Example #3
Source File: DataScopeAspect.java From ruoyiplus with MIT License | 6 votes |
protected void handleDataScope(final JoinPoint joinPoint) { // 获得注解 DataScope controllerDataScope = getAnnotationLog(joinPoint); if (controllerDataScope == null) { return; } // 获取当前的用户 SysUser currentUser = ShiroUtils.getSysUser(); if (currentUser != null) { // 如果是超级管理员,则不过滤数据 if (!currentUser.isAdmin()) { dataScopeFilter(joinPoint, currentUser, controllerDataScope.tableAlias()); } } }
Example #4
Source File: SysUserController.java From supplierShop with MIT License | 6 votes |
/** * 修改保存用户 */ @RequiresPermissions("system:user:edit") @Log(title = "用户管理", businessType = BusinessType.UPDATE) @PostMapping("/edit") @ResponseBody public AjaxResult editSave(@Validated SysUser user) { if (StringUtils.isNotNull(user.getUserId()) && SysUser.isAdmin(user.getUserId())) { return error("不允许修改超级管理员用户"); } else if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) { return error("修改用户'" + user.getLoginName() + "'失败,手机号码已存在"); } else if (UserConstants.USER_EMAIL_NOT_UNIQUE.equals(userService.checkEmailUnique(user))) { return error("修改用户'" + user.getLoginName() + "'失败,邮箱账号已存在"); } user.setUpdateBy(ShiroUtils.getLoginName()); return toAjax(userService.updateUser(user)); }
Example #5
Source File: SysUserController.java From supplierShop with MIT License | 6 votes |
@RequiresPermissions("system:user:resetPwd") @Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwdSave(SysUser user) { user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); if (userService.resetUserPwd(user) > 0) { if (ShiroUtils.getUserId() == user.getUserId()) { ShiroUtils.setSysUser(userService.selectUserById(user.getUserId())); } return success(); } return error(); }
Example #6
Source File: SysUserController.java From ruoyiplus with MIT License | 6 votes |
/** * 新增保存用户 */ @RequiresPermissions("system:user:add") @Log(title = "用户管理", businessType = BusinessType.INSERT) @PostMapping("/add") @Transactional(rollbackFor = Exception.class) @ResponseBody public AjaxResult addSave(SysUser user) { if (StringUtils.isNotNull(user.getUserId()) && SysUser.isAdmin(user.getUserId())) { return error("不允许修改超级管理员用户"); } user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); user.setCreateBy(ShiroUtils.getLoginName()); return toAjax(userService.insertUser(user)); }
Example #7
Source File: UserRealm.java From RuoYi with Apache License 2.0 | 6 votes |
/** * 授权 */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0) { SysUser user = ShiroUtils.getSysUser(); SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); // 管理员拥有所有权限 if (user.isAdmin()) { info.addRole("admin"); info.addStringPermission("*:*:*"); } else { // 角色列表 Set<String> roles = roleService.selectRoleKeys(user.getUserId()); // 功能列表 Set<String> menus = menuService.selectPermsByUserId(user.getUserId()); // 角色加入AuthorizationInfo认证对象 info.setRoles(roles); // 权限加入AuthorizationInfo认证对象 info.setStringPermissions(menus); } return info; }
Example #8
Source File: SysMenuServiceImpl.java From supplierShop with MIT License | 6 votes |
/** * 查询菜单集合 * * @return 所有菜单信息 */ @Override public List<SysMenu> selectMenuList(SysMenu menu, Long userId) { List<SysMenu> menuList = null; if (SysUser.isAdmin(userId)) { menuList = menuMapper.selectMenuList(menu); } else { menu.getParams().put("userId", userId); menuList = menuMapper.selectMenuListByUserId(menu); } return menuList; }
Example #9
Source File: SysProfileController.java From supplierShop with MIT License | 6 votes |
@Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwd(String oldPassword, String newPassword) { SysUser user = ShiroUtils.getSysUser(); if (StringUtils.isNotEmpty(newPassword) && passwordService.matches(user, oldPassword)) { user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), newPassword, user.getSalt())); if (userService.resetUserPwd(user) > 0) { ShiroUtils.setSysUser(userService.selectUserById(user.getUserId())); return success(); } return error(); } else { return error("修改密码失败,旧密码错误"); } }
Example #10
Source File: SysUserController.java From supplierShop with MIT License | 5 votes |
/** * 校验email邮箱 */ @PostMapping("/checkEmailUnique") @ResponseBody public String checkEmailUnique(SysUser user) { return userService.checkEmailUnique(user); }
Example #11
Source File: SysUserController.java From ruoyiplus with MIT License | 5 votes |
/** * 校验手机号码 */ @PostMapping("/checkPhoneUnique") @ResponseBody public String checkPhoneUnique(SysUser user) { return userService.checkPhoneUnique(user); }
Example #12
Source File: SysUserController.java From RuoYi with Apache License 2.0 | 5 votes |
@RequiresPermissions("system:user:view") @GetMapping("/importTemplate") @ResponseBody public AjaxResult importTemplate(){ ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class); return util.importTemplateExcel("用户信息导入模版"); }
Example #13
Source File: SysRoleController.java From supplierShop with MIT License | 5 votes |
/** * 查询已分配用户角色列表 */ @RequiresPermissions("system:role:list") @PostMapping("/authUser/allocatedList") @ResponseBody public TableDataInfo allocatedList(SysUser user) { startPage(); List<SysUser> list = userService.selectAllocatedList(user); return getDataTable(list); }
Example #14
Source File: SysUserController.java From RuoYi with Apache License 2.0 | 5 votes |
@Log(title = "用户管理", businessType = BusinessType.EXPORT) @RequiresPermissions("system:user:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysUser user) { List<SysUser> list = userService.selectUserList(user); ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class); return util.exportExcel(list, "用户信息"); }
Example #15
Source File: SysUserController.java From supplierShop with MIT License | 5 votes |
@Log(title = "用户管理", businessType = BusinessType.IMPORT) @RequiresPermissions("system:user:import") @PostMapping("/importData") @ResponseBody public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); List<SysUser> userList = util.importExcel(file.getInputStream()); String operName = ShiroUtils.getSysUser().getLoginName(); String message = userService.importUser(userList, updateSupport, operName); return AjaxResult.success(message); }
Example #16
Source File: SysProfileController.java From supplierShop with MIT License | 5 votes |
/** * 个人信息 */ @GetMapping() public String profile(ModelMap mmap) { SysUser user = ShiroUtils.getSysUser(); mmap.put("user", user); mmap.put("roleGroup", userService.selectUserRoleGroup(user.getUserId())); mmap.put("postGroup", userService.selectUserPostGroup(user.getUserId())); return prefix + "/profile"; }
Example #17
Source File: SysProfileController.java From supplierShop with MIT License | 5 votes |
@GetMapping("/checkPassword") @ResponseBody public boolean checkPassword(String password) { SysUser user = ShiroUtils.getSysUser(); if (passwordService.matches(user, password)) { return true; } return false; }
Example #18
Source File: SysProfileController.java From supplierShop with MIT License | 5 votes |
/** * 修改用户 */ @GetMapping("/edit") public String edit(ModelMap mmap) { SysUser user = ShiroUtils.getSysUser(); mmap.put("user", userService.selectUserById(user.getUserId())); return prefix + "/edit"; }
Example #19
Source File: DataScopeAspect.java From RuoYi with Apache License 2.0 | 5 votes |
/** * 数据范围过滤 */ private static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String alias) { StringBuilder sqlString = new StringBuilder(); for (SysRole role : user.getRoles()) { String dataScope = role.getDataScope(); if (DATA_SCOPE_ALL.equals(dataScope)) { sqlString = new StringBuilder(); break; } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) { sqlString.append(String.format( " OR %s.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = %d ) " , alias, role.getRoleId())); }else if (DATA_SCOPE_DEPT.equals(dataScope)){ sqlString.append(String.format(" OR %s.dept_id = %d ", alias, user.getDeptId())); }else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)){ String deptChild = user.getDept().getParentId() + "," + user.getDeptId(); sqlString.append(String.format( " OR %s.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = %d or ancestors LIKE '%%%s%%' )", alias, user.getDeptId(), deptChild)); } } if (StrUtil.isNotBlank(sqlString.toString())) { BaseEntity baseEntity = (BaseEntity) joinPoint.getArgs()[0]; baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); } }
Example #20
Source File: SysProfileController.java From supplierShop with MIT License | 5 votes |
/** * 保存头像 */ @Log(title = "个人信息", businessType = BusinessType.UPDATE) @PostMapping("/updateAvatar") @ResponseBody public AjaxResult updateAvatar(@RequestParam("avatarfile") MultipartFile file) { SysUser currentUser = ShiroUtils.getSysUser(); try { if (!file.isEmpty()) { String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file); currentUser.setAvatar(avatar); if (userService.updateUserInfo(currentUser) > 0) { ShiroUtils.setSysUser(userService.selectUserById(currentUser.getUserId())); return success(); } } return error(); } catch (Exception e) { log.error("修改头像失败!", e); return error(e.getMessage()); } }
Example #21
Source File: SysUserController.java From RuoYi with Apache License 2.0 | 5 votes |
@ApiOperation("重置密码") @ApiImplicitParam(name = "user", value = "修改用户信息", dataType = "SysUser") @RequiresPermissions("system:user:resetPwd") @Log(title = "重置密码", businessType = BusinessType.UPDATE) @PostMapping("/resetPwd") @ResponseBody public AjaxResult resetPwdSave(SysUser user) { user.setSalt(ShiroUtils.randomSalt()); user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt())); return toAjax(userService.resetUserPwd(user)); }
Example #22
Source File: LoginUserArgumentResolver.java From RuoYi with Apache License 2.0 | 5 votes |
@Override public boolean supportsParameter(MethodParameter methodParameter) { final Method method = methodParameter.getMethod(); final Class<?> clazz = Objects.requireNonNull(methodParameter.getMethod()).getDeclaringClass(); boolean isHasLoginAuthAnn = clazz.isAnnotationPresent(LoginAuth.class) || Objects.requireNonNull(method).isAnnotationPresent(LoginAuth.class); boolean isHasLoginUserParameter = methodParameter.getParameterType().isAssignableFrom(SysUser.class); return isHasLoginAuthAnn && isHasLoginUserParameter; }
Example #23
Source File: SysUserController.java From ruoyiplus with MIT License | 5 votes |
@Log(title = "用户管理", businessType = BusinessType.EXPORT) @RequiresPermissions("system:user:export") @PostMapping("/export") @ResponseBody public AjaxResult export(SysUser user) { List<SysUser> list = userService.selectUserList(user); ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class); return util.exportExcel(list, "用户数据"); }
Example #24
Source File: SysUserController.java From ruoyiplus with MIT License | 5 votes |
/** * 校验用户名 */ @PostMapping("/checkLoginNameUnique") @ResponseBody public String checkLoginNameUnique(SysUser user) { return userService.checkLoginNameUnique(user.getLoginName()); }
Example #25
Source File: SysProfileController.java From ruoyiplus with MIT License | 5 votes |
/** * 修改用户 */ @GetMapping("/edit") public String edit(ModelMap mmap) { SysUser user = getSysUser(); mmap.put("user", userService.selectUserById(user.getUserId())); return prefix + "/edit"; }
Example #26
Source File: DataScopeAspect.java From ruoyiplus with MIT License | 5 votes |
/** * 数据范围过滤 * @param joinPoint 切点 * @param user 用户 * @param alias 别名 */ public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String alias) { StringBuilder sqlString = new StringBuilder(); for (SysRole role : user.getRoles()) { String dataScope = role.getDataScope(); if (DATA_SCOPE_ALL.equals(dataScope)) { sqlString = new StringBuilder(); break; } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) { sqlString.append(StringUtils.format( " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", alias, role.getRoleId())); } } if (StringUtils.isNotBlank(sqlString.toString())) { BaseEntity baseEntity = (BaseEntity) joinPoint.getArgs()[0]; baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")"); } }
Example #27
Source File: LoginAuthInterceptor.java From RuoYi with Apache License 2.0 | 5 votes |
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){ if (handler instanceof HandlerMethod) { final HandlerMethod handlerMethod = (HandlerMethod) handler; final Class<?> clazz = handlerMethod.getBeanType(); final Method method = handlerMethod.getMethod(); if (clazz.isAnnotationPresent(LoginAuth.class) || method.isAnnotationPresent(LoginAuth.class)) { SysUser loginUser = ShiroUtils.getSysUser(); return ObjectUtil.isNotNull(loginUser); } } return true; }
Example #28
Source File: UserRealm.java From ruoyiplus with MIT License | 5 votes |
/** * 授权 */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection arg0) { SysUser user = ShiroUtils.getSysUser(); // 角色列表 Set<String> roles = new HashSet<String>(); // 功能列表 Set<String> menus = new HashSet<String>(); SimpleAuthorizationInfo info = new SimpleAuthorizationInfo(); // 管理员拥有所有权限 if (user.isAdmin()) { info.addRole("admin"); info.addStringPermission("*:*:*"); } else { roles = roleService.selectRoleKeys(user.getUserId()); menus = menuService.selectPermsByUserId(user.getUserId()); // 角色加入AuthorizationInfo认证对象 info.setRoles(roles); // 权限加入AuthorizationInfo认证对象 info.setStringPermissions(menus); } return info; }
Example #29
Source File: ShiroUtils.java From RuoYi with Apache License 2.0 | 5 votes |
public static void setSysUser(SysUser user) { Subject subject = getSubject(); PrincipalCollection principalCollection = subject.getPrincipals(); String realmName = principalCollection.getRealmNames().iterator().next(); PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName); // 重新加载Principal subject.runAs(newPrincipalCollection); }
Example #30
Source File: SysUserController.java From ruoyiplus with MIT License | 5 votes |
/** * 校验email邮箱 */ @PostMapping("/checkEmailUnique") @ResponseBody public String checkEmailUnique(SysUser user) { return userService.checkEmailUnique(user); }