Java Code Examples for cn.hutool.core.util.ObjectUtil#equal()

The following examples show how to use cn.hutool.core.util.ObjectUtil#equal() . 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: MessageEventHandler.java    From spring-boot-demo with MIT License 6 votes vote down vote up
@OnEvent(value = Event.GROUP)
public void onGroupEvent(SocketIOClient client, AckRequest request, GroupMessageRequest data) {
    Collection<SocketIOClient> clients = server.getRoomOperations(data.getGroupId()).getClients();

    boolean inGroup = false;
    for (SocketIOClient socketIOClient : clients) {
        if (ObjectUtil.equal(socketIOClient.getSessionId(), client.getSessionId())) {
            inGroup = true;
            break;
        }
    }
    if (inGroup) {
        log.info("群号 {} 收到来自 {} 的群聊消息:{}", data.getGroupId(), data.getFromUid(), data.getMessage());
        sendToGroup(data);
    } else {
        request.sendAckData("请先加群!");
    }
}
 
Example 2
Source File: MessageEventHandler.java    From spring-boot-demo with MIT License 6 votes vote down vote up
@OnEvent(value = Event.GROUP)
public void onGroupEvent(SocketIOClient client, AckRequest request, GroupMessageRequest data) {
    Collection<SocketIOClient> clients = server.getRoomOperations(data.getGroupId()).getClients();

    boolean inGroup = false;
    for (SocketIOClient socketIOClient : clients) {
        if (ObjectUtil.equal(socketIOClient.getSessionId(), client.getSessionId())) {
            inGroup = true;
            break;
        }
    }
    if (inGroup) {
        log.info("群号 {} 收到来自 {} 的群聊消息:{}", data.getGroupId(), data.getFromUid(), data.getMessage());
        sendToGroup(data);
    } else {
        request.sendAckData("请先加群!");
    }
}
 
Example 3
Source File: MessageEventHandler.java    From spring-boot-demo with MIT License 6 votes vote down vote up
@OnEvent(value = Event.GROUP)
public void onGroupEvent(SocketIOClient client, AckRequest request, GroupMessageRequest data) {
    Collection<SocketIOClient> clients = server.getRoomOperations(data.getGroupId()).getClients();

    boolean inGroup = false;
    for (SocketIOClient socketIOClient : clients) {
        if (ObjectUtil.equal(socketIOClient.getSessionId(), client.getSessionId())) {
            inGroup = true;
            break;
        }
    }
    if (inGroup) {
        log.info("群号 {} 收到来自 {} 的群聊消息:{}", data.getGroupId(), data.getFromUid(), data.getMessage());
        sendToGroup(data);
    } else {
        request.sendAckData("请先加群!");
    }
}
 
Example 4
Source File: EmailMessageSender.java    From magic-starter with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 数据校验
 *
 * @param message 消息实体
 */
@Override
protected void validate(EmailMessage message) {
	if (ObjectUtil.equal(message.getEmailType(), EmailType.SIMPLE)) {
		AssertUtil.isNotEmpty(message.getAttachments(), "简单邮件不支持附件,请更换复杂邮件类型");
		AssertUtil.isNotEmpty(message.getStaticResources(), "简单邮件不支持静态资源,请更换复杂邮件类型");
	}
}
 
Example 5
Source File: PageController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 跳转到 登录页
 *
 * @param redirect 是否是跳转回来的
 */
@GetMapping("/login")
public ModelAndView login(Boolean redirect) {
    ModelAndView mv = new ModelAndView();

    if (ObjectUtil.isNotNull(redirect) && ObjectUtil.equal(true, redirect)) {
        mv.addObject("message", "请先登录!");
    }
    mv.setViewName("login");
    return mv;
}
 
Example 6
Source File: PageController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 跳转到 登录页
 *
 * @param redirect 是否是跳转回来的
 */
@GetMapping("/login")
public ModelAndView login(Boolean redirect) {
    ModelAndView mv = new ModelAndView();

    if (ObjectUtil.isNotNull(redirect) && ObjectUtil.equal(true, redirect)) {
        mv.addObject("message", "请先登录!");
    }
    mv.setViewName("login");
    return mv;
}
 
Example 7
Source File: PageController.java    From spring-boot-demo with MIT License 5 votes vote down vote up
/**
 * 跳转到 登录页
 *
 * @param redirect 是否是跳转回来的
 */
@GetMapping("/login")
public ModelAndView login(Boolean redirect) {
    ModelAndView mv = new ModelAndView();

    if (ObjectUtil.isNotNull(redirect) && ObjectUtil.equal(true, redirect)) {
        mv.addObject("message", "请先登录!");
    }
    mv.setViewName("login");
    return mv;
}
 
Example 8
Source File: AdminController.java    From stone with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 验证登录信息
 *
 * @param loginName 登录名:邮箱/用户名
 * @param loginPwd  loginPwd 密码
 * @param session   session session
 *
 * @return JsonResult JsonResult
 */
@PostMapping(value = "/getLogin")
@ResponseBody
public JsonResult getLogin(@ModelAttribute("loginName") String loginName,
                           @ModelAttribute("loginPwd") String loginPwd,
                           HttpSession session) {
    //已注册账号,单用户,只有一个
    final User aUser = userService.findUser();
    //首先判断是否已经被禁用已经是否已经过了10分钟
    Date loginLast = DateUtil.date();
    if (null != aUser.getLoginLast()) {
        loginLast = aUser.getLoginLast();
    }
    final Long between = DateUtil.between(loginLast, DateUtil.date(), DateUnit.MINUTE);
    if (StrUtil.equals(aUser.getLoginEnable(), TrueFalseEnum.FALSE.getDesc()) && (between < CommonParamsEnum.TEN.getValue())) {
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.login.disabled"));
    }
    //验证用户名和密码
    User user = null;
    if (Validator.isEmail(loginName)) {
        user = userService.userLoginByEmail(loginName, SecureUtil.md5(loginPwd));
    } else {
        user = userService.userLoginByName(loginName, SecureUtil.md5(loginPwd));
    }
    userService.updateUserLoginLast(DateUtil.date());
    //判断User对象是否相等
    if (ObjectUtil.equal(aUser, user)) {
        session.setAttribute(HaloConst.USER_SESSION_KEY, aUser);
        //重置用户的登录状态为正常
        userService.updateUserNormal();
        logsService.save(LogsRecord.LOGIN, LogsRecord.LOGIN_SUCCESS, request);
        log.info("User {} login succeeded.", aUser.getUserDisplayName());
        return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.login.success"));
    } else {
        //更新失败次数
        final Integer errorCount = userService.updateUserLoginError();
        //超过五次禁用账户
        if (errorCount >= CommonParamsEnum.FIVE.getValue()) {
            userService.updateUserLoginEnable(TrueFalseEnum.FALSE.getDesc());
        }
        logsService.save(LogsRecord.LOGIN, LogsRecord.LOGIN_ERROR + "[" + HtmlUtil.escape(loginName) + "," + HtmlUtil.escape(loginPwd) + "]", request);
        final Object[] args = {(5 - errorCount)};
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.login.failed", args));
    }
}
 
Example 9
Source File: AdminController.java    From blog-sharon with Apache License 2.0 4 votes vote down vote up
/**
 * 验证登录信息
 *
 * @param loginName 登录名:邮箱/用户名
 * @param loginPwd  loginPwd 密码
 * @param session   session session
 * @return JsonResult JsonResult
 */
@PostMapping(value = "/getLogin")
@ResponseBody
public JsonResult getLogin(@ModelAttribute("loginName") String loginName,
                           @ModelAttribute("loginPwd") String loginPwd,
                           HttpSession session) {
    //已注册账号,单用户,只有一个
    User aUser = userService.findUser();
    //首先判断是否已经被禁用已经是否已经过了10分钟
    Date loginLast = DateUtil.date();
    if (null != aUser.getLoginLast()) {
        loginLast = aUser.getLoginLast();
    }
    Long between = DateUtil.between(loginLast, DateUtil.date(), DateUnit.MINUTE);
    if (StrUtil.equals(aUser.getLoginEnable(), TrueFalseEnum.FALSE.getDesc()) && (between < CommonParamsEnum.TEN.getValue())) {
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.login.disabled"));
    }
    //验证用户名和密码
    User user = null;
    if (Validator.isEmail(loginName)) {
        user = userService.userLoginByEmail(loginName, SecureUtil.md5(loginPwd));
    } else {
        user = userService.userLoginByName(loginName, SecureUtil.md5(loginPwd));
    }
    userService.updateUserLoginLast(DateUtil.date());
    //判断User对象是否相等
    if (ObjectUtil.equal(aUser, user)) {
        session.setAttribute(HaloConst.USER_SESSION_KEY, aUser);
        //重置用户的登录状态为正常
        userService.updateUserNormal();
        logsService.save(LogsRecord.LOGIN, LogsRecord.LOGIN_SUCCESS, request);
        log.info("User {} login succeeded.", aUser.getUserDisplayName());
        return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.login.success"));
    } else {
        //更新失败次数
        Integer errorCount = userService.updateUserLoginError();
        //超过五次禁用账户
        if (errorCount >= CommonParamsEnum.FIVE.getValue()) {
            userService.updateUserLoginEnable(TrueFalseEnum.FALSE.getDesc());
        }
        logsService.save(LogsRecord.LOGIN, LogsRecord.LOGIN_ERROR + "[" + HtmlUtil.escape(loginName) + "," + HtmlUtil.escape(loginPwd) + "]", request);
        Object[] args = {(5 - errorCount)};
        return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.login.failed", args));
    }
}