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