Search in sources :

Example 41 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class UserVOFactory method post.

public static void post(User dbUser, UserVO user, Locale locale) {
    UserManager um = UserManager.getInstance();
    List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(UserWebService.PROPERTY_HANDLER_IDENTIFIER, false);
    dbUser.setProperty(UserConstants.FIRSTNAME, user.getFirstName());
    dbUser.setProperty(UserConstants.LASTNAME, user.getLastName());
    dbUser.setProperty(UserConstants.EMAIL, user.getEmail());
    for (UserPropertyVO entry : user.getProperties()) {
        for (UserPropertyHandler propertyHandler : propertyHandlers) {
            if (entry.getName().equals(propertyHandler.getName())) {
                String value = parseUserProperty(entry.getValue(), propertyHandler, locale);
                String parsedValue;
                if (propertyHandler instanceof DatePropertyHandler) {
                    parsedValue = formatDbDate(value, locale);
                } else if (propertyHandler instanceof GenderPropertyHandler) {
                    parsedValue = parseGender(value, (GenderPropertyHandler) propertyHandler, locale);
                } else {
                    parsedValue = propertyHandler.getStringValue(value, locale);
                }
                dbUser.setProperty(entry.getName(), parsedValue);
                break;
            }
        }
    }
}
Also used : GenderPropertyHandler(org.olat.user.propertyhandlers.GenderPropertyHandler) UserManager(org.olat.user.UserManager) DatePropertyHandler(org.olat.user.propertyhandlers.DatePropertyHandler) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 42 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class UserVOFactory method get.

public static UserVO get(Identity identity, Locale locale, boolean allProperties, boolean isAdmin, boolean withPortrait) {
    if (locale == null) {
        locale = I18nModule.getDefaultLocale();
    }
    UserVO userVO = new UserVO();
    User user = identity.getUser();
    userVO.setKey(identity.getKey());
    if (identity != null) {
        userVO.setLogin(identity.getName());
    }
    userVO.setExternalId(identity.getExternalId());
    userVO.setFirstName(user.getProperty(UserConstants.FIRSTNAME, null));
    userVO.setLastName(user.getProperty(UserConstants.LASTNAME, null));
    userVO.setEmail(user.getProperty(UserConstants.EMAIL, null));
    if (withPortrait) {
        File portrait = DisplayPortraitManager.getInstance().getSmallPortrait(identity.getName());
        if (portrait != null && portrait.exists()) {
            try {
                InputStream input = new FileInputStream(portrait);
                byte[] datas = IOUtils.toByteArray(input);
                FileUtils.closeSafely(input);
                byte[] data64 = Base64.encodeBase64(datas);
                userVO.setPortrait(new String(data64, "UTF8"));
            } catch (IOException e) {
                log.error("", e);
            }
        }
    }
    if (allProperties) {
        UserManager um = UserManager.getInstance();
        HomePageConfig hpc = isAdmin ? null : HomePageConfigManagerImpl.getInstance().loadConfigFor(identity.getName());
        List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(UserWebService.PROPERTY_HANDLER_IDENTIFIER, false);
        for (UserPropertyHandler propertyHandler : propertyHandlers) {
            String propName = propertyHandler.getName();
            if (hpc != null && !hpc.isEnabled(propName)) {
                continue;
            }
            if (!UserConstants.FIRSTNAME.equals(propName) && !UserConstants.LASTNAME.equals(propName) && !UserConstants.EMAIL.equals(propName)) {
                String value = propertyHandler.getUserProperty(user, locale);
                userVO.putProperty(propName, value);
            }
        }
    }
    return userVO;
}
Also used : HomePageConfig(org.olat.user.HomePageConfig) User(org.olat.core.id.User) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) UserManager(org.olat.user.UserManager) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 43 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class GroupController method init.

protected void init(UserRequest ureq, boolean mayModifyMembers, boolean keepAtLeastOne, boolean enableTablePreferences, boolean enableUserSelection, boolean allowDownload, boolean mandatoryEmail, SecurityGroup aSecurityGroup) {
    this.securityGroup = aSecurityGroup;
    this.mayModifyMembers = mayModifyMembers;
    this.keepAtLeastOne = keepAtLeastOne;
    this.mandatoryEmail = mandatoryEmail;
    securityManager = BaseSecurityManager.getInstance();
    imModule = CoreSpringFactory.getImpl(InstantMessagingModule.class);
    imService = CoreSpringFactory.getImpl(InstantMessagingService.class);
    userManager = CoreSpringFactory.getImpl(UserManager.class);
    sessionManager = CoreSpringFactory.getImpl(UserSessionManager.class);
    mailManager = CoreSpringFactory.getImpl(MailManager.class);
    Roles roles = ureq.getUserSession().getRoles();
    BaseSecurityModule securityModule = CoreSpringFactory.getImpl(BaseSecurityModule.class);
    isAdministrativeUser = securityModule.isUserAllowedAdminProps(roles);
    chatEnabled = imModule.isEnabled() && imModule.isPrivateEnabled();
    // default group controller has no mail functionality
    this.addUserMailDefaultTempl = null;
    this.removeUserMailDefaultTempl = null;
    groupmemberview = createVelocityContainer("index");
    addUsersButton = LinkFactory.createButtonSmall("overview.addusers", groupmemberview, this);
    addUsersButton.setElementCssClass("o_sel_group_import_users");
    addUserButton = LinkFactory.createButtonSmall("overview.adduser", groupmemberview, this);
    addUserButton.setElementCssClass("o_sel_group_add_user");
    if (mayModifyMembers) {
        groupmemberview.contextPut("mayadduser", Boolean.TRUE);
    }
    TableGuiConfiguration tableConfig = new TableGuiConfiguration();
    tableConfig.setDownloadOffered(allowDownload);
    if (enableTablePreferences) {
        // save table preferences for each group seperatly
        if (mayModifyMembers) {
            tableConfig.setPreferencesOffered(true, "groupcontroller" + securityGroup.getKey());
        } else {
            // different rowcount...
            tableConfig.setPreferencesOffered(true, "groupcontrollerreadonly" + securityGroup.getKey());
        }
    }
    myTrans = userManager.getPropertyHandlerTranslator(getTranslator());
    tableCtr = new TableController(tableConfig, ureq, getWindowControl(), myTrans);
    listenTo(tableCtr);
    initGroupTable(tableCtr, ureq, enableTablePreferences, enableUserSelection);
    // set data model
    reloadData();
    groupmemberview.put("subjecttable", tableCtr.getInitialComponent());
    putInitialPanel(groupmemberview);
}
Also used : UserSessionManager(org.olat.core.util.session.UserSessionManager) UserManager(org.olat.user.UserManager) TableController(org.olat.core.gui.components.table.TableController) InstantMessagingService(org.olat.instantMessaging.InstantMessagingService) MailManager(org.olat.core.util.mail.MailManager) BaseSecurityModule(org.olat.basesecurity.BaseSecurityModule) Roles(org.olat.core.id.Roles) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration) InstantMessagingModule(org.olat.instantMessaging.InstantMessagingModule)

Example 44 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class AuthHelper method doInvitationLogin.

public static int doInvitationLogin(String invitationToken, UserRequest ureq, Locale locale) {
    InvitationDAO invitationDao = CoreSpringFactory.getImpl(InvitationDAO.class);
    boolean hasPolicies = invitationDao.hasInvitations(invitationToken, new Date());
    if (!hasPolicies) {
        return LOGIN_DENIED;
    }
    UserManager um = UserManager.getInstance();
    BaseSecurity securityManager = BaseSecurityManager.getInstance();
    GroupDAO groupDao = CoreSpringFactory.getImpl(GroupDAO.class);
    Invitation invitation = invitationDao.findInvitation(invitationToken);
    if (invitation == null) {
        return LOGIN_DENIED;
    }
    // check if identity exists
    Identity identity = um.findUniqueIdentityByEmail(invitation.getMail());
    if (identity != null) {
        SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
        if (securityManager.isIdentityInSecurityGroup(identity, allUsers)) {
            // already a normal olat user, cannot be invited
            return LOGIN_DENIED;
        } else {
            // fxdiff FXOLAT-151: add eventually the identity to the security group
            if (!groupDao.hasRole(invitation.getBaseGroup(), identity, GroupRoles.invitee.name())) {
                groupDao.addMembershipTwoWay(invitation.getBaseGroup(), identity, GroupRoles.invitee.name());
                DBFactory.getInstance().commit();
            }
            int result = doLogin(identity, BaseSecurityModule.getDefaultAuthProviderIdentifier(), ureq);
            // fxdiff FXOLAT-151: double check: problem with the DB, invitee is not marked has such
            if (ureq.getUserSession().getRoles().isInvitee()) {
                return result;
            }
            return LOGIN_DENIED;
        }
    }
    Collection<String> supportedLanguages = CoreSpringFactory.getImpl(I18nModule.class).getEnabledLanguageKeys();
    if (locale == null || !supportedLanguages.contains(locale.toString())) {
        locale = I18nModule.getDefaultLocale();
    }
    // invitation ok -> create a temporary user
    Identity invitee = invitationDao.createIdentityFrom(invitation, locale);
    return doLogin(invitee, BaseSecurityModule.getDefaultAuthProviderIdentifier(), ureq);
}
Also used : I18nModule(org.olat.core.util.i18n.I18nModule) InvitationDAO(org.olat.portfolio.manager.InvitationDAO) Date(java.util.Date) UserManager(org.olat.user.UserManager) GroupDAO(org.olat.basesecurity.manager.GroupDAO) Identity(org.olat.core.id.Identity)

Example 45 with UserManager

use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.

the class ExtendedIdentitiesTableDataModel method addColumnDescriptors.

/**
 * Add all column descriptors to this table that are available in the table
 * model
 *
 * @param tableCtr
 */
public void addColumnDescriptors(TableController tableCtr, Translator trans) {
    setLocale(trans.getLocale());
    if (isAdministrativeUser) {
        String action = actionEnabled ? COMMAND_SELECTUSER : null;
        tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.identity.name", colCount++, action, getLocale()));
    }
    UserManager um = UserManager.getInstance();
    // followed by the users fields
    for (int i = 0; i < userPropertyHandlers.size(); i++) {
        UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
        boolean visible = um.isMandatoryUserProperty(usageIdentifyer, userPropertyHandler);
        String action = null;
        if (actionEnabled && i < 2) {
            action = COMMAND_SELECTUSER;
        }
        tableCtr.addColumnDescriptor(visible, userPropertyHandler.getColumnDescriptor(colCount++, action, getLocale()));
    }
    // in the end the last login and creation date
    tableCtr.addColumnDescriptor(false, new DefaultColumnDescriptor("table.identity.lastlogin", colCount++, null, getLocale()));
    // creation date at the end, enabled by default
    tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.identity.creationdate", colCount++, null, getLocale()));
    if (actionEnabled) {
        StaticColumnDescriptor vcd = new StaticColumnDescriptor(COMMAND_VCARD, "table.header.vcard", trans.translate("table.identity.vcard"));
        vcd.setIsPopUpWindowAction(true, "height=700, width=900, location=no, menubar=no, resizable=yes, status=no, scrollbars=yes, toolbar=no");
        tableCtr.addColumnDescriptor(vcd);
    }
}
Also used : UserManager(org.olat.user.UserManager) StaticColumnDescriptor(org.olat.core.gui.components.table.StaticColumnDescriptor) DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

UserManager (org.olat.user.UserManager)64 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)22 Locale (java.util.Locale)12 Identity (org.olat.core.id.Identity)12 Date (java.util.Date)10 FormItem (org.olat.core.gui.components.form.flexible.FormItem)10 Translator (org.olat.core.gui.translator.Translator)10 User (org.olat.core.id.User)10 ArrayList (java.util.ArrayList)8 File (java.io.File)6 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)6 RestSecurityHelper.getLocale (org.olat.restapi.security.RestSecurityHelper.getLocale)6 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 ValidationError (org.olat.core.gui.components.form.ValidationError)4 SelectionElement (org.olat.core.gui.components.form.flexible.elements.SelectionElement)4 ItemValidatorProvider (org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider)4 AssertException (org.olat.core.logging.AssertException)4 ICourse (org.olat.course.ICourse)4 RestSecurityHelper.isUserManager (org.olat.restapi.security.RestSecurityHelper.isUserManager)4