Package org.olat.user

Examples of org.olat.user.UserManager


    uifactory.addStaticTextElement("heading1", null, translate("new.form.please.enter"), formLayout);
    usernameTextElement = uifactory.addTextElement(LOGINNAME, "username", 128, "", formLayout);
    usernameTextElement.setMandatory(true);
    usernameTextElement.setDisplaySize(30);
   
    UserManager um = UserManager.getInstance();
    userPropertyHandlers = um.getUserPropertyHandlersFor(formIdentifyer, true);
    // Add all available user fields to this form
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
      if (userPropertyHandler == null) continue;
      FormItem formItem = userPropertyHandler.addFormItem(ureq.getLocale(), null, formIdentifyer, true, formLayout);
      // special case to handle email field
View Full Code Here


    }
    // special test on email address: validate if email is already used
    if (emailTextElement != null) {     
      String email = emailTextElement.getValue();
      // Check if email is not already taken
      UserManager um = UserManager.getInstance();

      // TODO:fj offer a method in basesecurity to threadsafely generate a new
      // user!!!

      Identity exists = um.findIdentityByEmail(email);
      if (exists != null) {
        // Oups, email already taken, display error
        emailTextElement.setErrorKey("new.error.email.choosen", new String[] {});
        return false;
      }
View Full Code Here

        pwd = null;
      }
    }
    // Create new user and identity and put user to users group
    // Create transient user without firstName,lastName, email
    UserManager um = UserManager.getInstance();
    User newUser = um.createUser(null, null, null);
    // Now add data from user fields (firstName,lastName and email are mandatory)
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
      FormItem propertyItem = this.flc.getFormComponent(userPropertyHandler.getName());
      userPropertyHandler.updateUserFromFormItem(newUser, propertyItem);
    }
View Full Code Here

    notUpdatedIdentities.clear();
    List<Identity> changedIdentities = new ArrayList<Identity>();
    List<UserPropertyHandler> userPropertyHandlers = UserManager.getInstance().getUserPropertyHandlersFor(usageIdentifyer,
        isAdministrativeUser);
    String[] securityGroups = { Constants.GROUP_USERMANAGERS, Constants.GROUP_GROUPMANAGERS, Constants.GROUP_AUTHORS, Constants.GROUP_ADMIN };
    UserManager um = UserManager.getInstance();
    Manager secMgr = ManagerFactory.getManager();


    // loop over users to be edited:
    for (Identity identity : selIdentities) {
      DB db = DBFactory.getInstance();
      //reload identity from cache, to prevent stale object
      identity = (Identity) db.loadObject(identity);
      User user = identity.getUser();
      String errorDesc = "";
      boolean updateError = false;
      // change pwd
      if (attributeChangeMap.containsKey(PWD_IDENTIFYER)) {
        String newPwd = attributeChangeMap.get(PWD_IDENTIFYER);
        if (StringHelper.containsNonWhitespace(newPwd)) {
          if (!UserManager.getInstance().syntaxCheckOlatPassword(newPwd)) {
            errorDesc = transWithFallback.translate("error.password");
            updateError = true;
          }
        } else newPwd = null;
        OLATAuthManager.changePasswordAsAdmin(identity, newPwd);
      }

      // set language
      String userLanguage = user.getPreferences().getLanguage();
      if (attributeChangeMap.containsKey(LANG_IDENTIFYER)) {
        String inputLanguage = attributeChangeMap.get(LANG_IDENTIFYER);
        if (!userLanguage.equals(inputLanguage)) {
          Preferences preferences = user.getPreferences();
          preferences.setLanguage(inputLanguage);
          user.setPreferences(preferences);
        }
      }

      Context vcContext = new VelocityContext();
      // set all properties as context
      setUserContext(identity, vcContext, isAdministrativeUser);
      // loop for each property configured in
      // src/serviceconfig/org/olat/_spring/olat_userconfig.xml -> Key:
      // org.olat.admin.user.bulkChange.UserBulkChangeStep00
      for (int k = 0; k < userPropertyHandlers.size(); k++) {
        UserPropertyHandler propHandler = userPropertyHandlers.get(k);
        String propertyName = propHandler.getName();
        String userValue = identity.getUser().getProperty(propertyName, null);
        String inputFieldValue = "";
        if (attributeChangeMap.containsKey(propertyName)) {
          inputFieldValue = attributeChangeMap.get(propertyName);
          inputFieldValue = inputFieldValue.replace("$", "$!");
          String evaluatedInputFieldValue = evaluateValueWithUserContext(inputFieldValue, vcContext)
         
          // validate evaluated property-value
          ValidationError validationError = new ValidationError();
          // do validation checks with users current locale!
          Locale locale = transWithFallback.getLocale();
          if (!propHandler.isValidValue(evaluatedInputFieldValue, validationError, locale)) {
            errorDesc = transWithFallback.translate(validationError.getErrorKey()) + " (" + evaluatedInputFieldValue + ")";
            updateError = true;
            break;
          }

          if (!evaluatedInputFieldValue.equals(userValue)) {
            String stringValue = propHandler.getStringValue(evaluatedInputFieldValue, locale);
              propHandler.setUserProperty(user, stringValue);
          }
        }

      } // for (propertyHandlers)

      // set roles for identity
      // loop over securityGroups defined above
      for (String securityGroup : securityGroups) {
        SecurityGroup secGroup = secMgr.findSecurityGroupByName(securityGroup);
        Boolean isInGroup = secMgr.isIdentityInSecurityGroup(identity, secGroup);
        String thisRoleAction = "";
        if (roleChangeMap.containsKey(securityGroup)) {
          thisRoleAction = roleChangeMap.get(securityGroup);
          // user not anymore in security group, remove him
          if (isInGroup && thisRoleAction.equals("remove")) secMgr.removeIdentityFromSecurityGroup(identity, secGroup);
          // user not yet in security group, add him
          if (!isInGroup && thisRoleAction.equals("add")) secMgr.addIdentityToSecurityGroup(identity, secGroup);
        }
      }
     
      // set status
      if (roleChangeMap.containsKey("Status")) {
        Integer status = Integer.parseInt(roleChangeMap.get("Status"));
        secMgr.saveIdentityStatus(identity, status);
        identity = (Identity) db.loadObject(identity);
      }

      // persist changes:
      if (updateError) {
        String errorOutput = identity.getName() + ": " + errorDesc;
        log.debug("error during bulkChange of users, following user could not be updated: " + errorOutput);
        notUpdatedIdentities.add(errorOutput);
      } else {
        um.updateUserFromIdentity(identity);
        changedIdentities.add(identity);
        log.audit("user successfully changed during bulk-change: " + identity.getName());
      }

      // commit changes for this user
View Full Code Here

        pwd = null;
      }
    }

    // Create transient user without firstName,lastName, email
    UserManager um = UserManager.getInstance();
    User newUser = um.createUser(null, null, null);

    List<UserPropertyHandler> userProperties = userPropertyHandlers;
    int col = 4;
    String thisValue = "", stringValue;
    for (UserPropertyHandler userPropertyHandler : userProperties) {
View Full Code Here

    List<FormItem> formItems;

    public UserBulkChangeStepForm00(UserRequest ureq, WindowControl control, Form rootForm, StepsRunContext runContext) {
      super(ureq, control, rootForm, runContext, LAYOUT_VERTICAL, null);
      // use custom translator with fallback to user properties translator
      UserManager um = UserManager.getInstance();
      setTranslator(um.getPropertyHandlerTranslator(getTranslator()));
      flc.setTranslator(getTranslator());
      initForm(ureq);
    }
View Full Code Here

    private List<UserPropertyHandler> userPropertyHandlers;

    public ImportStepForm01(UserRequest ureq, WindowControl control, Form rootForm, StepsRunContext runContext) {
      super(ureq, control, rootForm, runContext, LAYOUT_VERTICAL, null);
      // use custom translator with fallback to user properties translator
      UserManager um = UserManager.getInstance();
      setTranslator(um.getPropertyHandlerTranslator(getTranslator()));
      flc.setTranslator(getTranslator());
      initForm(ureq);
    }
View Full Code Here

    }

    @Override
    protected boolean validateFormLogic(UserRequest ureq) {
      Boolean validChange = false;
      UserManager um = UserManager.getInstance();

      // loop through and check if any checkbox has been selected
      int i = 0;
     
      for (Iterator<MultipleSelectionElement> iterator = checkBoxes.iterator(); iterator.hasNext();) {
        MultipleSelectionElement checkbox = iterator.next();
        if (checkbox.isSelected(0)) {
          Context vcContext = ubcMan.getDemoContext(getTranslator(), isAdministrativeUser);
          validChange = true;
          FormItem formItem = formItems.get(i);
          if (formItem instanceof TextElement) {
            TextElement propertyField = (TextElement) formItem;
            String inputFieldValue = propertyField.getValue();


            // check validity of velocity-variables by using default values from
            // userproperties
            inputFieldValue = inputFieldValue.replace("$", "$!");
            String evaluatedInputFieldValue = ubcMan.evaluateValueWithUserContext(inputFieldValue, vcContext);

            // check user property configuration
            for (UserPropertyHandler handler : userPropertyHandlers) {
              if (handler.getName().equals(formItem.getName())) {
                // first check on mandatoryness
                if (um.isMandatoryUserProperty(usageIdentifyer, handler) && ! StringHelper.containsNonWhitespace(evaluatedInputFieldValue)) {
                  formItem.setErrorKey("form.name." + handler.getName() + ".error.empty", null);       
                  return false;                 
                }
                // second check on property content
                ValidationError valicationError = new ValidationError();
                if (! handler.isValidValue(evaluatedInputFieldValue, valicationError, ureq.getLocale())) {
                  formItem.setErrorKey(valicationError.getErrorKey(), null);
                  return false;
                }
                // else validation was ok, reset previous errors
                formItem.clearError();
              }
            }

            // special case: check password-syntax:
            if (propertyField.getName().equals("password")) {
              if (!um.syntaxCheckOlatPassword(evaluatedInputFieldValue)) {
                propertyField.setErrorKey("error.password", new String[] { evaluatedInputFieldValue });
                return false;
              }
            }
View Full Code Here

        tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.user.pwd"));
      }
      colPos++;
      tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.user.lang"));
      colPos++;
      UserManager um = UserManager.getInstance();
      // followed by all properties configured
      // if only mandatory required: check for um.isMandatoryUserProperty(usageIdentifyer, userPropertyHandler);
      userPropertyHandlers = UserManager.getInstance().getUserPropertyHandlersFor(usageIdentifyer, true);
      for (int i = 0; i < userPropertyHandlers.size(); i++) {
        UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
View Full Code Here

    addFormElement("title.user", new TitleElement("search.form.title.user"));
    login = new TextElement("search.form.login", 128);
    addFormElement("login", login);

    // search user fields
    UserManager um = UserManager.getInstance();
    userPropertyHandlers = um.getUserPropertyHandlersFor(formIdentifyer, true);
    String currentGroup = null;
    // Add all available user fields to this form
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
      if (userPropertyHandler == null) continue;
      FormElement ui = userPropertyHandler.getFormElement(getLocale(), null, formIdentifyer, true);
View Full Code Here

TOP

Related Classes of org.olat.user.UserManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.