Search in sources :

Example 1 with User

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")));
        }
    }
}
Also used : User(com.erudika.para.core.User) HashMap(java.util.HashMap) ParaObject(com.erudika.para.core.ParaObject) Profile(com.erudika.scoold.core.Profile)

Example 2 with User

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;
}
Also used : User(com.erudika.para.core.User) ParaObject(com.erudika.para.core.ParaObject) Profile(com.erudika.scoold.core.Profile) LinkedHashMap(java.util.LinkedHashMap) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with User

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;
}
Also used : User(com.erudika.para.core.User) Profile(com.erudika.scoold.core.Profile)

Example 4 with User

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);
}
Also used : User(com.erudika.para.core.User) Post(com.erudika.scoold.core.Post) Pager(com.erudika.para.core.utils.Pager) UnapprovedReply(com.erudika.scoold.core.UnapprovedReply) Reply(com.erudika.scoold.core.Reply) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 5 with User

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;
}
Also used : User(com.erudika.para.core.User) Profile(com.erudika.scoold.core.Profile)

Aggregations

User (com.erudika.para.core.User)24 Profile (com.erudika.scoold.core.Profile)18 ParaObject (com.erudika.para.core.ParaObject)10 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)9 Sysprop (com.erudika.para.core.Sysprop)6 Pager (com.erudika.para.core.utils.Pager)6 Post (com.erudika.scoold.core.Post)6 Reply (com.erudika.scoold.core.Reply)6 Map (java.util.Map)6 ParaClient (com.erudika.para.client.ParaClient)5 Tag (com.erudika.para.core.Tag)5 Webhook (com.erudika.para.core.Webhook)5 Config (com.erudika.para.core.utils.Config)5 ParaObjectUtils (com.erudika.para.core.utils.ParaObjectUtils)5 Utils (com.erudika.para.core.utils.Utils)5 Comment (com.erudika.scoold.core.Comment)5 Question (com.erudika.scoold.core.Question)5 UnapprovedReply (com.erudika.scoold.core.UnapprovedReply)5 Report (com.erudika.scoold.core.Report)4