Search in sources :

Example 16 with User

use of com.erudika.para.core.User in project scoold by Erudika.

the class ScooldUtils method sendUpdatedFavTagsNotifications.

@SuppressWarnings("unchecked")
public void sendUpdatedFavTagsNotifications(Post question, List<String> addedTags, HttpServletRequest req) {
    if (!isFavTagsNotificationAllowed()) {
        return;
    }
    // sends a notification to subscibers of a tag if that tag was added to an existing question
    if (question != null && !question.isReply() && addedTags != null && !addedTags.isEmpty()) {
        // the current user - same as utils.getAuthUser(req)
        Profile postAuthor = question.getAuthor();
        Map<String, Object> model = new HashMap<String, Object>();
        Map<String, String> lang = getLang(req);
        String name = postAuthor.getName();
        String body = Utils.markdownToHtml(question.getBody());
        String picture = Utils.formatMessage("<img src='{0}' width='25'>", escapeHtmlAttribute(avatarRepository.getLink(postAuthor, AvatarFormat.Square25)));
        String postURL = getServerURL() + question.getPostLink(false, false);
        String tagsString = Optional.ofNullable(question.getTags()).orElse(Collections.emptyList()).stream().map(t -> "<span class=\"tag\">" + (addedTags.contains(t) ? "<b>" + escapeHtml(t) + "<b>" : escapeHtml(t)) + "</span>").collect(Collectors.joining("&nbsp;"));
        String subject = Utils.formatMessage(lang.get("notification.favtags.subject"), name, Utils.abbreviate(question.getTitle(), 255));
        model.put("subject", escapeHtml(subject));
        model.put("logourl", getSmallLogoUrl());
        model.put("heading", Utils.formatMessage(lang.get("notification.favtags.heading"), picture, escapeHtml(name)));
        model.put("body", Utils.formatMessage("<h2><a href='{0}'>{1}</a></h2><div>{2}</div><br>{3}", postURL, escapeHtml(question.getTitle()), body, tagsString));
        Set<String> emails = getFavTagsSubscribers(addedTags);
        sendEmailsToSubscribersInSpace(emails, question.getSpace(), subject, compileEmailTemplate(model));
    }
}
Also used : Question(com.erudika.scoold.core.Question) Arrays(java.util.Arrays) Webhook(com.erudika.para.core.Webhook) ServletException(javax.servlet.ServletException) Date(java.util.Date) HttpUtils.getCookieValue(com.erudika.scoold.utils.HttpUtils.getCookieValue) JOSEException(com.nimbusds.jose.JOSEException) LoggerFactory(org.slf4j.LoggerFactory) Vote(com.erudika.para.core.Vote) Scanner(java.util.Scanner) ParaClient(com.erudika.para.client.ParaClient) Revision(com.erudika.scoold.core.Revision) StringUtils(org.apache.commons.lang3.StringUtils) Base64(org.apache.commons.codec.binary.Base64) MACVerifier(com.nimbusds.jose.crypto.MACVerifier) Matcher(java.util.regex.Matcher) Locale(java.util.Locale) Map(java.util.Map) ParseException(java.text.ParseException) Config(com.erudika.para.core.utils.Config) ConstraintViolation(javax.validation.ConstraintViolation) ValidationUtils(com.erudika.para.core.validation.ValidationUtils) ParaObject(com.erudika.para.core.ParaObject) Predicate(java.util.function.Predicate) HttpHeaders(org.springframework.http.HttpHeaders) AvatarFormat(com.erudika.scoold.utils.avatars.AvatarFormat) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConfigObject(com.typesafe.config.ConfigObject) Set(java.util.Set) JWSAlgorithm(com.nimbusds.jose.JWSAlgorithm) UnapprovedQuestion(com.erudika.scoold.core.UnapprovedQuestion) Emailer(com.erudika.para.core.email.Emailer) JWSHeader(com.nimbusds.jose.JWSHeader) SignedJWT(com.nimbusds.jwt.SignedJWT) Collectors(java.util.stream.Collectors) Comment(com.erudika.scoold.core.Comment) List(java.util.List) JWSSigner(com.nimbusds.jose.JWSSigner) Tag(com.erudika.para.core.Tag) GravatarAvatarGenerator(com.erudika.scoold.utils.avatars.GravatarAvatarGenerator) Optional(java.util.Optional) DEFAULT_SPACE(com.erudika.scoold.core.Post.DEFAULT_SPACE) Para(com.erudika.para.core.utils.Para) Pattern(java.util.regex.Pattern) Feedback(com.erudika.scoold.core.Feedback) Sysprop(com.erudika.para.core.Sysprop) ParaObjectUtils(com.erudika.para.core.utils.ParaObjectUtils) ALL_MY_SPACES(com.erudika.scoold.core.Post.ALL_MY_SPACES) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) AvatarRepositoryProxy(com.erudika.scoold.utils.avatars.AvatarRepositoryProxy) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Pager(com.erudika.para.core.utils.Pager) ENTHUSIAST(com.erudika.scoold.core.Profile.Badge.ENTHUSIAST) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) Named(javax.inject.Named) LinkedList(java.util.LinkedList) TEACHER(com.erudika.scoold.core.Profile.Badge.TEACHER) UnapprovedReply(com.erudika.scoold.core.UnapprovedReply) LinkedHashSet(java.util.LinkedHashSet) MACSigner(com.nimbusds.jose.crypto.MACSigner) JWSVerifier(com.nimbusds.jose.JWSVerifier) RegExUtils(org.apache.commons.lang3.RegExUtils) Logger(org.slf4j.Logger) AvatarRepository(com.erudika.scoold.utils.avatars.AvatarRepository) Address(com.erudika.para.core.Address) Post(com.erudika.scoold.core.Post) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) User(com.erudika.para.core.User) Utils(com.erudika.para.core.utils.Utils) Report(com.erudika.scoold.core.Report) Component(org.springframework.stereotype.Component) TreeMap(java.util.TreeMap) ScooldServer(com.erudika.scoold.ScooldServer) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Reply(com.erudika.scoold.core.Reply) Collections(java.util.Collections) Profile(com.erudika.scoold.core.Profile) InputStream(java.io.InputStream) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ParaObject(com.erudika.para.core.ParaObject) ConfigObject(com.typesafe.config.ConfigObject) Profile(com.erudika.scoold.core.Profile)

Example 17 with User

use of com.erudika.para.core.User in project scoold by Erudika.

the class ScooldUtils method readAuthUser.

public Profile readAuthUser(HttpServletRequest req) {
    Profile authUser = null;
    User u = pc.me(HttpUtils.getStateParam(AUTH_COOKIE, req));
    if (u != null && isEmailDomainApproved(u.getEmail())) {
        return getOrCreateProfile(u, req);
    }
    return authUser;
}
Also used : User(com.erudika.para.core.User) Profile(com.erudika.scoold.core.Profile)

Example 18 with User

use of com.erudika.para.core.User in project scoold by Erudika.

the class ProfileController method updateUserPictureAndName.

private boolean updateUserPictureAndName(Profile showUser, String picture, String name) {
    boolean updateProfile = false;
    boolean updateUser = false;
    User u = showUser.getUser();
    if (Config.getConfigBoolean("avatar_edits_enabled", true) && !StringUtils.isBlank(picture)) {
        updateProfile = avatarRepository.store(showUser, picture);
    }
    if (Config.getConfigBoolean("name_edits_enabled", true) && !StringUtils.isBlank(name)) {
        showUser.setName(name);
        if (StringUtils.isBlank(showUser.getOriginalName())) {
            showUser.setOriginalName(name);
        }
        if (!u.getName().equals(name)) {
            u.setName(name);
            updateUser = true;
        }
        updateProfile = true;
    }
    if (updateUser) {
        utils.getParaClient().update(u);
    }
    return updateProfile;
}
Also used : User(com.erudika.para.core.User)

Example 19 with User

use of com.erudika.para.core.User in project scoold by Erudika.

the class SigninController method register.

@GetMapping(path = "/signin/register")
public String register(@RequestParam(name = "verify", required = false, defaultValue = "false") Boolean verify, @RequestParam(name = "resend", required = false, defaultValue = "false") Boolean resend, @RequestParam(name = "id", required = false) String id, @RequestParam(name = "token", required = false) String token, HttpServletRequest req, Model model) {
    if (utils.isAuthenticated(req)) {
        return "redirect:" + HOMEPAGE;
    }
    model.addAttribute("path", "signin.vm");
    model.addAttribute("title", utils.getLang(req).get("signup.title"));
    model.addAttribute("signinSelected", "navbtn-hover");
    model.addAttribute("emailPattern", Email.EMAIL_PATTERN);
    model.addAttribute("register", true);
    model.addAttribute("verify", verify);
    model.addAttribute("resend", resend);
    model.addAttribute("bademail", req.getParameter("email"));
    model.addAttribute("nosmtp", StringUtils.isBlank(Config.getConfigParam("mail.host", "")));
    model.addAttribute("captchakey", Config.getConfigParam("signup_captcha_site_key", ""));
    if (id != null && token != null) {
        User u = (User) pc.read(id);
        boolean verified = activateWithEmailToken(u, token);
        if (verified) {
            model.addAttribute("verified", verified);
            model.addAttribute("verifiedEmail", u.getEmail());
        } else {
            return "redirect:" + SIGNINLINK;
        }
    }
    return "base";
}
Also used : User(com.erudika.para.core.User) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 20 with User

use of com.erudika.para.core.User in project scoold by Erudika.

the class SigninController method verifyEmailIfNecessary.

private void verifyEmailIfNecessary(String name, String email, HttpServletRequest req) {
    Sysprop ident = pc.read(email);
    if (ident != null && !ident.hasProperty(Config._EMAIL_TOKEN)) {
        User u = new User(ident.getCreatorid());
        u.setActive(false);
        u.setName(name);
        u.setEmail(email);
        u.setIdentifier(email);
        utils.sendWelcomeEmail(u, true, req);
    }
}
Also used : User(com.erudika.para.core.User) Sysprop(com.erudika.para.core.Sysprop)

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