cn.hutool.core.lang.Validator Java Examples

The following examples show how to use cn.hutool.core.lang.Validator. 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: QiniuUtils.java    From qiniu with MIT License 6 votes vote down vote up
/**
 * 下载文件
 *
 * @param url 文件链接
 */
public static void download(String url) {
    // 验证存储路径
    if (Validator.isEmpty(QiniuApplication.getConfigBean().getStoragePath())) {
        // 显示存储路径输入框
        String storagePath = DialogUtils.showInputDialog(null, QiniuValueConsts.CONFIG_DOWNLOAD_PATH,
                Utils.getCurrentWorkDir());
        if (Validator.isEmpty(storagePath)) {
            return;
        }
        QiniuApplication.getConfigBean().setStoragePath(storagePath);
        ConfigUtils.writeConfig();
    }
    final String dest = QiniuApplication.getConfigBean().getStoragePath();
    // 下载文件
    ThreadPool.executor.execute(() -> HttpUtil.downloadFile(url, dest));
}
 
Example #2
Source File: FrontCommentController.java    From SENS with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    //发送通知给对方
    if (StringUtils.equals(SensConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getValue()) && StringUtils.equals(SensConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getValue())) {
        if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
            Map<String, Object> map = new HashMap<>(8);
            map.put("blogTitle", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
            map.put("commentAuthor", lastComment.getCommentAuthor());
            map.put("pageName", post.getPostTitle());
            if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getValue())) {
                map.put("pageUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/article/" + post.getId() + "#comment-id-" + comment.getId());
            } else if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_NOTICE.getValue())) {
                map.put("pageUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/notice/" + post.getId() + "#comment-id-" + comment.getId());
            } else {
                map.put("pageUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getId());
            }
            map.put("commentContent", lastComment.getCommentContent());
            map.put("replyAuthor", comment.getCommentAuthor());
            map.put("replyContent", comment.getCommentContent());
            map.put("blogUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
            mailService.sendTemplateMail(
                    lastComment.getCommentAuthorEmail(), "您在" + SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()) + "的评论有了新回复", map, "common/mail_template/mail_reply.ftl");
        }
    }
}
 
Example #3
Source File: UserServiceImpl.java    From SENS with GNU General Public License v3.0 6 votes vote down vote up
private void basicUserCheck(User user) {
    if (user.getUserName() == null || user.getUserEmail() == null || user.getUserDisplayName() == null) {
        throw new SensBusinessException("请输入完整信息!");
    }
    String userName = user.getUserName();
    userName = userName.trim().replaceAll(" ", "-");
    if (userName.length() < 4 || userName.length() > 20) {
        throw new SensBusinessException("用户名长度为4-20位!");
    }
    if (Strings.isNotEmpty(user.getUserPass())) {
        if (user.getUserPass().length() < 6 || user.getUserPass().length() > 20) {
            throw new SensBusinessException("用户密码为6-20位!");
        }
    }
    if (!Validator.isEmail(user.getUserEmail())) {
        throw new SensBusinessException("电子邮箱格式不合法!");
    }
    if (user.getUserDisplayName().length() < 1 || user.getUserDisplayName().length() > 20) {
        throw new SensBusinessException("昵称为2-20位");
    }
}
 
Example #4
Source File: CommentController.java    From SENS with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    if (StringUtils.equals(SensConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getValue()) && StringUtils.equals(SensConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getValue())) {
        if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
            Map<String, Object> map = new HashMap<>(8);
            map.put("blogTitle", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
            map.put("commentAuthor", lastComment.getCommentAuthor());
            map.put("pageName", post.getPostTitle());
            if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getValue())) {
                map.put("pageUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/article/" + post.getId() + "#comment-id-" + comment.getId());
            } else if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_NOTICE.getValue())) {
                map.put("pageUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/notice/" + post.getId() + "#comment-id-" + comment.getId());
            } else {
                map.put("pageUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getId());
            }
            map.put("commentContent", lastComment.getCommentContent());
            map.put("replyAuthor", user.getUserDisplayName());
            map.put("replyContent", commentContent);
            map.put("blogUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
            mailService.sendTemplateMail(
                    lastComment.getCommentAuthorEmail(), "您在" + SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()) + "的评论有了新回复", map, "common/mail_template/mail_reply.ftl");
        }
    }
}
 
Example #5
Source File: BirthdayValidator.java    From yue-library with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
	String validValue = null;
	if (value instanceof String) {
		validValue = (String) value;
	} else if (value instanceof Date) {
		validValue = DateUtil.formatDate((Date) value);
	} else if (value instanceof TemporalAccessor) {
		validValue = DateUtils.toDateFormatter((TemporalAccessor) value);
	}
	
	if (StringUtils.isNotBlank(validValue)) {
		return Validator.isBirthday(validValue);
	}
	
	if (notNull) {
		return false;
	}
	
	return true;
}
 
Example #6
Source File: ChineseValidator.java    From yue-library with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
	String validValue = null;
	if ((CharUtil.isChar(value) && !CharUtil.isBlankChar((char) value))
			|| (value instanceof String && StrUtil.isNotBlank((String) value))) {
		validValue = StrUtil.toString(value);
	}
	
	if (StringUtils.isNotBlank(validValue)) {
		return Validator.isChinese(validValue);
	}
	
	if (notNull) {
		return false;
	}
	
	return true;
}
 
Example #7
Source File: BlackListController.java    From feiqu-opensource with Apache License 2.0 6 votes vote down vote up
@PostMapping("/manage/add")
@ResponseBody
public BaseResult add(String ip){
    BaseResult result = new BaseResult();
    try {
        if(!Validator.isIpv4(ip)){
            result.setResult(ResultEnum.FAIL);
            result.setMessage("IP格式不正确!");
            return result;
        }
        JedisCommands commands = JedisProviderFactory.getJedisCommands(null);
        commands.sadd(CommonConstant.FQ_BLACK_LIST_REDIS_KEY,ip);
    } catch (Exception e) {
        logger.error("",e);
    }finally {
        JedisProviderFactory.getJedisProvider(null).release();;
    }
    return result;
}
 
Example #8
Source File: CertificateController.java    From Jpom with MIT License 6 votes vote down vote up
/**
 * 获取证书信息
 *
 * @param certModel  实体
 * @param jsonObject json对象
 * @return 错误消息
 */
private String getCertModel(CertModel certModel, JSONObject jsonObject) {
    String id = jsonObject.getString("id");
    String path = jsonObject.getString("path");
    String name = jsonObject.getString("name");
    if (StrUtil.isEmpty(id)) {
        return JsonMessage.getString(400, "请填写证书id");
    }
    if (Validator.isChinese(id)) {
        return JsonMessage.getString(400, "证书id不能使用中文");
    }
    if (StrUtil.isEmpty(name)) {
        return JsonMessage.getString(400, "请填写证书名称");
    }
    if (!whitelistDirectoryService.checkCertificateDirectory(path)) {
        return JsonMessage.getString(400, "请选择正确的项目路径,或者还没有配置白名单");
    }
    certModel.setId(id);
    certModel.setWhitePath(path);
    certModel.setName(name);
    return null;
}
 
Example #9
Source File: IPV6Validator.java    From yue-library with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
	if (StringUtils.isNotBlank(value)) {
		return Validator.isIpv6(value);
	}
	
	if (notNull) {
		return false;
	}
	
	return true;
}
 
Example #10
Source File: PlateNumberValidator.java    From yue-library with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
	if (StringUtils.isNotBlank(value)) {
		return Validator.isPlateNumber(value);
	}
	
	if (notNull) {
		return false;
	}
	
	return true;
}
 
Example #11
Source File: IPV4Validator.java    From yue-library with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
	if (StringUtils.isNotBlank(value)) {
		return Validator.isIpv4(value);
	}
	
	if (notNull) {
		return false;
	}
	
	return true;
}
 
Example #12
Source File: IdCardValidator.java    From yue-library with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
	if (StringUtils.isNotBlank(value)) {
		return Validator.isCitizenId(value);
	}
	
	if (notNull) {
		return false;
	}
	
	return true;
}
 
Example #13
Source File: IpUtil.java    From magic-starter with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 判断我们获取的ip是否是一个符合规则ip
 */
public static boolean isValidIP(String ip) {
	if (StrUtil.isBlank(ip)) {
		return false;
	}

	return Validator.isIpv4(ip);
}
 
Example #14
Source File: ManageEditProjectController.java    From Jpom with MIT License 5 votes vote down vote up
/**
 * 检查项目lib 情况
 *
 * @param id     项目id
 * @param newLib 新路径
 * @return 状态码,400是一定不能操作的,401 是提醒
 */
@RequestMapping(value = "judge_lib.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public String saveProject(String id, String newLib) {
    File file = new File(newLib);
    //  填写的jar路径是一个存在的文件
    if (file.exists() && file.isFile()) {
        return JsonMessage.getString(400, "填写jar目录当前是一个已经存在的文件,请修改");
    }
    ProjectInfoModel exits = projectInfoService.getItem(id);
    if (exits == null) {
        // 创建项目 填写的jar路径是已经存在的文件夹
        if (file.exists()) {
            return JsonMessage.getString(401, "填写jar目录当前已经在,创建成功后会自动同步文件");
        }
    } else {
        // 已经存在的项目
        File oldLib = new File(exits.allLib());
        Path newPath = file.toPath();
        Path oldPath = oldLib.toPath();
        if (newPath.equals(oldPath)) {
            // 新 旧没有变更
            return JsonMessage.getString(200, "");
        }
        if (file.exists()) {
            if (oldLib.exists()) {
                // 新旧jar路径都存在,会自动覆盖新的jar路径中的文件
                return JsonMessage.getString(401, "原jar目录已经存在并且新的jar目录已经存在,保存将覆盖新文件夹并会自动同步原jar目录");
            }
            return JsonMessage.getString(401, "填写jar目录当前已经在,创建成功后会自动同步文件");
        }
    }
    if (Validator.isChinese(newLib)) {
        return JsonMessage.getString(401, "不建议使用中文目录");
    }
    return JsonMessage.getString(200, "");
}
 
Example #15
Source File: UserBasicInfoController.java    From Jpom with MIT License 5 votes vote down vote up
@RequestMapping(value = "save_basicInfo.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public String saveBasicInfo(@ValidatorItem(value = ValidatorRule.EMAIL, msg = "邮箱格式不正确") String email,
                            String dingDing, String workWx, String code) {
    UserModel userModel = getUser();
    userModel = userService.getItem(userModel.getId());
    // 判断是否一样
    if (!StrUtil.equals(email, userModel.getEmail())) {
        Integer cacheCode = CACHE.get(email);
        if (cacheCode == null || !Objects.equals(cacheCode.toString(), code)) {
            return JsonMessage.getString(405, "请输入正确验证码");
        }
    }
    userModel.setEmail(email);
    //
    if (StrUtil.isNotEmpty(dingDing) && !Validator.isUrl(dingDing)) {
        return JsonMessage.getString(405, "请输入正确钉钉地址");
    }
    userModel.setDingDing(dingDing);
    if (StrUtil.isNotEmpty(workWx) && !Validator.isUrl(workWx)) {
        return JsonMessage.getString(405, "请输入正确企业微信地址");
    }
    userModel.setWorkWx(workWx);
    userService.updateItem(userModel);
    setSessionAttribute(LoginInterceptor.SESSION_NAME, userModel);
    return JsonMessage.getString(200, "修改成功");
}
 
Example #16
Source File: CommentController.java    From blog-sharon with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
        if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
            Map<String, Object> map = new HashMap<>(8);
            map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
            map.put("commentAuthor", lastComment.getCommentAuthor());
            map.put("pageName", lastComment.getPost().getPostTitle());

            StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
            if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
                pageUrl.append("/archives/");
            } else {
                pageUrl.append("/p/");
            }
            pageUrl.append(post.getPostUrl());
            pageUrl.append("#comment-id-");
            pageUrl.append(comment.getCommentId());

            map.put("pageUrl",pageUrl.toString());
            map.put("commentContent", lastComment.getCommentContent());
            map.put("replyAuthor", user.getUserDisplayName());
            map.put("replyContent", commentContent);
            map.put("blogUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
            mailService.sendTemplateMail(
                    lastComment.getCommentAuthorEmail(), "您在" + HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "的评论有了新回复", map, "common/mail_template/mail_reply.ftl");
        }
    }
}
 
Example #17
Source File: CommentController.java    From blog-sharon with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
        try {
            if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) {
                Map<String, Object> map = new HashMap<>(6);

                StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
                if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
                    pageUrl.append("/archives/");
                } else {
                    pageUrl.append("/p/");
                }
                pageUrl.append(post.getPostUrl());
                pageUrl.append("#comment-id-");
                pageUrl.append(comment.getCommentId());

                map.put("pageUrl",pageUrl.toString());
                map.put("pageName", post.getPostTitle());
                map.put("commentContent", comment.getCommentContent());
                map.put("blogUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
                map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
                map.put("author", user.getUserDisplayName());
                mailService.sendTemplateMail(
                        comment.getCommentAuthorEmail(),
                        "您在" + HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "的评论已审核通过!", map, "common/mail_template/mail_passed.ftl");
            }
        } catch (Exception e) {
            log.error("Mail server not configured: {}", e.getMessage());
        }
    }
}
 
Example #18
Source File: FrontCommentController.java    From blog-sharon with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    //发送通知给对方
    if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
        if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
            Map<String, Object> map = new HashMap<>(8);
            StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
            if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
                pageUrl.append("/archives/");

            } else {
                pageUrl.append("/p/");
            }
            pageUrl.append(post.getPostUrl());
            pageUrl.append("#comment-id-");
            pageUrl.append(comment.getCommentId());
            map.put("pageUrl",  pageUrl.toString());
            map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
            map.put("commentAuthor", lastComment.getCommentAuthor());
            map.put("pageName", lastComment.getPost().getPostTitle());
            map.put("commentContent", lastComment.getCommentContent());
            map.put("replyAuthor", comment.getCommentAuthor());
            map.put("replyContent", comment.getCommentContent());
            map.put("blogUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
            mailService.sendTemplateMail(
                    lastComment.getCommentAuthorEmail(), "您在" + HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()) + "的评论有了新回复", map, "common/mail_template/mail_reply.ftl");
        }
    }
}
 
Example #19
Source File: AdminServiceImpl.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public User authenticate(LoginParam loginParam) {
    Assert.notNull(loginParam, "Login param must not be null");

    String username = loginParam.getUsername();

    String mismatchTip = "用户名或者密码不正确";

    final User user;

    try {
        // Get user by username or email
        user = Validator.isEmail(username) ?
            userService.getByEmailOfNonNull(username) : userService.getByUsernameOfNonNull(username);
    } catch (NotFoundException e) {
        log.error("Failed to find user by name: " + username, e);
        eventPublisher.publishEvent(new LogEvent(this, loginParam.getUsername(), LogType.LOGIN_FAILED, loginParam.getUsername()));

        throw new BadRequestException(mismatchTip);
    }

    userService.mustNotExpire(user);

    if (!userService.passwordMatch(user, loginParam.getPassword())) {
        // If the password is mismatch
        eventPublisher.publishEvent(new LogEvent(this, loginParam.getUsername(), LogType.LOGIN_FAILED, loginParam.getUsername()));

        throw new BadRequestException(mismatchTip);
    }

    return user;
}
 
Example #20
Source File: AdminServiceImpl.java    From halo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public LoginPreCheckDTO getUserEnv(@NonNull String username) {
    Assert.notNull(username, "username must not be null");

    boolean useMFA = true;
    try {
        final User user = Validator.isEmail(username) ?
            userService.getByEmailOfNonNull(username) : userService.getByUsernameOfNonNull(username);
        useMFA = MFAType.useMFA(user.getMfaType());
    } catch (NotFoundException e) {
        log.error("Failed to find user by name: " + username, e);
        eventPublisher.publishEvent(new LogEvent(this, username, LogType.LOGIN_FAILED, username));
    }
    return new LoginPreCheckDTO(useMFA);
}
 
Example #21
Source File: CommentController.java    From stone with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
    if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
        if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
            final Map<String, Object> map = new HashMap<>(8);
            map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
            map.put("commentAuthor", lastComment.getCommentAuthor());
            map.put("pageName", lastComment.getPost().getPostTitle());

            final StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
            if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
                pageUrl.append("/archives/");
            } else {
                pageUrl.append("/p/");
            }
            pageUrl.append(post.getPostUrl());
            pageUrl.append("#comment-id-");
            pageUrl.append(comment.getCommentId());

            map.put("pageUrl", pageUrl.toString());
            map.put("commentContent", lastComment.getCommentContent());
            map.put("replyAuthor", user.getUserDisplayName());
            map.put("replyContent", commentContent);
            map.put("blogUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
            mailService.sendTemplateMail(
                    lastComment.getCommentAuthorEmail(), "您在" + HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "的评论有了新回复", map, "common/mail_template/mail_reply.ftl");
        }
    }
}
 
Example #22
Source File: CommentController.java    From SENS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
    if (StringUtils.equals(SensConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getValue()) && StringUtils.equals(SensConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getValue())) {
        try {
            //待审核的评论变成已通过,发邮件
            if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) {
                Map<String, Object> map = new HashMap<>(6);
                if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getValue())) {
                    map.put("pageUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/article/" + post.getId() + "#comment-id-" + comment.getId());
                } else if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_NOTICE.getValue())) {
                    map.put("pageUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/notice/" + post.getId() + "#comment-id-" + comment.getId());
                } else {
                    map.put("pageUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getId());
                }
                map.put("pageName", post.getPostTitle());
                map.put("commentContent", comment.getCommentContent());
                map.put("blogUrl", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
                map.put("blogTitle", SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
                map.put("author", user.getUserDisplayName());
                mailService.sendTemplateMail(
                        comment.getCommentAuthorEmail(),
                        "您在" + SensConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()) + "的评论已审核通过!", map, "common/mail_template/mail_passed.ftl");
            }
        } catch (Exception e) {
            log.error("邮件服务器未配置:{}", e.getMessage());
        }
    }
}
 
Example #23
Source File: FreeRealm.java    From SENS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 认证信息(身份验证) Authentication 是用来验证用户身份
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    //1.验证用户名
    User user = null;
    String account = (String) token.getPrincipal();
    if (Validator.isEmail(account)) {
        user = userService.findByEmail(account);
    } else {
        user = userService.findByUserName(account);
    }
    if (user == null) {
        //用户不存在
        log.info("第三方登录,用户不存在! 登录名:{}, 密码:{}", account,token.getCredentials());
        return null;
    }

    //2.判断账号是否被封号
    if (!Objects.equals(user.getStatus(), UserStatusEnum.NORMAL.getCode())) {
        throw new LockedAccountException(localeMessageUtil.getMessage("code.admin.login.disabled.forever"));
    }

    //3.封装authenticationInfo,准备验证密码
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
            user,
            user.getUserPass(),
            null,
            getName()
    );
    return authenticationInfo;
}
 
Example #24
Source File: FqShortVideoController.java    From feiqu-opensource with Apache License 2.0 5 votes vote down vote up
/**
 * ajax添加FqShortVideo
 */
@ResponseBody
@PostMapping("/add")
public Object add(FqShortVideo fqShortVideo) {
    logger.info("视频上传"+JSON.toJSONString(fqShortVideo));
    BaseResult result = new BaseResult();
    try {
        FqUserCache fqUserCache = getCurrentUser();
        if(fqUserCache == null){
            result.setResult(ResultEnum.USER_NOT_LOGIN);
            return result;
        }
        if(!Validator.isUrl(fqShortVideo.getUrl())){
            result.setResult(ResultEnum.PARAM_ERROR);
            return result;
        }
        if(StringUtils.isBlank(fqShortVideo.getTitle())){
            result.setResult(ResultEnum.PARAM_NULL);
            return result;
        }
        fqShortVideo.setDelFlag(YesNoEnum.NO.getValue());
        fqShortVideo.setLikeCount(0);
        fqShortVideo.setCreateTime(new Date());
        fqShortVideo.setUserId(fqUserCache.getId());
        fqShortVideoService.insert(fqShortVideo);
        CommonUtils.addActiveNum(fqUserCache.getId(), ActiveNumEnum.VIDEO_UPLOAD.getValue());
    } catch (Exception e) {
        logger.error("视频上传失败",e);
        result.setResult(ResultEnum.FAIL);
    }
    return result;
}
 
Example #25
Source File: EnglishValidator.java    From yue-library with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
	if (StringUtils.isNotBlank(value)) {
		return Validator.isWord(value);
	}
	
	if (notNull) {
		return false;
	}
	
	return true;
}
 
Example #26
Source File: CommentController.java    From stone with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
    if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
        try {
            if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) {
                final Map<String, Object> map = new HashMap<>(6);

                final StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
                if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
                    pageUrl.append("/archives/");
                } else {
                    pageUrl.append("/p/");
                }
                pageUrl.append(post.getPostUrl());
                pageUrl.append("#comment-id-");
                pageUrl.append(comment.getCommentId());

                map.put("pageUrl", pageUrl.toString());
                map.put("pageName", post.getPostTitle());
                map.put("commentContent", comment.getCommentContent());
                map.put("blogUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
                map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
                map.put("author", user.getUserDisplayName());
                mailService.sendTemplateMail(
                        comment.getCommentAuthorEmail(),
                        "您在" + HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "的评论已审核通过!", map, "common/mail_template/mail_passed.ftl");
            }
        } catch (Exception e) {
            log.error("Mail server not configured: {}", e.getMessage());
        }
    }
}
 
Example #27
Source File: FrontCommentController.java    From stone with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void run() {
    //发送通知给对方
    if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
        if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
            final Map<String, Object> map = new HashMap<>(8);
            final StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
            if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
                pageUrl.append("/archives/");

            } else {
                pageUrl.append("/p/");
            }
            pageUrl.append(post.getPostUrl());
            pageUrl.append("#comment-id-");
            pageUrl.append(comment.getCommentId());
            map.put("pageUrl", pageUrl.toString());
            map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
            map.put("commentAuthor", lastComment.getCommentAuthor());
            map.put("pageName", lastComment.getPost().getPostTitle());
            map.put("commentContent", lastComment.getCommentContent());
            map.put("replyAuthor", comment.getCommentAuthor());
            map.put("replyContent", comment.getCommentContent());
            map.put("blogUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
            mailService.sendTemplateMail(
                    lastComment.getCommentAuthorEmail(), "您在" + HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()) + "的评论有了新回复", map, "common/mail_template/mail_reply.ftl");
        }
    }
}
 
Example #28
Source File: UUIDValidator.java    From yue-library with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
	if (StringUtils.isNotBlank(value)) {
		return Validator.isUUID(value);
	}
	
	if (notNull) {
		return false;
	}
	
	return true;
}
 
Example #29
Source File: MacAddressValidator.java    From yue-library with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
	if (StringUtils.isNotBlank(value)) {
		return Validator.isMac(value);
	}
	
	if (notNull) {
		return false;
	}
	
	return true;
}
 
Example #30
Source File: CellphoneValidator.java    From yue-library with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
	if (StringUtils.isNotBlank(value)) {
		return Validator.isMobile(value);
	}
	
	if (notNull) {
		return false;
	}
	
	return true;
}