use of org.olat.core.id.Preferences in project openolat by klemens.
the class UserWebService method getUserPreferences.
/**
* Retrieves the preferences of a user given its unique key identifier
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The preferences
* @response.representation.200.example {@link org.olat.user.restapi.Examples#SAMPLE_PREFERENCESVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The identity not found
* @param identityKey The user key identifier of the user being searched
* @param httpRequest The HTTP request
* @return an xml or json representation of a the roles being search.
*/
@GET
@Path("{identityKey}/preferences")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getUserPreferences(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
boolean isUserManager = isUserManager(request);
if (!isUserManager) {
return Response.serverError().status(Status.FORBIDDEN).build();
}
Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Preferences prefs = identity.getUser().getPreferences();
return Response.ok(new PreferencesVO(prefs)).build();
}
use of org.olat.core.id.Preferences in project openolat by klemens.
the class UserWebService method updatePreferences.
/**
* Update the preferences of a user given its unique key identifier
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The user
* @response.representation.200.example {@link org.olat.user.restapi.Examples#SAMPLE_PREFERENCESVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The identity not found
* @param identityKey The user key identifier of the user being searched
* @param preferences The updated preferences
* @param httpRequest The HTTP request
* @return an xml or json representation of a the roles being search.
*/
@POST
@Path("{identityKey}/preferences")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response updatePreferences(@PathParam("identityKey") Long identityKey, PreferencesVO preferences, @Context HttpServletRequest request) {
try {
boolean isUserManager = isUserManager(request);
if (!isUserManager) {
return Response.serverError().status(Status.FORBIDDEN).build();
}
Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Preferences prefs = identity.getUser().getPreferences();
prefs.setLanguage(preferences.getLanguage());
UserManager.getInstance().updateUserFromIdentity(identity);
return Response.ok(new PreferencesVO(prefs)).build();
} catch (Throwable e) {
throw new WebApplicationException(e);
}
}
use of org.olat.core.id.Preferences in project openolat by klemens.
the class SendTokenToUserForm method sendToken.
private void sendToken(UserRequest ureq, String text) {
// mailer configuration
// We allow creation of password token when user has no password so far or when he as an OpenOLAT Password.
// For other cases such as Shibboleth, LDAP, oAuth etc. we don't allow creation of token as this is most
// likely not a desired action.
List<Authentication> authentications = BaseSecurityManager.getInstance().getAuthentications(user);
boolean isOOpwdAllowed = (authentications.size() == 0);
for (Authentication authentication : authentications) {
if (authentication.getProvider().equals(BaseSecurityModule.getDefaultAuthProviderIdentifier())) {
isOOpwdAllowed = true;
}
}
if (!isOOpwdAllowed) {
showWarning("sendtoken.wrong.auth");
return;
}
Preferences prefs = user.getUser().getPreferences();
Locale locale = i18nManager.getLocaleOrDefault(prefs.getLanguage());
String emailAdress = user.getUser().getProperty(UserConstants.EMAIL, locale);
String ip = ureq.getHttpReq().getRemoteAddr();
TemporaryKey tk = registrationManager.createAndDeleteOldTemporaryKey(user.getKey(), emailAdress, ip, RegistrationManager.PW_CHANGE);
if (text.indexOf(dummyKey) < 0) {
showWarning("changeuserpwd.failed");
logWarn("Can not replace temporary registration token in change pwd mail token dialog, user probably changed temporary token in mai template", null);
return;
}
String body = text.replace(dummyKey, tk.getRegistrationKey());
Translator userTrans = Util.createPackageTranslator(RegistrationManager.class, locale);
MailBundle bundle = new MailBundle();
bundle.setToId(user);
bundle.setContent(userTrans.translate("pwchange.subject"), body);
MailerResult result = mailManager.sendExternMessage(bundle, null, false);
if (result.getReturnCode() == 0) {
showInfo("email.sent");
} else {
showInfo("email.notsent");
}
}
use of org.olat.core.id.Preferences in project OpenOLAT by OpenOLAT.
the class PreferencesFormController method formOK.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
*/
protected void formOK(UserRequest ureq) {
UserManager um = UserManager.getInstance();
BaseSecurity secMgr = BaseSecurityManager.getInstance();
// Refresh user from DB to prevent stale object issues
tobeChangedIdentity = secMgr.loadIdentityByKey(tobeChangedIdentity.getKey());
Preferences prefs = tobeChangedIdentity.getUser().getPreferences();
prefs.setLanguage(language.getSelectedKey());
prefs.setFontsize(fontsize.getSelectedKey());
if (notificationInterval != null) {
// only read notification interval if available, could be disabled by configuration
prefs.setNotificationInterval(notificationInterval.getSelectedKey());
}
// Maybe the user changed the font size
if (ureq.getIdentity().equalsByPersistableKey(tobeChangedIdentity)) {
int fontSize = Integer.parseInt(fontsize.getSelectedKey());
WindowManager wm = getWindowControl().getWindowBackOffice().getWindowManager();
if (fontSize != wm.getFontSize()) {
getWindowControl().getWindowBackOffice().getWindow().setDirty(true);
}
}
if (mailSystem != null && mailSystem.isOneSelected()) {
String val = mailSystem.isSelected(1) ? "true" : "false";
prefs.setReceiveRealMail(val);
}
if (um.updateUserFromIdentity(tobeChangedIdentity)) {
// Language change needs logout / login
showInfo("preferences.successful");
} else {
showInfo("preferences.unsuccessful");
}
um.setUserCharset(tobeChangedIdentity, charset.getSelectedKey());
fireEvent(ureq, Event.DONE_EVENT);
}
use of org.olat.core.id.Preferences in project OpenOLAT by OpenOLAT.
the class UserWebService method getUserPreferences.
/**
* Retrieves the preferences of a user given its unique key identifier
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The preferences
* @response.representation.200.example {@link org.olat.user.restapi.Examples#SAMPLE_PREFERENCESVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The identity not found
* @param identityKey The user key identifier of the user being searched
* @param httpRequest The HTTP request
* @return an xml or json representation of a the roles being search.
*/
@GET
@Path("{identityKey}/preferences")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getUserPreferences(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
boolean isUserManager = isUserManager(request);
if (!isUserManager) {
return Response.serverError().status(Status.FORBIDDEN).build();
}
Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Preferences prefs = identity.getUser().getPreferences();
return Response.ok(new PreferencesVO(prefs)).build();
}
Aggregations