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