@RequestParam("reason") String reason,
@RequestParam("time") String time,
@RequestParam(value="allow_posting", required = false, defaultValue="false") boolean allowPosting,
@RequestParam(value="captcha_required", required = false, defaultValue="false") boolean captchaRequired
) throws Exception {
Template tmpl = Template.getTemplate(request);
if (!tmpl.isModeratorSession()) {
throw new IllegalAccessException("Not authorized");
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
if ("hour".equals(time)) {
calendar.add(Calendar.HOUR_OF_DAY, 1);
} else if ("day".equals(time)) {
calendar.add(Calendar.DAY_OF_MONTH, 1);
} else if ("month".equals(time)) {
calendar.add(Calendar.MONTH, 1);
} else if ("3month".equals(time)) {
calendar.add(Calendar.MONTH, 3);
} else if ("6month".equals(time)) {
calendar.add(Calendar.MONTH, 6);
} else if ("remove".equals(time)) {
} else if ("custom".equals(time)) {
int days = ServletRequestUtils.getRequiredIntParameter(request, "ban_days");
if (days <= 0 || days > 180) {
throw new UserErrorException("Invalid days count");
}
calendar.add(Calendar.DAY_OF_MONTH, days);
}
Timestamp ts;
if ("unlim".equals(time)) {
ts = null;
} else {
ts = new Timestamp(calendar.getTimeInMillis());
}
User user = tmpl.getCurrentUser();
user.checkCommit();
ipBlockDao.blockIP(ip, user, reason, ts, allowPosting, captchaRequired);