Beispiel #1
0
  private void createUserIfNeeded(LDAPResource ldap, String cn) throws LdapException {
    Entry ldapUser = ldap.getUser(cn);
    String email = ldap.getAttribute(ldapUser, emailAttr);
    User user = users.findByEmail(email);
    if (user == null) {
      String fullName = ldap.getAttribute(ldapUser, nameAttr);
      if (isNotEmpty(surnameAttr)) {
        fullName += " " + ldap.getAttribute(ldapUser, surnameAttr);
      }

      user = new User(fromTrustedText(fullName.trim()), email);

      LoginMethod brutalLogin = LoginMethod.brutalLogin(user, email, PLACHOLDER_PASSWORD);
      user.add(brutalLogin);

      users.save(user);
      loginMethods.save(brutalLogin);
    }

    // update moderator status
    // if (isNotEmpty(moderatorGroup) && ldap.getGroups(ldapUser).contains(moderatorGroup)) {
    //	user = user.asModerator();
    // } else {
    //	user.removeModerator();
    // }
    // updateAvatarImage(ldap, ldapUser, user);

    users.save(user);
  }
  public boolean validate(String email) {
    if (users.existsWithEmail(email)) {
      validator.add(messageFactory.build("error", "user.errors.email.used"));
    }
    if (email == null) {
      validator.add(messageFactory.build("error", "user.errors.email.required"));
    }

    return !validator.hasErrors();
  }