use of com.erudika.para.core.User in project scoold by Erudika.
the class SigninController method getAuth.
private String getAuth(String provider, String accessToken, HttpServletRequest req, HttpServletResponse res) {
if (!utils.isAuthenticated(req)) {
if (StringUtils.equalsAnyIgnoreCase(accessToken, "password", "ldap")) {
accessToken = req.getParameter("username") + ":" + ("password".equals(accessToken) ? ":" : "") + req.getParameter("password");
}
String email = getEmailFromAccessToken(accessToken);
if ("password".equals(provider) && !isEmailRegistered(email)) {
return "redirect:" + SIGNINLINK + "?code=3&error=true";
}
User u = pc.signIn(provider, accessToken, false);
if (u == null && isAccountLocked(email)) {
return "redirect:" + SIGNINLINK + "?code=6&error=true&email=" + email;
}
return onAuthSuccess(u, req, res);
}
return "redirect:" + getBackToUrl(req);
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class SigninController method signup.
@PostMapping("/signin/register")
public String signup(@RequestParam String name, @RequestParam String email, @RequestParam String passw, HttpServletRequest req, HttpServletResponse res, Model model) {
boolean approvedDomain = utils.isEmailDomainApproved(email);
if (!utils.isAuthenticated(req) && approvedDomain && HttpUtils.isValidCaptcha(req.getParameter("g-recaptcha-response"))) {
boolean goodPass = isPasswordStrongEnough(passw);
if (!isEmailRegistered(email) && isSubmittedByHuman(req) && goodPass) {
User u = pc.signIn("password", email + ":" + name + ":" + passw, false);
if (u != null && u.getActive()) {
setAuthCookie(u.getPassword(), req, res);
return "redirect:" + getBackToUrl(req);
} else {
verifyEmailIfNecessary(name, email, req);
}
} else {
model.addAttribute("path", "signin.vm");
model.addAttribute("title", utils.getLang(req).get("signup.title"));
model.addAttribute("signinSelected", "navbtn-hover");
model.addAttribute("register", true);
model.addAttribute("name", name);
model.addAttribute("bademail", email);
model.addAttribute("emailPattern", Email.EMAIL_PATTERN);
if (!goodPass) {
model.addAttribute("error", Collections.singletonMap("passw", utils.getLang(req).get("msgcode.8")));
} else {
model.addAttribute("error", Collections.singletonMap("email", utils.getLang(req).get("msgcode.1")));
}
return "base";
}
}
return "redirect:" + SIGNINLINK + (approvedDomain ? "/register?verify=true" : "?code=3&error=true");
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class GravatarAvatarGeneratorTest method getProfileWithEmail.
private Profile getProfileWithEmail(String email) {
User user = new User();
Profile profile = new Profile();
profile.setUser(user);
user.setEmail(email);
return profile;
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class ApiController method getUser.
@GetMapping("/users/{id}")
public Map<String, Object> getUser(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
List<?> usrProfile = pc.readAll(Arrays.asList(StringUtils.substringBefore(id, Config.SEPARATOR), Profile.id(id)));
Iterator<?> it = usrProfile.iterator();
User u = it.hasNext() ? (User) it.next() : null;
Profile p = it.hasNext() ? (Profile) it.next() : null;
if (p == null) {
res.setStatus(HttpStatus.NOT_FOUND.value());
return null;
}
Map<String, Object> result = new LinkedHashMap<>(ParaObjectUtils.getAnnotatedFields(p, false));
result.put("user", u);
return result;
}
use of com.erudika.para.core.User in project scoold by Erudika.
the class CommentController method sendCommentNotification.
private void sendCommentNotification(Post parentPost, Comment comment, Profile commentAuthor) {
// send email notification to author of post except when the comment is by the same person
if (parentPost != null && comment != null && !StringUtils.equals(parentPost.getCreatorid(), comment.getCreatorid())) {
Profile authorProfile = pc.read(parentPost.getCreatorid());
if (authorProfile != null && authorProfile.getCommentEmailsEnabled()) {
User author = authorProfile.getUser();
if (author != null) {
Map<String, Object> model = new HashMap<String, Object>();
String name = commentAuthor.getName();
String body = Utils.markdownToHtml(Utils.abbreviate(comment.getComment(), 255));
String pic = Utils.formatMessage("<img src='{0}' width='25'>", commentAuthor.getPicture());
String postURL = getServerURL() + parentPost.getPostLink(false, false);
model.put("logourl", Config.getConfigParam("small_logo_url", "https://scoold.com/logo.png"));
model.put("heading", Utils.formatMessage("New comment on <a href='{0}'>{1}</a>", postURL, parentPost.getTitle()));
model.put("body", Utils.formatMessage("<h2>{0} {1}:</h2><div class='panel'>{2}</div>", pic, name, body));
emailer.sendEmail(Arrays.asList(author.getEmail()), name + " commented on your post", Utils.compileMustache(model, utils.loadEmailTemplate("notify")));
}
}
}
}
Aggregations