HttpServletRequest request,
@Valid @ModelAttribute("form") AddTopicRequest form,
BindingResult errors,
@ModelAttribute("ipBlockInfo") IPBlockInfo ipBlockInfo
) throws Exception {
Template tmpl = Template.getTemplate(request);
HttpSession session = request.getSession();
String image = processUploadImage(request);
Group group = form.getGroup();
Map<String, Object> params = new HashMap<>();
params.putAll(prepareModel(form, tmpl.getCurrentUser()));
Section section = null;
if (group!=null) {
section = sectionService.getSection(group.getSectionId());
}
User user = postingUser(tmpl, form);
user.checkBlocked(errors);
IPBlockDao.checkBlockIP(ipBlockInfo, errors, user);
if (group!=null && !groupPermissionService.isTopicPostingAllowed(group, user)) {
errors.reject(null, "Недостаточно прав для постинга тем в эту группу");
}
String message = processMessage(form.getMsg(), form.getMode());
if (user.isAnonymous()) {
if (message.length() > MAX_MESSAGE_LENGTH_ANONYMOUS) {
errors.rejectValue("msg", null, "Слишком большое сообщение");
}
} else {
if (message.length() > MAX_MESSAGE_LENGTH) {
errors.rejectValue("msg", null, "Слишком большое сообщение");
}
}
Screenshot scrn = null;
if (section!=null && groupPermissionService.isImagePostingAllowed(section, tmpl.getCurrentUser())) {
scrn = processUpload(session, image, errors);
if (section.isImagepost() && scrn == null && !errors.hasErrors()) {
errors.reject(null, "Изображение отсутствует");
}
}
Poll poll = null;
if (section!=null && section.isPollPostAllowed()) {
poll = preparePollPreview(form);
}
Topic previewMsg = null;
if (group!=null) {
previewMsg = new Topic(form, user, request.getRemoteAddr());
Image imageObject = null;
if (scrn!=null) {
imageObject = new Image(
0,
0,
"gallery/preview/" + scrn.getMainFile().getName(),
"gallery/preview/" + scrn.getIconFile().getName()
);
}
List<String> tagNames = TagName.parseAndSanitizeTags(form.getTags());
if (!groupPermissionService.canCreateTag(section, tmpl.getCurrentUser())) {
List<String> newTags = tagService.getNewTags(tagNames);
if (!newTags.isEmpty()) {
errors.rejectValue("tags", null, "Вы не можете создавать новые теги ("+ TagService.tagsToString(newTags)+")");
}
}
PreparedTopic preparedTopic = prepareService.prepareTopicPreview(
previewMsg,
TagService.namesToRefs(tagNames),
poll,
request.isSecure(),
message,
imageObject
);
params.put("message", preparedTopic);
TopicMenu topicMenu = prepareService.getTopicMenu(
preparedTopic,
tmpl.getCurrentUser(),
request.isSecure(),
tmpl.getProf(),
true
);
params.put("topicMenu", topicMenu);
}
if (!form.isPreviewMode() && !errors.hasErrors()) {
CSRFProtectionService.checkCSRF(request, errors);
}
if (!form.isPreviewMode() && !errors.hasErrors() && !tmpl.isSessionAuthorized()
|| ipBlockInfo.isCaptchaRequired()) {
captcha.checkCaptcha(request, errors);
}
if (!form.isPreviewMode() && !errors.hasErrors()) {