Search in sources :

Example 31 with Sysprop

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

the class SigninController method generatePasswordResetToken.

private String generatePasswordResetToken(String email, HttpServletRequest req) {
    if (StringUtils.isBlank(email)) {
        return "";
    }
    Sysprop s = pc.read(email);
    // pass reset emails can be sent once every 12h
    if (s != null) {
        if (!s.hasProperty("iforgotTimestamp") || Utils.timestamp() > (Long.valueOf(s.getProperty("iforgotTimestamp").toString()) + TimeUnit.HOURS.toMillis(12))) {
            String token = Utils.generateSecurityToken(42, true);
            s.addProperty(Config._RESET_TOKEN, token);
            s.addProperty("iforgotTimestamp", Utils.timestamp());
            s.setUpdated(Utils.timestamp());
            if (pc.update(s) != null) {
                utils.sendPasswordResetEmail(email, token, req);
            }
            return token;
        } else {
            logger.warn("Failed to send password reset email to '{}' - this can only be done once every 12h.", email);
        }
    } else {
        logger.warn("Failed to send password reset email to '{}' - user has not signed in with that email and passowrd.", email);
    }
    return "";
}
Also used : Sysprop(com.erudika.para.core.Sysprop)

Example 32 with Sysprop

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

the class Profile method fromUser.

public static Profile fromUser(User u) {
    Profile p = new Profile(u.getId(), u.getName());
    p.setUser(u);
    p.setOriginalName(u.getName());
    p.setPicture(u.getPicture());
    p.setAppid(u.getAppid());
    p.setCreatorid(u.getId());
    p.setTimestamp(u.getTimestamp());
    p.setGroups(ScooldUtils.getInstance().isRecognizedAsAdmin(u) ? User.Groups.ADMINS.toString() : u.getGroups());
    // auto-assign spaces to new users
    String space = StringUtils.substringBefore(Config.getConfigParam("auto_assign_spaces", ""), ",");
    if (!StringUtils.isBlank(space) && !ScooldUtils.getInstance().isDefaultSpace(space)) {
        Sysprop s = client().read(ScooldUtils.getInstance().getSpaceId(space));
        if (s == null) {
            s = ScooldUtils.getInstance().buildSpaceObject(space);
            // create the space it it's missing
            client().create(s);
        }
        if (Config.getConfigBoolean("reset_spaces_on_new_assignment", u.isOAuth2User() || u.isLDAPUser() || u.isSAMLUser())) {
            p.setSpaces(Collections.singleton(s.getId() + Config.SEPARATOR + s.getName()));
        } else {
            p.getSpaces().add(s.getId() + Config.SEPARATOR + s.getName());
        }
    }
    return p;
}
Also used : 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