Search in sources :

Example 1 with PROFILELINK

use of com.erudika.scoold.ScooldServer.PROFILELINK in project scoold by Erudika.

the class ProfileController method get.

@GetMapping({ "", "/{id}/**" })
public String get(@PathVariable(required = false) String id, HttpServletRequest req, Model model) {
    if (!utils.isAuthenticated(req) && StringUtils.isBlank(id)) {
        return "redirect:" + SIGNINLINK + "?returnto=" + PROFILELINK;
    }
    Profile authUser = utils.getAuthUser(req);
    Profile showUser;
    boolean isMyProfile;
    if (StringUtils.isBlank(id) || isMyid(authUser, Profile.id(id))) {
        // requested userid !exists or = my userid => show my profile
        showUser = authUser;
        isMyProfile = true;
    } else {
        showUser = utils.getParaClient().read(Profile.id(id));
        isMyProfile = isMyid(authUser, Profile.id(id));
    }
    if (showUser == null || !ParaObjectUtils.typesMatch(showUser)) {
        return "redirect:" + PROFILELINK;
    }
    boolean protekted = !utils.isDefaultSpacePublic() && !utils.isAuthenticated(req);
    boolean sameSpace = (utils.canAccessSpace(showUser, "default") && utils.canAccessSpace(authUser, "default")) || (authUser != null && showUser.getSpaces().stream().anyMatch(s -> utils.canAccessSpace(authUser, s)));
    if (protekted || !sameSpace) {
        return "redirect:" + PEOPLELINK;
    }
    Pager itemcount1 = utils.getPager("page1", req);
    Pager itemcount2 = utils.getPager("page2", req);
    List<? extends Post> questionslist = getQuestions(authUser, showUser, isMyProfile, itemcount1);
    List<? extends Post> answerslist = getAnswers(authUser, showUser, isMyProfile, itemcount2);
    model.addAttribute("path", "profile.vm");
    model.addAttribute("title", utils.getLang(req).get("profile.title") + " - " + showUser.getName());
    model.addAttribute("description", getUserDescription(showUser, itemcount1.getCount(), itemcount2.getCount()));
    model.addAttribute("ogimage", avatarRepository.getLink(showUser, AvatarFormat.Profile));
    model.addAttribute("includeGMapsScripts", utils.isNearMeFeatureEnabled());
    model.addAttribute("showUser", showUser);
    model.addAttribute("isMyProfile", isMyProfile);
    model.addAttribute("badgesCount", showUser.getBadgesMap().size());
    model.addAttribute("canEdit", isMyProfile || canEditProfile(authUser, id));
    model.addAttribute("canEditAvatar", Config.getConfigBoolean("avatar_edits_enabled", true));
    model.addAttribute("gravatarPicture", gravatarAvatarGenerator.getLink(showUser, AvatarFormat.Profile));
    model.addAttribute("isGravatarPicture", gravatarAvatarGenerator.isLink(showUser.getPicture()));
    model.addAttribute("itemcount1", itemcount1);
    model.addAttribute("itemcount2", itemcount2);
    model.addAttribute("questionslist", questionslist);
    model.addAttribute("answerslist", answerslist);
    model.addAttribute("nameEditsAllowed", Config.getConfigBoolean("name_edits_enabled", true));
    return "base";
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) SIGNINLINK(com.erudika.scoold.ScooldServer.SIGNINLINK) Question(com.erudika.scoold.core.Question) ParaObjectUtils(com.erudika.para.core.utils.ParaObjectUtils) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Pager(com.erudika.para.core.utils.Pager) Controller(org.springframework.stereotype.Controller) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Badge(com.erudika.scoold.core.Profile.Badge) Inject(javax.inject.Inject) HttpServletRequest(javax.servlet.http.HttpServletRequest) Model(org.springframework.ui.Model) MODS(com.erudika.para.core.User.Groups.MODS) com.erudika.scoold.utils.avatars(com.erudika.scoold.utils.avatars) GetMapping(org.springframework.web.bind.annotation.GetMapping) Config(com.erudika.para.core.utils.Config) ScooldUtils(com.erudika.scoold.utils.ScooldUtils) PostMapping(org.springframework.web.bind.annotation.PostMapping) PEOPLELINK(com.erudika.scoold.ScooldServer.PEOPLELINK) Post(com.erudika.scoold.core.Post) HttpServletResponse(javax.servlet.http.HttpServletResponse) PROFILELINK(com.erudika.scoold.ScooldServer.PROFILELINK) User(com.erudika.para.core.User) Utils(com.erudika.para.core.utils.Utils) List(java.util.List) USERS(com.erudika.para.core.User.Groups.USERS) Reply(com.erudika.scoold.core.Reply) Profile(com.erudika.scoold.core.Profile) Pager(com.erudika.para.core.utils.Pager) Profile(com.erudika.scoold.core.Profile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

User (com.erudika.para.core.User)1 MODS (com.erudika.para.core.User.Groups.MODS)1 USERS (com.erudika.para.core.User.Groups.USERS)1 Config (com.erudika.para.core.utils.Config)1 Pager (com.erudika.para.core.utils.Pager)1 ParaObjectUtils (com.erudika.para.core.utils.ParaObjectUtils)1 Utils (com.erudika.para.core.utils.Utils)1 PEOPLELINK (com.erudika.scoold.ScooldServer.PEOPLELINK)1 PROFILELINK (com.erudika.scoold.ScooldServer.PROFILELINK)1 SIGNINLINK (com.erudika.scoold.ScooldServer.SIGNINLINK)1 Post (com.erudika.scoold.core.Post)1 Profile (com.erudika.scoold.core.Profile)1 Badge (com.erudika.scoold.core.Profile.Badge)1 Question (com.erudika.scoold.core.Question)1 Reply (com.erudika.scoold.core.Reply)1 ScooldUtils (com.erudika.scoold.utils.ScooldUtils)1 com.erudika.scoold.utils.avatars (com.erudika.scoold.utils.avatars)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Inject (javax.inject.Inject)1