use of com.erudika.para.core.User in project scoold by Erudika.
the class QuestionController method sendReplyNotifications.
private void sendReplyNotifications(Post parentPost, Post reply) {
// send email notification to author of post except when the reply is by the same person
if (parentPost != null && reply != null && !StringUtils.equals(parentPost.getCreatorid(), reply.getCreatorid())) {
// the current user - same as utils.getAuthUser(req)
Profile replyAuthor = reply.getAuthor();
Map<String, Object> model = new HashMap<String, Object>();
String name = replyAuthor.getName();
String body = Utils.markdownToHtml(Utils.abbreviate(reply.getBody(), 500));
String picture = Utils.formatMessage("<img src='{0}' width='25'>", replyAuthor.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 reply to <a href='{0}'>{1}</a>", postURL, parentPost.getTitle()));
model.put("body", Utils.formatMessage("<h2>{0} {1}:</h2><div class='panel'>{2}</div>", picture, name, body));
Profile authorProfile = pc.read(parentPost.getCreatorid());
if (authorProfile != null) {
User author = authorProfile.getUser();
if (author != null) {
if (authorProfile.getReplyEmailsEnabled()) {
parentPost.addFollower(author);
}
}
}
if (parentPost.hasFollowers()) {
emailer.sendEmail(new ArrayList<String>(parentPost.getFollowers().values()), name + " replied to '" + Utils.abbreviate(reply.getTitle(), 50) + "...'", Utils.compileMustache(model, utils.loadEmailTemplate("notify")));
}
}
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class ApiController method getUser.
@GetMapping("/users/{id}")
public Map<String, Object> getUser(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
List<?> usrProfile = pc.readAll(Arrays.asList(StringUtils.substringBefore(id, Config.SEPARATOR), Profile.id(id)));
Iterator<?> it = usrProfile.iterator();
User u = it.hasNext() ? (User) it.next() : null;
Profile p = it.hasNext() ? (Profile) it.next() : null;
if (p == null) {
res.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
Map<String, Object> result = new LinkedHashMap<>(ParaObjectUtils.getAnnotatedFields(p, false));
result.put("user", u);
return result;
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class GravatarAvatarGeneratorTest method getProfileWithEmail.
private Profile getProfileWithEmail(String email) {
User user = new User();
Profile profile = new Profile();
profile.setUser(user);
user.setEmail(email);
return profile;
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class QuestionController method merge.
@PostMapping("/{id}/merge-into")
public String merge(@PathVariable String id, @RequestParam String id2, HttpServletRequest req) {
Post showPost = pc.read(id);
Post targetPost = pc.read(id2);
Profile authUser = utils.getAuthUser(req);
if (!(utils.canEdit(showPost, authUser) && utils.canEdit(targetPost, authUser)) || showPost == null || targetPost == null || showPost.isReply() || targetPost.isReply() || showPost.equals(targetPost)) {
return "redirect:" + req.getRequestURI();
}
if (utils.canEdit(showPost, authUser) && utils.canEdit(targetPost, authUser)) {
if (Config.getConfigBoolean("merge_question_bodies", true)) {
targetPost.setBody(targetPost.getBody() + "\n\n" + showPost.getBody());
}
targetPost.setAnswercount(targetPost.getAnswercount() + showPost.getAnswercount());
targetPost.setViewcount(targetPost.getViewcount() + showPost.getViewcount());
if (showPost.hasFollowers()) {
for (Map.Entry<String, String> entry : showPost.getFollowers().entrySet()) {
User u = new User(entry.getKey());
u.setEmail(entry.getValue());
targetPost.addFollower(u);
}
}
Pager pager = new Pager(1, "_docid", false, Config.MAX_ITEMS_PER_PAGE);
List<Reply> answers;
do {
answers = pc.getChildren(showPost, Utils.type(Reply.class), pager);
for (Reply answer : answers) {
answer.setParentid(targetPost.getId());
answer.setTitle(targetPost.getTitle());
}
// overwrite
pc.createAll(answers);
} while (!answers.isEmpty());
targetPost.update();
showPost.delete();
}
return "redirect:" + targetPost.getPostLink(false, false);
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class ScooldUtils method checkAuth.
public ParaObject checkAuth(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
Profile authUser = null;
String jwt = HttpUtils.getStateParam(AUTH_COOKIE, req);
if (isApiRequest(req)) {
return checkApiAuth(req);
} else if (jwt != null && !StringUtils.endsWithAny(req.getRequestURI(), ".js", ".css", ".svg", ".png", ".jpg", ".ico", ".gif", ".woff2", ".woff", "people/avatar")) {
User u = pc.me(jwt);
if (u != null && isEmailDomainApproved(u.getEmail())) {
authUser = getOrCreateProfile(u, req);
authUser.setUser(u);
authUser.setOriginalPicture(u.getPicture());
boolean updatedRank = promoteOrDemoteUser(authUser, u);
boolean updatedProfile = updateProfilePictureAndName(authUser, u);
if (updatedRank || updatedProfile) {
authUser.update();
}
} else {
clearSession(req, res);
logger.info("Invalid JWT found in cookie {}.", AUTH_COOKIE);
res.sendRedirect(getServerURL() + CONTEXT_PATH + SIGNINLINK + "?code=3&error=true");
return null;
}
}
return authUser;
}
Aggregations