use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class FeedbackController method replyAjax.
@PostMapping({ "/{id}", "/{id}/{title}" })
public String replyAjax(@PathVariable String id, @PathVariable(required = false) String title, HttpServletRequest req, HttpServletResponse res, Model model) throws IOException {
Post showPost = pc.read(id);
Profile authUser = utils.getAuthUser(req);
if (showPost != null && !showPost.isClosed() && !showPost.isReply()) {
//create new answer
Reply answer = utils.populate(req, new Reply(), "body");
Map<String, String> error = utils.validate(answer);
if (!error.containsKey("body")) {
answer.setTitle(showPost.getTitle());
answer.setCreatorid(authUser.getId());
answer.setParentid(showPost.getId());
answer.create();
showPost.setAnswercount(showPost.getAnswercount() + 1);
if (showPost.getAnswercount() >= MAX_REPLIES_PER_POST) {
showPost.setCloserid("0");
}
// update without adding revisions
pc.update(showPost);
utils.addBadgeAndUpdate(authUser, Profile.Badge.EUREKA, answer.getCreatorid().equals(showPost.getCreatorid()));
answer.setAuthor(authUser);
model.addAttribute("showPost", showPost);
model.addAttribute("answerslist", Collections.singletonList(answer));
return "reply";
}
}
if (utils.isAjaxRequest(req)) {
res.setStatus(200);
return "base";
} else {
return "redirect:" + feedbacklink + "/" + id;
}
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class PeopleController method get.
@GetMapping
public String get(@RequestParam(required = false, defaultValue = Config._TIMESTAMP) String sortby, HttpServletRequest req, Model model) {
Pager itemcount = utils.getPager("page", req);
itemcount.setSortby(sortby);
List<Profile> userlist = utils.getParaClient().findQuery(Utils.type(Profile.class), "*", itemcount);
model.addAttribute("path", "people.vm");
model.addAttribute("title", utils.getLang(req).get("people.title"));
model.addAttribute("peopleSelected", "navbtn-hover");
model.addAttribute("itemcount", itemcount);
model.addAttribute("userlist", userlist);
return "base";
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class ProfileController method edit.
@PostMapping("/{id}")
public String edit(@PathVariable(required = false) String id, @RequestParam(required = false) String name, @RequestParam(required = false) String location, @RequestParam(required = false) String website, @RequestParam(required = false) String aboutme, @RequestParam(required = false) String picture, HttpServletRequest req) {
Profile authUser = utils.getAuthUser(req);
String showId = StringUtils.isBlank(id) ? authUser.getId() : id;
if (canEditProfile(authUser, showId)) {
Profile showUser = utils.getParaClient().read(Profile.id(id));
boolean update = false;
if (!StringUtils.isBlank(name)) {
showUser.setName(name);
update = true;
}
if (!StringUtils.isBlank(location)) {
showUser.setLocation(location);
update = true;
}
if (!StringUtils.isBlank(website)) {
showUser.setWebsite(website);
update = true;
}
if (!StringUtils.isBlank(aboutme)) {
showUser.setAboutme(aboutme);
update = true;
}
if (!StringUtils.isBlank(picture)) {
showUser.setPicture(picture);
update = true;
}
boolean isComplete = showUser.isComplete() && isMyid(authUser, showUser.getId());
if (update || utils.addBadgeOnce(authUser, Badge.NICEPROFILE, isComplete)) {
showUser.update();
}
}
return "redirect:" + profilelink;
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class ProfileController method mods.
@PostMapping(path = "/{id}", params = { "makemod" })
public String mods(@PathVariable String id, @RequestParam Boolean makemod, HttpServletRequest req) {
Profile authUser = utils.getAuthUser(req);
if (!isMyid(authUser, Profile.id(id))) {
Profile showUser = utils.getParaClient().read(Profile.id(id));
if (showUser != null) {
boolean isShowUserAdmin = User.Groups.ADMINS.toString().equals(showUser.getGroups());
boolean isShowUserMod = User.Groups.MODS.toString().equals(showUser.getGroups());
if (makemod && utils.isAdmin(authUser) && !isShowUserAdmin) {
showUser.setGroups(isShowUserMod ? USERS.toString() : MODS.toString());
showUser.update();
}
}
}
return "redirect:" + profilelink + "/" + id;
}
use of com.erudika.scoold.core.Profile in project scoold by Erudika.
the class QuestionController method close.
@PostMapping("/{id}/close")
public String close(@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 (utils.isMod(authUser)) {
if (showPost.isClosed()) {
showPost.setCloserid(null);
} else {
showPost.setCloserid(authUser.getId());
}
showPost.update();
}
return "redirect:" + showPost.getPostLink(false, false);
}
Aggregations