Search in sources :

Example 26 with Sysprop

use of com.erudika.para.core.Sysprop in project scoold by Erudika.

the class QuestionsController method setSpace.

@GetMapping({ "/questions/space/{space}", "/questions/space" })
public String setSpace(@PathVariable(required = false) String space, HttpServletRequest req, HttpServletResponse res, Model model) {
    if ("all".equals(space) || utils.isAllSpaces(space)) {
        space = Post.ALL_MY_SPACES + ":" + utils.getLang(req).get("allspaces");
    } else {
        Sysprop spaceObj = pc.read(utils.getSpaceId(space));
        if (!StringUtils.isBlank(space) && spaceObj == null) {
            Profile authUser = utils.getAuthUser(req);
            if (authUser != null && utils.canAccessSpace(authUser, space)) {
                authUser.removeSpace(space);
                authUser.update();
            }
        }
        if (spaceObj != null) {
            space = spaceObj.getId().concat(Config.SEPARATOR).concat(spaceObj.getName());
        } else {
            space = Post.DEFAULT_SPACE;
        }
    }
    utils.storeSpaceIdInCookie(space, req, res);
    String backTo = HttpUtils.getBackToUrl(req);
    if (StringUtils.isBlank(backTo)) {
        return get(req.getParameter("sortby"), req, model);
    } else {
        return "redirect:" + backTo;
    }
}
Also used : Sysprop(com.erudika.para.core.Sysprop) Profile(com.erudika.scoold.core.Profile) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 27 with Sysprop

use of com.erudika.para.core.Sysprop in project scoold by Erudika.

the class PrivacyController method edit.

@PostMapping
public String edit(@RequestParam String privacyhtml, HttpServletRequest req, Model model) {
    if (!utils.isAuthenticated(req) || !utils.isAdmin(utils.getAuthUser(req))) {
        return "redirect:" + PRIVACYLINK;
    }
    Sysprop privacy = new Sysprop("template" + Config.SEPARATOR + "privacy");
    if (StringUtils.isBlank(privacyhtml)) {
        utils.getParaClient().delete(privacy);
    } else {
        privacy.addProperty("html", privacyhtml);
        utils.getParaClient().create(privacy);
    }
    return "redirect:" + PRIVACYLINK;
}
Also used : Sysprop(com.erudika.para.core.Sysprop) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 28 with Sysprop

use of com.erudika.para.core.Sysprop in project scoold by Erudika.

the class SigninController method resetPassword.

private boolean resetPassword(String email, String newpass, String token) {
    if (StringUtils.isBlank(newpass) || StringUtils.isBlank(token) || !isPasswordStrongEnough(newpass)) {
        return false;
    }
    Sysprop s = pc.read(email);
    if (isValidResetToken(s, Config._RESET_TOKEN, token)) {
        // avoid removeProperty method because it won't be seen by server
        s.addProperty(Config._RESET_TOKEN, "");
        s.addProperty("iforgotTimestamp", 0);
        s.addProperty(Config._PASSWORD, Utils.bcrypt(newpass));
        pc.update(s);
        return true;
    }
    return false;
}
Also used : Sysprop(com.erudika.para.core.Sysprop)

Example 29 with Sysprop

use of com.erudika.para.core.Sysprop in project scoold by Erudika.

the class SigninController method activateWithEmailToken.

private boolean activateWithEmailToken(User u, String token) {
    if (u != null && token != null) {
        Sysprop s = pc.read(u.getIdentifier());
        if (s != null && token.equals(s.getProperty(Config._EMAIL_TOKEN))) {
            s.addProperty(Config._EMAIL_TOKEN, "");
            pc.update(s);
            u.setActive(true);
            pc.update(u);
            return true;
        }
        logger.warn("Failed to verify user with email '{}' - invalid verification token.", u.getEmail());
    }
    return false;
}
Also used : Sysprop(com.erudika.para.core.Sysprop)

Example 30 with Sysprop

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

Aggregations

Sysprop (com.erudika.para.core.Sysprop)32 HashMap (java.util.HashMap)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 Map (java.util.Map)6 ParaObject (com.erudika.para.core.ParaObject)5 Profile (com.erudika.scoold.core.Profile)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 LinkedHashMap (java.util.LinkedHashMap)4 Pager (com.erudika.para.core.utils.Pager)3 TreeMap (java.util.TreeMap)3 User (com.erudika.para.core.User)2 ConfigValue (com.typesafe.config.ConfigValue)2 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ParaClient (com.erudika.para.client.ParaClient)1 App (com.erudika.para.core.App)1 Tag (com.erudika.para.core.Tag)1 Webhook (com.erudika.para.core.Webhook)1 Config (com.erudika.para.core.utils.Config)1