Search in sources :

Example 21 with User

use of org.olat.core.id.User in project OpenOLAT by OpenOLAT.

the class ProfileFormController method updateFromFormData.

/**
 * Stores the data from the form into a) the user's home page configuration
 * and b) the user's properties.
 *
 * @param config The user's home page configuration (i.e. flags for publicly
 *          visible fields).
 * @param identity The user's identity
 */
public void updateFromFormData() {
    User user = identityToModify.getUser();
    // For each user property...
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        // ...get the value from the form field and store it into the user
        // property...
        FormItem formItem = formItems.get(userPropertyHandler.getName());
        if (formItem.isEnabled()) {
            userPropertyHandler.updateUserFromFormItem(user, formItem);
        }
    }
    // Store the "about me" text.
    HomePageConfig conf = hpcm.loadConfigFor(identityToModify.getName());
    conf.setTextAboutMe(textAboutMe.getValue());
    hpcm.saveConfigTo(identityToModify.getName(), conf);
}
Also used : User(org.olat.core.id.User) FormItem(org.olat.core.gui.components.form.flexible.FormItem) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 22 with User

use of org.olat.core.id.User in project OpenOLAT by OpenOLAT.

the class ProfileFormController method validateFormLogic.

@Override
protected boolean validateFormLogic(UserRequest ureq) {
    boolean allOk = true;
    formContext.put("username", identityToModify.getName());
    User user = identityToModify.getUser();
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        FormItem formItem = formItems.get(userPropertyHandler.getName());
        if (formItem.isEnabled()) {
            formItem.clearError();
            allOk &= userPropertyHandler.isValid(user, formItem, formContext);
        }
    }
    try {
        String aboutMe = textAboutMe.getValue();
        if (aboutMe.length() > 10000) {
            textAboutMe.setErrorKey("input.toolong", new String[] { "10000" });
            allOk = false;
        } else {
            textAboutMe.clearError();
        }
    } catch (Exception e) {
        textAboutMe.setErrorKey("input.toolong", new String[] { "10000" });
        allOk = false;
    }
    return allOk & super.validateFormLogic(ureq);
}
Also used : User(org.olat.core.id.User) FormItem(org.olat.core.gui.components.form.flexible.FormItem) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 23 with User

use of org.olat.core.id.User in project OpenOLAT by OpenOLAT.

the class ProfileFormController method formOK.

@Override
protected void formOK(final UserRequest ureq) {
    User user = identityToModify.getUser();
    // update each user field
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        FormItem formItem = formItems.get(userPropertyHandler.getName());
        if (formItem.isEnabled()) {
            userPropertyHandler.updateUserFromFormItem(user, formItem);
        }
    }
    if (portraitDeleted) {
        File img = dps.getLargestPortrait(identityToModify.getName());
        if (img != null) {
            dps.deletePortrait(identityToModify);
            notifyPortraitChanged();
        }
    }
    File uploadedImage = portraitUpload.getUploadFile();
    String uploadedFilename = portraitUpload.getUploadFileName();
    if (uploadedImage != null) {
        dps.setPortrait(uploadedImage, uploadedFilename, identityToModify.getName());
        notifyPortraitChanged();
    }
    if (logoDeleted) {
        File img = dps.getLargestLogo(identityToModify.getName());
        if (img != null) {
            dps.deleteLogo(identityToModify);
            notifyPortraitChanged();
        }
    }
    if (logoUpload != null) {
        File uploadedLogo = logoUpload.getUploadFile();
        String uploadedLogoname = logoUpload.getUploadFileName();
        if (uploadedLogo != null) {
            dps.setLogo(uploadedLogo, uploadedLogoname, identityToModify.getName());
            notifyPortraitChanged();
        }
    }
    // Store the "about me" text.
    HomePageConfig conf = hpcm.loadConfigFor(identityToModify.getName());
    conf.setTextAboutMe(textAboutMe.getValue());
    hpcm.saveConfigTo(identityToModify.getName(), conf);
    // fire the appropriate event
    fireEvent(ureq, Event.DONE_EVENT);
    // update the user profile data
    CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(OresHelper.createOLATResourceableInstance(Identity.class, identityToModify.getKey()), new SyncerExecutor() {

        @Override
        public void execute() {
            UserManager um = UserManager.getInstance();
            identityToModify = (Identity) DBFactory.getInstance().loadObject(identityToModify);
            currentEmail = identityToModify.getUser().getProperty("email", null);
            identityToModify = updateIdentityFromFormData(identityToModify);
            changedEmail = identityToModify.getUser().getProperty("email", null);
            emailChanged = false;
            if ((currentEmail == null && StringHelper.containsNonWhitespace(changedEmail)) || (currentEmail != null && !currentEmail.equals(changedEmail))) {
                if (isAllowedToChangeEmailWithoutVerification(ureq) || !StringHelper.containsNonWhitespace(changedEmail)) {
                    String key = identityToModify.getUser().getProperty("emchangeKey", null);
                    TemporaryKey tempKey = rm.loadTemporaryKeyByRegistrationKey(key);
                    if (tempKey != null) {
                        rm.deleteTemporaryKey(tempKey);
                    }
                    securityManager.deleteInvalidAuthenticationsByEmail(currentEmail);
                } else {
                    emailChanged = true;
                    // change email address to old address until it is verified
                    identityToModify.getUser().setProperty("email", currentEmail);
                }
            }
            if (!um.updateUserFromIdentity(identityToModify)) {
                getWindowControl().setInfo(translate("profile.unsuccessful"));
                // reload user data from db
                identityToModify = BaseSecurityManager.getInstance().loadIdentityByKey(identityToModify.getKey());
            }
            OLATResourceable modRes = OresHelper.createOLATResourceableInstance(Identity.class, identityToModify.getKey());
            CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new MultiUserEvent("changed"), modRes);
            if (!emailChanged) {
                fireEvent(ureq, Event.FAILED_EVENT);
            }
        }
    });
    if (emailChanged) {
        removeAsListenerAndDispose(dialogCtr);
        String dialogText = "";
        if (identityToModify.equals(ureq.getIdentity())) {
            dialogText = translate("email.change.dialog.text");
        } else {
            dialogText = translate("email.change.dialog.text.usermanager");
        }
        dialogCtr = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), translate("email.change.dialog.title"), dialogText);
        listenTo(dialogCtr);
        dialogCtr.activate();
    }
}
Also used : User(org.olat.core.id.User) OLATResourceable(org.olat.core.id.OLATResourceable) FormItem(org.olat.core.gui.components.form.flexible.FormItem) TemporaryKey(org.olat.registration.TemporaryKey) SyncerExecutor(org.olat.core.util.coordinate.SyncerExecutor) Identity(org.olat.core.id.Identity) File(java.io.File) MultiUserEvent(org.olat.core.util.event.MultiUserEvent) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 24 with User

use of org.olat.core.id.User in project OpenOLAT by OpenOLAT.

the class UserModule method init.

@Override
public void init() {
    int count = 0;
    for (String regexp : loginBlacklist) {
        try {
            Pattern.compile(regexp);
            loginBlacklistChecked.add(regexp);
        } catch (PatternSyntaxException pse) {
            log.error("Invalid pattern syntax in blacklist. Pattern: " + regexp + ". Removing from this entry from list ");
        }
        count++;
    }
    log.info("Successfully added " + count + " entries to login blacklist.");
    String userEmailOptionalValue = getStringPropertyValue(USER_EMAIL_MANDATORY, false);
    if (StringHelper.containsNonWhitespace(userEmailOptionalValue)) {
        isEmailMandatory = "true".equalsIgnoreCase(userEmailOptionalValue);
    }
    String userEmailUniquenessOptionalValue = getStringPropertyValue(USER_EMAIL_UNIQUE, false);
    if (StringHelper.containsNonWhitespace(userEmailUniquenessOptionalValue)) {
        isEmailUnique = "true".equalsIgnoreCase(userEmailUniquenessOptionalValue);
    }
    // Check if user manager is configured properly and has user property
    // handlers for the mandatory user properties used in OLAT
    checkMandatoryUserProperty(UserConstants.FIRSTNAME);
    checkMandatoryUserProperty(UserConstants.LASTNAME);
    if (isEmailMandatory()) {
        checkMandatoryUserProperty(UserConstants.EMAIL);
    }
    // Add controller factory extension point to launch user profile controller
    NewControllerFactory.getInstance().addContextEntryControllerCreator(Identity.class.getSimpleName(), new IdentityContextEntryControllerCreator());
    NewControllerFactory.getInstance().addContextEntryControllerCreator("HomeSite", new IdentityContextEntryControllerCreator());
    NewControllerFactory.getInstance().addContextEntryControllerCreator("HomePage", new HomePageContextEntryControllerCreator());
    NewControllerFactory.getInstance().addContextEntryControllerCreator(User.class.getSimpleName(), new UserAdminContextEntryControllerCreator());
    NewControllerFactory.getInstance().addContextEntryControllerCreator(UserAdminSite.class.getSimpleName(), new UserAdminContextEntryControllerCreator());
}
Also used : User(org.olat.core.id.User) UserAdminContextEntryControllerCreator(org.olat.admin.user.UserAdminContextEntryControllerCreator) UserAdminSite(org.olat.admin.site.UserAdminSite) Identity(org.olat.core.id.Identity) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 25 with User

use of org.olat.core.id.User in project OpenOLAT by OpenOLAT.

the class LDAPLoginManagerImpl method syncUser.

/**
 * Sync all OLATPropertys in Map of Identity
 *
 * @param olatPropertyMap Map of changed OLAT properties
 *          (OLATProperty,LDAPValue)
 * @param identity Identity to sync
 */
@Override
public Identity syncUser(Map<String, String> olatPropertyMap, IdentityRef identityRef) {
    if (identityRef == null) {
        log.warn("Identiy is null - should not happen", null);
        return null;
    }
    Identity identity = securityManager.loadIdentityByKey(identityRef.getKey());
    User user = identity.getUser();
    // remove user identifyer - can not be changed later
    olatPropertyMap.remove(LDAPConstants.LDAP_USER_IDENTIFYER);
    // remove attributes that are defined as sync-only-on-create
    Set<String> syncOnlyOnCreateProperties = syncConfiguration.getSyncOnlyOnCreateProperties();
    if (syncOnlyOnCreateProperties != null) {
        for (String syncOnlyOnCreateKey : syncOnlyOnCreateProperties) {
            olatPropertyMap.remove(syncOnlyOnCreateKey);
        }
    }
    for (Map.Entry<String, String> keyValuePair : olatPropertyMap.entrySet()) {
        String propName = keyValuePair.getKey();
        String value = keyValuePair.getValue();
        if (value == null) {
            if (user.getProperty(propName, null) != null) {
                log.debug("removed property " + propName + " for identity " + identity);
                user.setProperty(propName, value);
            }
        } else {
            user.setProperty(propName, value);
        }
    }
    // Add static user properties from the configuration
    Map<String, String> staticProperties = syncConfiguration.getStaticUserProperties();
    if (staticProperties != null && staticProperties.size() > 0) {
        for (Map.Entry<String, String> staticProperty : staticProperties.entrySet()) {
            user.setProperty(staticProperty.getKey(), staticProperty.getValue());
        }
    }
    userManager.updateUser(user);
    return identity;
}
Also used : LDAPUser(org.olat.ldap.model.LDAPUser) User(org.olat.core.id.User) Identity(org.olat.core.id.Identity) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

User (org.olat.core.id.User)260 Identity (org.olat.core.id.Identity)126 Test (org.junit.Test)82 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)52 HashMap (java.util.HashMap)28 Translator (org.olat.core.gui.translator.Translator)26 SecurityGroup (org.olat.basesecurity.SecurityGroup)20 Date (java.util.Date)18 ArrayList (java.util.ArrayList)16 Locale (java.util.Locale)16 FormItem (org.olat.core.gui.components.form.flexible.FormItem)16 File (java.io.File)14 VelocityContext (org.apache.velocity.VelocityContext)14 MailTemplate (org.olat.core.util.mail.MailTemplate)12 LDAPUser (org.olat.ldap.model.LDAPUser)12 UserManager (org.olat.user.UserManager)12 IOException (java.io.IOException)10 Map (java.util.Map)10 List (java.util.List)8 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)8