use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class ReportsController method close.
@PostMapping("/{id}/close")
public String close(@PathVariable String id, @RequestParam(required = false, defaultValue = "") String solution, HttpServletRequest req, HttpServletResponse res) {
if (utils.isAuthenticated(req)) {
Profile authUser = utils.getAuthUser(req);
Report report = pc.read(id);
if (report != null && !report.getClosed() && utils.isMod(authUser)) {
report.setClosed(true);
report.setSolution(solution);
report.update();
}
}
if (!utils.isAjaxRequest(req)) {
return "redirect:" + reportslink;
}
return "base";
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class AdminController method forceDelete.
@PostMapping
public String forceDelete(@RequestParam Boolean confirmdelete, @RequestParam String id, HttpServletRequest req) {
Profile authUser = utils.getAuthUser(req);
if (confirmdelete && utils.isAdmin(authUser)) {
ParaObject sobject = pc.read(id);
if (sobject != null) {
sobject.delete();
logger.info("{} #{} deleted {} #{}", authUser.getName(), authUser.getId(), sobject.getClass().getName(), sobject.getId());
}
}
return "redirect:" + adminlink;
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class CommentController method createAjax.
@PostMapping
public String createAjax(@RequestParam String comment, @RequestParam String parentid, HttpServletRequest req, Model model) {
Profile authUser = utils.getAuthUser(req);
if (utils.canComment(authUser, req) && !StringUtils.isBlank(comment) && !StringUtils.isBlank(parentid)) {
Comment showComment = utils.populate(req, new Comment(), "comment");
showComment.setCreatorid(authUser.getId());
Map<String, String> error = utils.validate(showComment);
if (error.isEmpty()) {
showComment.setComment(comment);
showComment.setParentid(parentid);
showComment.setAuthorName(authUser.getName());
if (showComment.create() != null) {
long commentCount = authUser.getComments();
utils.addBadgeOnce(authUser, COMMENTATOR, commentCount >= COMMENTATOR_IFHAS);
authUser.setComments(commentCount + 1);
authUser.update();
model.addAttribute("showComment", showComment);
// send email to the author of parent post
Post parentPost = pc.read(parentid);
if (parentPost != null) {
parentPost.addCommentId(showComment.getId());
parentPost.update();
}
sendCommentNotification(parentPost, showComment, authUser);
}
}
}
return "comment";
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class FeedbackController method createAjax.
@PostMapping
public String createAjax(HttpServletRequest req, Model model) {
model.addAttribute("path", "feedback.vm");
if (utils.isAuthenticated(req)) {
Profile authUser = utils.getAuthUser(req);
Post post = utils.populate(req, new Feedback(), "title", "body", "tags|,");
Map<String, String> error = utils.validate(post);
if (error.isEmpty()) {
post.setCreatorid(authUser.getId());
post.create();
authUser.setLastseen(System.currentTimeMillis());
return "redirect:" + feedbacklink;
} else {
model.addAttribute("error", error);
return "base";
}
}
return "redirect:" + feedbacklink;
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class ScooldRequestInterceptor method postHandle.
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
if (modelAndView == null || StringUtils.startsWith(modelAndView.getViewName(), "redirect:")) {
// skip if redirect
return;
}
/*============================*
* COMMON MODEL FOR ALL PAGES *
*============================*/
// Misc
modelAndView.addObject("HOMEPAGE", HOMEPAGE);
modelAndView.addObject("APPNAME", Config.APP_NAME);
modelAndView.addObject("CDN_URL", CDN_URL);
modelAndView.addObject("DESCRIPTION", Config.getConfigParam("meta_description", ""));
modelAndView.addObject("KEYWORDS", Config.getConfigParam("meta_keywords", ""));
modelAndView.addObject("IN_PRODUCTION", Config.IN_PRODUCTION);
modelAndView.addObject("IN_DEVELOPMENT", !Config.IN_PRODUCTION);
modelAndView.addObject("MAX_ITEMS_PER_PAGE", Config.MAX_ITEMS_PER_PAGE);
modelAndView.addObject("SESSION_TIMEOUT_SEC", Config.SESSION_TIMEOUT_SEC);
modelAndView.addObject("TOKEN_PREFIX", TOKEN_PREFIX);
modelAndView.addObject("FB_APP_ID", Config.FB_APP_ID);
modelAndView.addObject("GMAPS_API_KEY", Config.getConfigParam("gmaps_api_key", ""));
modelAndView.addObject("GOOGLE_CLIENT_ID", Config.getConfigParam("google_client_id", ""));
modelAndView.addObject("includeGAjs", !StringUtils.isBlank(Config.getConfigParam("google_analytics_id", "")));
modelAndView.addObject("includeHighlightJS", Config.getConfigBoolean("code_highlighting_enabled", true));
modelAndView.addObject("isAjaxRequest", utils.isAjaxRequest(request));
modelAndView.addObject("reportTypes", ReportType.values());
modelAndView.addObject("returnto", request.getRequestURI());
// Configurable constants
modelAndView.addObject("MAX_CONTACTS_PER_USER", MAX_CONTACTS_PER_USER);
modelAndView.addObject("MAX_TEXT_LENGTH", MAX_TEXT_LENGTH);
modelAndView.addObject("MAX_TAGS_PER_POST", MAX_TAGS_PER_POST);
modelAndView.addObject("MAX_REPLIES_PER_POST", MAX_REPLIES_PER_POST);
modelAndView.addObject("MAX_FAV_TAGS", MAX_FAV_TAGS);
modelAndView.addObject("ANSWER_VOTEUP_REWARD_AUTHOR", ANSWER_VOTEUP_REWARD_AUTHOR);
modelAndView.addObject("QUESTION_VOTEUP_REWARD_AUTHOR", QUESTION_VOTEUP_REWARD_AUTHOR);
modelAndView.addObject("VOTEUP_REWARD_AUTHOR", VOTEUP_REWARD_AUTHOR);
modelAndView.addObject("ANSWER_APPROVE_REWARD_AUTHOR", ANSWER_APPROVE_REWARD_AUTHOR);
modelAndView.addObject("ANSWER_APPROVE_REWARD_VOTER", ANSWER_APPROVE_REWARD_VOTER);
modelAndView.addObject("POST_VOTEDOWN_PENALTY_AUTHOR", POST_VOTEDOWN_PENALTY_AUTHOR);
modelAndView.addObject("POST_VOTEDOWN_PENALTY_VOTER", POST_VOTEDOWN_PENALTY_VOTER);
modelAndView.addObject("VOTER_IFHAS", VOTER_IFHAS);
modelAndView.addObject("COMMENTATOR_IFHAS", COMMENTATOR_IFHAS);
modelAndView.addObject("CRITIC_IFHAS", CRITIC_IFHAS);
modelAndView.addObject("SUPPORTER_IFHAS", SUPPORTER_IFHAS);
modelAndView.addObject("GOODQUESTION_IFHAS", GOODQUESTION_IFHAS);
modelAndView.addObject("GOODANSWER_IFHAS", GOODANSWER_IFHAS);
modelAndView.addObject("ENTHUSIAST_IFHAS", ENTHUSIAST_IFHAS);
modelAndView.addObject("FRESHMAN_IFHAS", FRESHMAN_IFHAS);
modelAndView.addObject("SCHOLAR_IFHAS", SCHOLAR_IFHAS);
modelAndView.addObject("TEACHER_IFHAS", TEACHER_IFHAS);
modelAndView.addObject("PROFESSOR_IFHAS", PROFESSOR_IFHAS);
modelAndView.addObject("GEEK_IFHAS", GEEK_IFHAS);
// Paths
modelAndView.addObject("localeCookieName", LOCALE_COOKIE);
modelAndView.addObject("csrfCookieName", CSRF_COOKIE);
modelAndView.addObject("peoplelink", peoplelink);
modelAndView.addObject("profilelink", profilelink);
modelAndView.addObject("imageslink", IMAGESLINK);
modelAndView.addObject("scriptslink", SCRIPTSLINK);
modelAndView.addObject("styleslink", STYLESLINK);
modelAndView.addObject("searchlink", searchlink);
modelAndView.addObject("signinlink", signinlink);
modelAndView.addObject("signoutlink", signoutlink);
modelAndView.addObject("aboutlink", aboutlink);
modelAndView.addObject("privacylink", privacylink);
modelAndView.addObject("termslink", termslink);
modelAndView.addObject("tagslink", tagslink);
modelAndView.addObject("settingslink", settingslink);
modelAndView.addObject("translatelink", translatelink);
modelAndView.addObject("reportslink", reportslink);
modelAndView.addObject("adminlink", adminlink);
modelAndView.addObject("votedownlink", votedownlink);
modelAndView.addObject("voteuplink", voteuplink);
modelAndView.addObject("questionlink", questionlink);
modelAndView.addObject("questionslink", questionslink);
modelAndView.addObject("commentlink", commentlink);
modelAndView.addObject("postlink", postlink);
modelAndView.addObject("revisionslink", revisionslink);
modelAndView.addObject("feedbacklink", feedbacklink);
modelAndView.addObject("languageslink", languageslink);
// Visual customization
modelAndView.addObject("navbarFixedClass", Config.getConfigBoolean("fixed_nav", false) ? "navbar-fixed" : "none");
modelAndView.addObject("showBranding", Config.getConfigBoolean("show_branding", true));
modelAndView.addObject("logoUrl", Config.getConfigParam("logo_url", IMAGESLINK + "/logo.svg"));
modelAndView.addObject("logoWidth", Config.getConfigInt("logo_width", 90));
modelAndView.addObject("stylesheetUrl", Config.getConfigParam("stylesheet_url", STYLESLINK + "/style.css"));
// Auth & Badges
Profile authUser = (Profile) request.getAttribute(AUTH_USER_ATTRIBUTE);
modelAndView.addObject("infoStripMsg", authUser == null ? Config.getConfigParam("welcome_message", "") : "");
modelAndView.addObject("authenticated", authUser != null);
modelAndView.addObject("canComment", utils.canComment(authUser, request));
modelAndView.addObject("isMod", utils.isMod(authUser));
modelAndView.addObject("isAdmin", utils.isAdmin(authUser));
modelAndView.addObject("utils", Utils.getInstance());
modelAndView.addObject("scooldUtils", utils);
modelAndView.addObject("authUser", authUser);
modelAndView.addObject("badgelist", utils.checkForBadges(authUser, request));
modelAndView.addObject("request", request);
// Language
Locale currentLocale = utils.getCurrentLocale(utils.getLanguageCode(request), request);
modelAndView.addObject("currentLocale", currentLocale);
modelAndView.addObject("lang", utils.getLang(currentLocale));
// check for AJAX pagination requests
if (utils.isAjaxRequest(request) && (utils.param(request, "page") || utils.param(request, "page1") || utils.param(request, "page2"))) {
// switch to page fragment view
modelAndView.setViewName("pagination");
}
// CSP Header
if (Config.getConfigBoolean("csp_header_enabled", true)) {
response.addHeader("Content-Security-Policy", Config.getConfigParam("csp_header", utils.getDefaultContentSecurityPolicy()));
}
// default metadata for social meta tags
if (!modelAndView.getModel().containsKey("title")) {
modelAndView.addObject("title", Config.APP_NAME);
}
if (!modelAndView.getModel().containsKey("description")) {
modelAndView.addObject("description", Config.getConfigParam("meta_description", ""));
}
if (!modelAndView.getModel().containsKey("ogimage")) {
modelAndView.addObject("ogimage", IMAGESLINK + "/logowhite.png");
}
}
Aggregations