Search in sources :

Example 11 with User

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);
}
Also used : User(com.erudika.para.core.User)

Example 12 with User

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");
}
Also used : User(com.erudika.para.core.User) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 13 with User

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;
}
Also used : User(com.erudika.para.core.User) Profile(com.erudika.scoold.core.Profile)

Example 14 with User

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;
}
Also used : User(com.erudika.para.core.User) ParaObject(com.erudika.para.core.ParaObject) Profile(com.erudika.scoold.core.Profile) LinkedHashMap(java.util.LinkedHashMap) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 15 with User

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")));
            }
        }
    }
}
Also used : User(com.erudika.para.core.User) HashMap(java.util.HashMap) Profile(com.erudika.scoold.core.Profile)

Aggregations

User (com.erudika.para.core.User)24 Profile (com.erudika.scoold.core.Profile)18 ParaObject (com.erudika.para.core.ParaObject)10 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)9 Sysprop (com.erudika.para.core.Sysprop)6 Pager (com.erudika.para.core.utils.Pager)6 Post (com.erudika.scoold.core.Post)6 Reply (com.erudika.scoold.core.Reply)6 Map (java.util.Map)6 ParaClient (com.erudika.para.client.ParaClient)5 Tag (com.erudika.para.core.Tag)5 Webhook (com.erudika.para.core.Webhook)5 Config (com.erudika.para.core.utils.Config)5 ParaObjectUtils (com.erudika.para.core.utils.ParaObjectUtils)5 Utils (com.erudika.para.core.utils.Utils)5 Comment (com.erudika.scoold.core.Comment)5 Question (com.erudika.scoold.core.Question)5 UnapprovedReply (com.erudika.scoold.core.UnapprovedReply)5 Report (com.erudika.scoold.core.Report)4