com.ruoyi.common.utils.MessageUtils Java Examples
The following examples show how to use
com.ruoyi.common.utils.MessageUtils.
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: PermissionUtils.java From RuoYi with Apache License 2.0 | 6 votes |
/** * 权限错误消息提醒 * * @param permissionsStr 错误信息 * @return 提示信息 */ public static String getMsg(String permissionsStr) { String permission = StringUtils.substringBetween(permissionsStr, "[", "]"); String msg = MessageUtils.message(PERMISSION, permission); if (StrUtil.endWithIgnoreCase(permission, PermissionConstants.ADD_PERMISSION)) { msg = MessageUtils.message(CREATE_PERMISSION, permission); } else if (StrUtil.endWithIgnoreCase(permission, PermissionConstants.EDIT_PERMISSION)) { msg = MessageUtils.message(UPDATE_PERMISSION, permission); } else if (StrUtil.endWithIgnoreCase(permission, PermissionConstants.REMOVE_PERMISSION)) { msg = MessageUtils.message(DELETE_PERMISSION, permission); } else if (StrUtil.endWithIgnoreCase(permission, PermissionConstants.EXPORT_PERMISSION)) { msg = MessageUtils.message(EXPORT_PERMISSION, permission); } else if (StrUtil.endWithAny(permission, PermissionConstants.VIEW_PERMISSION, PermissionConstants.LIST_PERMISSION)) { msg = MessageUtils.message(VIEW_PERMISSION, permission); } return msg; }
Example #3
Source File: LogoutFilter.java From supplierShop with MIT License | 5 votes |
@Override protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception { try { Subject subject = getSubject(request, response); String redirectUrl = getRedirectUrl(request, response, subject); try { SysUser user = ShiroUtils.getSysUser(); if (StringUtils.isNotNull(user)) { String loginName = user.getLoginName(); // 记录用户退出日志 AsyncManager.me().execute(AsyncFactory.recordLogininfor(loginName, Constants.LOGOUT, MessageUtils.message("user.logout.success"))); // 清理缓存 cache.remove(loginName); } // 退出登录 subject.logout(); } catch (SessionException ise) { log.error("logout fail.", ise); } issueRedirect(request, response, redirectUrl); } catch (Exception e) { log.error("Encountered session exception during logout. This can generally safely be ignored.", e); } return false; }
Example #4
Source File: PermissionUtils.java From supplierShop with MIT License | 5 votes |
/** * 权限错误消息提醒 * * @param permissionsStr 错误信息 * @return 提示信息 */ public static String getMsg(String permissionsStr) { String permission = StringUtils.substringBetween(permissionsStr, "[", "]"); String msg = MessageUtils.message(PERMISSION, permission); if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.ADD_PERMISSION)) { msg = MessageUtils.message(CREATE_PERMISSION, permission); } else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EDIT_PERMISSION)) { msg = MessageUtils.message(UPDATE_PERMISSION, permission); } else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.REMOVE_PERMISSION)) { msg = MessageUtils.message(DELETE_PERMISSION, permission); } else if (StringUtils.endsWithIgnoreCase(permission, PermissionConstants.EXPORT_PERMISSION)) { msg = MessageUtils.message(EXPORT_PERMISSION, permission); } else if (StringUtils.endsWithAny(permission, new String[] { PermissionConstants.VIEW_PERMISSION, PermissionConstants.LIST_PERMISSION })) { msg = MessageUtils.message(VIEW_PERMISSION, permission); } return msg; }
Example #5
Source File: BaseException.java From supplierShop with MIT License | 5 votes |
@Override public String getMessage() { String message = null; if (!StringUtils.isEmpty(code)) { message = MessageUtils.message(code, args); } if (message == null) { message = defaultMessage; } return message; }
Example #6
Source File: BaseException.java From RuoYi-Vue with MIT License | 5 votes |
@Override public String getMessage() { String message = null; if (!StringUtils.isEmpty(code)) { message = MessageUtils.message(code, args); } if (message == null) { message = defaultMessage; } return message; }
Example #7
Source File: BaseException.java From RuoYi with Apache License 2.0 | 5 votes |
@Override public String getMessage() { String message = null; if (!StrUtil.isEmpty(code)) { message = MessageUtils.message(code, args); } if (message == null) { message = defaultMessage; } return message; }
Example #8
Source File: SysLoginService.java From supplierShop with MIT License | 4 votes |
/** * 登录 */ public SysUser login(String username, String password) { // 验证码校验 // if (!StringUtils.isEmpty(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA))) // { // AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); // throw new CaptchaException(); // } // 用户名或密码为空 错误 if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null"))); throw new UserNotExistsException(); } // 密码如果不在指定范围内 错误 if (password.length() < UserConstants.PASSWORD_MIN_LENGTH || password.length() > UserConstants.PASSWORD_MAX_LENGTH) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); throw new UserPasswordNotMatchException(); } // 用户名不在指定范围内 错误 if (username.length() < UserConstants.USERNAME_MIN_LENGTH || username.length() > UserConstants.USERNAME_MAX_LENGTH) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); throw new UserPasswordNotMatchException(); } // 查询用户信息 SysUser user = userService.selectUserByLoginName(username); if (user == null && maybeMobilePhoneNumber(username)) { user = userService.selectUserByPhoneNumber(username); } if (user == null && maybeEmail(username)) { user = userService.selectUserByEmail(username); } if (user == null) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.not.exists"))); throw new UserNotExistsException(); } if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.delete"))); throw new UserDeleteException(); } if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.blocked", user.getRemark()))); throw new UserBlockedException(); } passwordService.validate(user, password); AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); recordLoginInfo(user); return user; }
Example #9
Source File: SysLoginService.java From RuoYi-Vue with MIT License | 4 votes |
/** * 登录验证 * * @param username 用户名 * @param password 密码 * @param captcha 验证码 * @param uuid 唯一标识 * @return 结果 */ public String login(String username, String password, String code, String uuid) { String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; String captcha = redisCache.getCacheObject(verifyKey); redisCache.deleteObject(verifyKey); if (captcha == null) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.expire"))); throw new CaptchaExpireException(); } if (!code.equalsIgnoreCase(captcha)) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); throw new CaptchaException(); } // 用户验证 Authentication authentication = null; try { // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername authentication = authenticationManager .authenticate(new UsernamePasswordAuthenticationToken(username, password)); } catch (Exception e) { if (e instanceof BadCredentialsException) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); throw new UserPasswordNotMatchException(); } else { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage())); throw new CustomException(e.getMessage()); } } AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); LoginUser loginUser = (LoginUser) authentication.getPrincipal(); // 生成token return tokenService.createToken(loginUser); }
Example #10
Source File: SysLoginService.java From RuoYi with Apache License 2.0 | 4 votes |
/** * 登录 */ public SysUser login(String username, String password) { // 验证码校验 if (ObjectUtil.isNotEmpty(ServletUtils.getRequest().getAttribute(ShiroConstants.CURRENT_CAPTCHA))) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.jcaptcha.error"))); throw new CaptchaException(); } // 用户名或密码为空 错误 if (StrUtil.isEmpty(username) || StrUtil.isEmpty(password)) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("not.null"))); throw new UserNotExistsException(); } // 密码如果不在指定范围内 错误 if (password.length() < UserConstants.PASSWORD_MIN_LENGTH || password.length() > UserConstants.PASSWORD_MAX_LENGTH) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); throw new UserPasswordNotMatchException(); } // 用户名不在指定范围内 错误 if (username.length() < UserConstants.USERNAME_MIN_LENGTH || username.length() > UserConstants.USERNAME_MAX_LENGTH) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match"))); throw new UserPasswordNotMatchException(); } // 查询用户信息 SysUser user = userService.selectUserByLoginName(username); if (user == null && maybeMobilePhoneNumber(username)) { user = userService.selectUserByPhoneNumber(username); } if (user == null && maybeEmail(username)) { user = userService.selectUserByEmail(username); } if (user == null) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.not.exists"))); throw new UserNotExistsException(); } if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.delete"))); throw new UserDeleteException(); } if (UserStatus.DISABLE.getCode().equals(user.getStatus())) { AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.blocked" , user.getRemark()))); throw new UserBlockedException(); } passwordService.validate(user, password); AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); recordLoginInfo(user); return user; }