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