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";
}
Aggregations