use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class QuestionController method delete.
@PostMapping("/{id}/delete")
public String delete(@PathVariable String id, HttpServletRequest req) {
Post showPost = pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (!utils.canEdit(showPost, authUser) || showPost == null) {
return "redirect:" + req.getRequestURI();
}
if (!showPost.isReply()) {
if ((utils.isMine(showPost, authUser) || utils.isMod(authUser))) {
showPost.delete();
return "redirect:" + questionslink + "?success=true&code=16";
}
} else if (showPost.isReply()) {
if (utils.isMine(showPost, authUser) || utils.isMod(authUser)) {
Post parent = pc.read(showPost.getParentid());
parent.setAnswercount(parent.getAnswercount() - 1);
parent.update();
showPost.delete();
}
}
return "redirect:" + showPost.getPostLink(false, false);
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class QuestionsController method post.
@PostMapping("/questions/ask")
public String post(@RequestParam(required = false) String location, @RequestParam(required = false) String latlng, @RequestParam(required = false) String address, HttpServletRequest req, Model model) {
if (utils.isAuthenticated(req)) {
Profile authUser = utils.getAuthUser(req);
Question q = utils.populate(req, new Question(), "title", "body", "tags|,", "location");
q.setCreatorid(authUser.getId());
Map<String, String> error = utils.validate(q);
if (error.isEmpty()) {
q.setLocation(location);
String qid = q.create();
if (!StringUtils.isBlank(latlng)) {
Address addr = new Address();
addr.setAddress(address);
addr.setCountry(location);
addr.setLatlng(latlng);
addr.setParentid(qid);
addr.setCreatorid(authUser.getId());
pc.create(addr);
}
authUser.setLastseen(System.currentTimeMillis());
} else {
model.addAttribute("error", error);
model.addAttribute("path", "questions.vm");
model.addAttribute("includeGMapsScripts", true);
model.addAttribute("askSelected", "navbtn-hover");
return "base";
}
return "redirect:" + q.getPostLink(false, false);
}
return "redirect:" + signinlink + "?returnto=" + questionslink + "/ask";
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class ReportsController method delete.
@PostMapping("/{id}/delete")
public String delete(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
if (utils.isAuthenticated(req)) {
Profile authUser = utils.getAuthUser(req);
Report rep = pc.read(id);
if (rep != null && utils.isAdmin(authUser)) {
rep.delete();
}
}
if (!utils.isAjaxRequest(req)) {
return "redirect:" + reportslink;
}
return "base";
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class CommentController method sendCommentNotification.
private void sendCommentNotification(Post parentPost, Comment comment, Profile commentAuthor) {
// send email notification to author of post except when the comment is by the same person
if (parentPost != null && comment != null && !StringUtils.equals(parentPost.getCreatorid(), comment.getCreatorid())) {
Profile authorProfile = pc.read(parentPost.getCreatorid());
if (authorProfile != null && authorProfile.getCommentEmailsEnabled()) {
User author = authorProfile.getUser();
if (author != null) {
Map<String, Object> model = new HashMap<String, Object>();
String name = commentAuthor.getName();
String body = Utils.markdownToHtml(Utils.abbreviate(comment.getComment(), 255));
String pic = Utils.formatMessage("<img src='{0}' width='25'>", commentAuthor.getPicture());
String postURL = getServerURL() + parentPost.getPostLink(false, false);
model.put("logourl", Config.getConfigParam("small_logo_url", "https://scoold.com/logo.png"));
model.put("heading", Utils.formatMessage("New comment on <a href='{0}'>{1}</a>", postURL, parentPost.getTitle()));
model.put("body", Utils.formatMessage("<h2>{0} {1}:</h2><div class='panel'>{2}</div>", pic, name, body));
emailer.sendEmail(Arrays.asList(author.getEmail()), name + " commented on your post", Utils.compileMustache(model, utils.loadEmailTemplate("notify")));
}
}
}
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class CommentController method deleteAjax.
@PostMapping("/{id}/delete")
public void deleteAjax(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
if (utils.isAuthenticated(req)) {
Comment comment = pc.read(id);
Profile authUser = utils.getAuthUser(req);
boolean isMod = utils.isMod(authUser);
if (comment != null && (comment.getCreatorid().equals(authUser.getId()) || isMod)) {
// check parent and correct (for multi-parent-object pages)
comment.delete();
if (!isMod) {
utils.addBadgeAndUpdate(authUser, DISCIPLINED, true);
}
}
}
res.setStatus(200);
}
Aggregations