Search in sources :

Example 46 with Profile

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;
}
Also used : Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 47 with Profile

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;
}
Also used : Profile(com.erudika.scoold.core.Profile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 48 with Profile

use of com.erudika.scoold.core.Profile in project scoold by Erudika.

the class ScooldUtils method getOrCreateProfile.

private Profile getOrCreateProfile(User u, HttpServletRequest req) {
    Profile authUser = pc.read(Profile.id(u.getId()));
    if (authUser == null) {
        authUser = Profile.fromUser(u);
        authUser.create();
        if (!u.getIdentityProvider().equals("generic")) {
            sendWelcomeEmail(u, false, req);
        }
        Map<String, Object> payload = new LinkedHashMap<>(ParaObjectUtils.getAnnotatedFields(authUser, false));
        payload.put("user", u);
        triggerHookEvent("user.signup", payload);
        logger.info("Created new user '{}' with id={}, groups={}, spaces={}.", u.getName(), authUser.getId(), authUser.getGroups(), authUser.getSpaces());
    }
    return authUser;
}
Also used : ParaObject(com.erudika.para.core.ParaObject) ConfigObject(com.typesafe.config.ConfigObject) Profile(com.erudika.scoold.core.Profile) LinkedHashMap(java.util.LinkedHashMap)

Example 49 with Profile

use of com.erudika.scoold.core.Profile 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 50 with Profile

use of com.erudika.scoold.core.Profile 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)

Aggregations

Profile (com.erudika.scoold.core.Profile)85 PostMapping (org.springframework.web.bind.annotation.PostMapping)47 Post (com.erudika.scoold.core.Post)29 ParaObject (com.erudika.para.core.ParaObject)25 User (com.erudika.para.core.User)19 Pager (com.erudika.para.core.utils.Pager)19 HashMap (java.util.HashMap)15 LinkedHashMap (java.util.LinkedHashMap)15 Question (com.erudika.scoold.core.Question)13 Reply (com.erudika.scoold.core.Reply)13 Report (com.erudika.scoold.core.Report)11 IOException (java.io.IOException)11 List (java.util.List)11 Map (java.util.Map)11 UnapprovedReply (com.erudika.scoold.core.UnapprovedReply)10 GetMapping (org.springframework.web.bind.annotation.GetMapping)10 Sysprop (com.erudika.para.core.Sysprop)9 Config (com.erudika.para.core.utils.Config)9 Utils (com.erudika.para.core.utils.Utils)9 Comment (com.erudika.scoold.core.Comment)9