Search in sources :

Example 11 with Preferences

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();
}
Also used : Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Preferences(org.olat.core.id.Preferences) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with Preferences

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);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Preferences(org.olat.core.id.Preferences) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 13 with Preferences

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");
    }
}
Also used : Locale(java.util.Locale) Translator(org.olat.core.gui.translator.Translator) MailerResult(org.olat.core.util.mail.MailerResult) Authentication(org.olat.basesecurity.Authentication) TemporaryKey(org.olat.registration.TemporaryKey) Preferences(org.olat.core.id.Preferences) MailBundle(org.olat.core.util.mail.MailBundle)

Example 14 with Preferences

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);
}
Also used : Preferences(org.olat.core.id.Preferences) BaseSecurity(org.olat.basesecurity.BaseSecurity) WindowManager(org.olat.core.gui.WindowManager)

Example 15 with Preferences

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();
}
Also used : Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Preferences(org.olat.core.id.Preferences) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Preferences (org.olat.core.id.Preferences)22 Locale (java.util.Locale)12 Translator (org.olat.core.gui.translator.Translator)8 Identity (org.olat.core.id.Identity)8 Date (java.util.Date)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 BaseSecurity (org.olat.basesecurity.BaseSecurity)4 User (org.olat.core.id.User)4 MailBundle (org.olat.core.util.mail.MailBundle)4 MailerResult (org.olat.core.util.mail.MailerResult)4 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)4 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)4 Charset (java.nio.charset.Charset)2 ArrayList (java.util.ArrayList)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 VelocityContext (org.apache.velocity.VelocityContext)2