use of com.erudika.para.core.Sysprop in project scoold by Erudika.
the class SettingsController method resetPasswordAndUpdate.
private boolean resetPasswordAndUpdate(User u, String pass, String newpass) {
if (u != null && !StringUtils.isBlank(pass) && !StringUtils.isBlank(newpass) && u.getIdentityProvider().equals("generic")) {
Sysprop s = utils.getParaClient().read(u.getEmail());
if (s != null && Utils.bcryptMatches(pass, (String) s.getProperty(Config._PASSWORD))) {
String hashed = Utils.bcrypt(newpass);
s.addProperty(Config._PASSWORD, hashed);
u.setPassword(hashed);
utils.getParaClient().update(s);
return true;
}
}
return false;
}
use of com.erudika.para.core.Sysprop in project scoold by Erudika.
the class TermsController method edit.
@PostMapping
public String edit(@RequestParam String termshtml, HttpServletRequest req, Model model) {
if (!utils.isAuthenticated(req) || !utils.isAdmin(utils.getAuthUser(req))) {
return "redirect:" + TERMSLINK;
}
Sysprop terms = new Sysprop("template" + Config.SEPARATOR + "terms");
if (StringUtils.isBlank(termshtml)) {
utils.getParaClient().delete(terms);
} else {
terms.addProperty("html", termshtml);
utils.getParaClient().create(terms);
}
return "redirect:" + TERMSLINK;
}
use of com.erudika.para.core.Sysprop in project scoold by Erudika.
the class LanguageUtils method updateTranslationProgressMap.
/**
* Updates the progress for all languages.
* @param langCode the 2-letter language code
* @param value {@link #PLUS}, {@link #MINUS} or the total percent of completion (0-100)
*/
private void updateTranslationProgressMap(String langCode, int value) {
if (getDefaultLanguageCode().equals(langCode)) {
return;
}
double defsize = getDefaultLanguage().size();
double approved = value;
Map<String, Integer> progress = getTranslationProgressMap();
Integer percent = progress.get(langCode);
if (value == PLUS) {
approved = Math.round(percent * (defsize / 100) + 1);
} else if (value == MINUS) {
approved = Math.round(percent * (defsize / 100) - 1);
}
// allow 3 identical words per language (i.e. Email, etc)
if (approved >= defsize - 3) {
approved = defsize;
}
if (((int) defsize) == 0) {
progress.put(langCode, 0);
} else {
progress.put(langCode, (int) ((approved / defsize) * 100));
}
if (percent < 100 && !percent.equals(progress.get(langCode))) {
Sysprop s = new Sysprop(progressKey);
for (Map.Entry<String, Integer> entry : progress.entrySet()) {
s.addProperty(entry.getKey(), entry.getValue());
}
pc.create(s);
}
}
use of com.erudika.para.core.Sysprop in project scoold by Erudika.
the class LanguageUtils method approveTranslation.
/**
* Approves a translation for a given language.
* @param langCode the 2-letter language code
* @param key the translation key
* @param value the translated string
* @return true if the operation was successful
*/
public boolean approveTranslation(String langCode, String key, String value) {
if (langCode == null || key == null || value == null || getDefaultLanguageCode().equals(langCode)) {
return false;
}
Sysprop s = pc.read(keyPrefix.concat(langCode));
if (s != null && !value.equals(s.getProperty(key))) {
s.addProperty(key, value);
pc.update(s);
updateTranslationProgressMap(langCode, PLUS);
return true;
}
return false;
}
use of com.erudika.para.core.Sysprop in project scoold by Erudika.
the class LanguageUtils method getTranslationProgressMap.
/**
* Returns a map of language codes and the percentage of translated string for that language.
* @return a map indicating translation progress
*/
public Map<String, Integer> getTranslationProgressMap() {
Sysprop progress = pc.read(progressKey);
Map<String, Integer> progressMap = new HashMap<String, Integer>(ALL_LOCALES.size());
boolean isMissing = progress == null;
if (isMissing) {
progress = new Sysprop(progressKey);
progress.addProperty(getDefaultLanguageCode(), 100);
}
for (String langCode : ALL_LOCALES.keySet()) {
Object percent = progress.getProperties().get(langCode);
if (percent != null && percent instanceof Number) {
progressMap.put(langCode, (Integer) percent);
} else {
progressMap.put(langCode, 0);
}
}
if (isMissing) {
pc.create(progress);
}
return progressMap;
}
Aggregations